473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

pyraf and matplotlib

3
Hi
I am writing a small script which will create a mask file interactively. The script is working fine but when I use this in another script which imports pyraf, it seems hanging. I am attaching the script here. could anybody help me?
thanks
Vinu V
The main program:

#!/usr/bin/env python
from pyraf import iraf
from manualmaskfunc1 import *
ManualMaskManager('I_EDCSNJ1216453-1201176.fits')

It calls manualmaskfunc1.py and it is as follows

from matplotlib.widgets import Lasso
from matplotlib.nxutils import points_inside_poly
import pyfits
from pylab import figure, show, nx, close, draw
import numpy as n
from matplotlib.patches import Polygon
import config as c
import os

#class ManualMaskManager:
class ManualMaskManager:
"""This class generate mask interactevely"""
def __init__(self, cutimage):
self.cutimage = cutimage
f = pyfits.open(self.cutimage)
self.z = f[0].data
f.close()
self.size = self.z.shape[0]
self.x = n.reshape(n.arange(self.size * self.size), (self.size, self.size)) % self.size
self.x =self.x.astype(n.float32)
self.y = n.reshape(n.arange(self.size * self.size), (self.size, self.size)) / self.size
self.y = self.y.astype(n.float32)
fig = figure()
ax = fig.add_subplot(111, autoscale_on=False)
ax.contourf(self.x, self.y, self.z, 50)
# self.lman = ManualMaskManager(self.cutimage, ax, x, y, z, size)
# show()
self.axes = ax
self.canvas = ax.figure.canvas
self.mask = n.zeros((self.size, self.size), int)
# self.axes.contourf(x,y,z, 50)
x1 = n.reshape(self.x, (self.size * self.size, 1))
y1 = n.reshape(self.y, (self.size * self.size, 1))
self.xy = n.concatenate((x1,y1),axis=1)
self.Nxy = self.size * self.size
self.cid = self.canvas.mpl_connect('button_press_event', self.onpress)
self.cid2 = self.canvas.mpl_connect('key_press_event', self.onpress1) show()
# return
def bad_pixel(self, ind):
for element in ind:
self.mask[element / self.size, element % self.size] = 1
def bad_pixel_remove(self, ind):
for element in ind:
self.mask[element / self.size, element % self.size] = 0
def write_fits(self):
try:
os.remove('M_' + str(self.cutimage)[:-5] + '.fits')
except:
pass
hdu = pyfits.PrimaryHDU(self.mask.astype(n.float32))
hdu.writeto('M_' + str(self.cutimage)[:-5] + '.fits')
close()
def onpress1(self, event):
if event.key=='a':
self.bad_pixel(self.ind)
accept = 'yes'
print accept
if event.key=='c':
self.bad_pixel_remove(self.ind)
rect = Polygon(self.ver, facecolor='red', alpha=0.5)
self.axes.add_patch(rect)
self.canvas.draw_idle()
accept = 'no'
print accept
elif event.key=='q':
self.canvas.mpl_disconnect(self.cid)
self.canvas.mpl_disconnect(self.cid2)
self.write_fits()
def callback(self, verts):
self.ind = nx.nonzero(points_inside_poly(self.xy, verts))
self.ver = verts
rect = Polygon(self.ver, facecolor='green', alpha=0.5)
self.axes.add_patch(rect)
self.canvas.draw_idle()
def onpress(self, event):
self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback)
Jan 27 '08 #1
0 1322

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: John Hunter | last post by:
matplotlib is a 2D plotting package for python with a matlab compatible syntax and output tested under linux and windows platforms. matplotlib-0.30 is available for download at...
3
by: John Hunter | last post by:
matplotlib is a 2D plotting library for python. You can use matplotlib interactively from a python shell or IDE, or embed it in GUI applications (WX, GTK, and Tkinter). matplotlib supports many...
2
by: Grant Edwards | last post by:
I downloaded examples/contour_demo.py, and it doesn't run. I've searched both the user guide and the Wiki for "contour" and got zero hits. ...
0
by: spross | last post by:
hi all i have to use matplotlib on mac os x. on the official site of matplotlib, i found a link to precompiled python packages for mac os x: http://pythonmac.org/packages/py24-fat/index.html ...
0
by: Soren | last post by:
Hi, I've been trying to embed matplotlib in wxpython. I want to be able to put a figure (axes) in a wx.Panel and place it somewhere in my GUI. The GUI should have other panels with buttons etc....
4
by: Bill Jackson | last post by:
Hi, I'm having some trouble plotting with the following matplotlibrc: text.usetex : True I tried clearing the cache files under ~/.matplotlib, but this did not help the problem. I'd post...
3
by: vajratkarviraj | last post by:
i hav python2.5, matplotlib0.90.1, and py2exe for python 2.5 all on windows xp... i hav a python program(letsc.py) which uses the matplotlib package... and i want 2 make an exe of it for distribution...
4
by: John Henry | last post by:
Has anybody been able to create an exe of their python applications involving matplotlib using pyinstall (ver 1.3)? I am getting a: RuntimeError: Could not find the matplotlib data files when...
0
by: PamMish1982 | last post by:
Hi all, I have recently started using Python and I am trying to make a GUI out of Tkinter. I am using matplotlib for the graphic purposes. I have to make a exe file from this code. I use py2exe...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.