def __init__(self, fv): # superclass defines some variables for us, like logger super(IRAFBase, self).__init__(fv) self.keyqueue = Queue.Queue() self.keyevent = threading.Event() self.keymap = { 'comma': ',', } self.ctrldown = False self.layertag = 'iraf-canvas' # this will be set in initialize() self.canvas = None self.addr = iis.get_interface() self.ev_quit = self.fv.ev_quit self.dataTask = None # colormap for use with IRAF displays self.cm_iis = cmap.ColorMap('iis_iraf', cmap_iis_iraf) self.im_iis = imap.get_imap('ultrasmooth') fv.add_callback('add-channel', self.add_channel) fv.add_callback('delete-channel', self.delete_channel)
def start(self): # holds frame buffers self.fb = {} self.current_frame = 0 # cursor position self.cursor_x = 1.0 self.cursor_y = 1.0 self.mode = 'ginga' self.imexam_active = False self.imexam_chname = None # init the first frame(frame 0) self.init_frame(0) try: if self.addr.prot == 'unix': os.remove(self.addr.path) except: pass # start the data listener task, if appropriate #ev_quit = threading.Event() self.dataTask = iis.IIS_DataListener(self.addr, controller=self, ev_quit=self.ev_quit, logger=self.logger) self.fv.nongui_do(self.dataTask.mainloop)
def info_xy(self, data_x, data_y, settings): ct = self.get('ct', None) # Get the value under the data coordinates try: # We report the value across the pixel, even though the coords # change halfway across the pixel x, y = int(data_x + 0.5), int(data_y + 0.5) value = self.get_data_xy(x, y) # Mapping from bytescaled values back to original values value = iis.wcs_pix_transform(ct, value) except Exception as e: self.logger.error("Exception getting value at %d,%d: %s" % (x, y, str(e))) value = None # Calculate WCS RA, if available try: # Subtract offsets of data in framebuffer and add offsets of # rect beginning in source data_x = data_x - (ct.dx - 1) + (ct.sx - 1) data_y = data_y - (ct.dy - 1) + (ct.sy - 1) #ra_deg, dec_deg = wcs_coord_transform(ct, data_x, data_y) #ra_txt, dec_txt = self.wcs.deg2fmt(ra_deg, dec_deg, 'str') ra_txt = 'BAD WCS' dec_txt = 'BAD WCS' except Exception as e: self.logger.warning("Bad coordinate conversion: %s" % (str(e))) ra_txt = 'BAD WCS' dec_txt = 'BAD WCS' # Note: FITS coordinates are 1-based, whereas numpy FITS arrays # are 0-based ra_lbl, dec_lbl = unichr(945), unichr(948) fits_x, fits_y = data_x + 1, data_y + 1 info = Bunch.Bunch(itype='astro', data_x=data_x, data_y=data_y, fits_x=fits_x, fits_y=fits_y, x=fits_x, y=fits_y, ra_txt=ra_txt, dec_txt=dec_txt, ra_lbl=ra_lbl, dec_lbl=dec_lbl, value=value) return info
def init_frame(self, n): """ NOTE: this is called from the IIS_RequestHandler """ self.logger.debug("initializing frame %d" % (n)) # create the frame, if needed try: fb = self.get_frame(n) except KeyError: fb = iis.framebuffer() self.fb[n] = fb fb.width = None fb.height = None fb.wcs = '' fb.image = None fb.bitmap = None fb.zoom = 1.0 fb.buffer = array.array('B') fb.ct = iis.coord_tran() #fb.chname = None return fb
def start(self): try: if self.addr.prot == 'unix': os.remove(self.addr.path) except: pass # start the data listener task, if appropriate ev_quit = threading.Event() self.dataTask = iis.IIS_DataListener( self.addr, controller=self, ev_quit=ev_quit, logger=self.logger) self.fv.nongui_do(self.dataTask.mainloop)
def info_xy(self, data_x, data_y, settings): ct = self.get("ct", None) # Get the value under the data coordinates try: # We report the value across the pixel, even though the coords # change halfway across the pixel x, y = int(data_x + 0.5), int(data_y + 0.5) value = self.get_data_xy(x, y) # Mapping from bytescaled values back to original values value = iis.wcs_pix_transform(ct, value) except Exception, e: self.logger.error("Exception getting value at %d,%d: %s" % (x, y, str(e))) value = None
def info_xy(self, data_x, data_y): ct = self.get('ct', None) # Get the value under the data coordinates try: # We report the value across the pixel, even though the coords # change halfway across the pixel x, y = int(data_x + 0.5), int(data_y + 0.5) value = self.get_data_xy(x, y) # Mapping from bytescaled values back to original values value = iis.wcs_pix_transform(ct, value) except Exception, e: self.logger.error("Exception getting value at %d,%d: %s" % (x, y, str(e))) value = None
def info_xy(self, data_x, data_y, settings): ct = self.get('ct', None) # Get the value under the data coordinates try: # We report the value across the pixel, even though the coords # change halfway across the pixel x, y = int(data_x+0.5), int(data_y+0.5) value = self.get_data_xy(x, y) # Mapping from bytescaled values back to original values value = iis.wcs_pix_transform(ct, value) except Exception as e: self.logger.error("Exception getting value at %d,%d: %s" % ( x, y, str(e))) value = None # Calculate WCS RA, if available try: # Subtract offsets of data in framebuffer and add offsets of # rect beginning in source data_x = data_x - (ct.dx-1) + (ct.sx-1) data_y = data_y - (ct.dy-1) + (ct.sy-1) #ra_deg, dec_deg = wcs_coord_transform(ct, data_x, data_y) #ra_txt, dec_txt = self.wcs.deg2fmt(ra_deg, dec_deg, 'str') ra_txt = 'BAD WCS' dec_txt = 'BAD WCS' except Exception as e: self.logger.warn("Bad coordinate conversion: %s" % ( str(e))) ra_txt = 'BAD WCS' dec_txt = 'BAD WCS' # Note: FITS coordinates are 1-based, whereas numpy FITS arrays # are 0-based ra_lbl, dec_lbl = unichr(945), unichr(948) fits_x, fits_y = data_x + 1, data_y + 1 info = Bunch.Bunch(itype='astro', data_x=data_x, data_y=data_y, fits_x=fits_x, fits_y=fits_y, x=fits_x, y=fits_y, ra_txt=ra_txt, dec_txt=dec_txt, ra_lbl=ra_lbl, dec_lbl=dec_lbl, value=value) return info
def __init__(self, fv): # superclass defines some variables for us, like logger super(IRAF, self).__init__(fv) self.keyqueue = Queue.Queue() self.keyevent = threading.Event() self.keymap = { 'comma': ',', } self.ctrldown = False self.layertag = 'iraf-canvas' # this will be set in initialize() self.canvas = None self.dc = fv.getDrawClasses() self.addr = iis.get_interface() self.ev_quit = self.fv.ev_quit self.dataTask = None # Holds frame buffers self.fb = {} self.current_frame = 0 # cursor position self.cursor_x = 1.0 self.cursor_y = 1.0 self.mode = 'ginga' self.imexam_active = False self.imexam_chname = None # init the first frame(frame 0) self.init_frame(0) # colormap for use with IRAF displays self.cm_iis = cmap.ColorMap('iis_iraf', cmap_iis_iraf) self.im_iis = imap.get_imap('ultrasmooth') fv.add_callback('add-channel', self.add_channel) fv.add_callback('delete-channel', self.delete_channel) #fv.set_callback('active-image', self.focus_cb) self.gui_up = False
def __init__(self, fv): # superclass defines some variables for us, like logger super(IRAF, self).__init__(fv) self.keyqueue = Queue.Queue() self.keyevent = threading.Event() self.keymap = { 'comma': ',', } self.ctrldown = False self.layertag = 'iraf-canvas' # this will be set in initialize() self.canvas = None self.dc = fv.get_draw_classes() self.addr = iis.get_interface() self.ev_quit = self.fv.ev_quit self.data_task = None # Holds frame buffers self.fb = {} self.current_frame = 0 # cursor position self.cursor_x = 1.0 self.cursor_y = 1.0 self.mode = 'ginga' self.imexam_active = False self.imexam_chname = None # init the first frame(frame 0) self.init_frame(0) # colormap for use with IRAF displays self.cm_iis = cmap.ColorMap('iis_iraf', cmap_iis_iraf) self.im_iis = imap.get_imap('ultrasmooth') fv.add_callback('add-channel', self.add_channel) fv.add_callback('delete-channel', self.delete_channel) #fv.set_callback('channel-change', self.focus_cb) self.gui_up = False
def new_image_cb(self, fitsimage, image, chinfo): # check if this is an image we received from IRAF or # one that was loaded locally. ct = image.get('ct', None) if ct != None: # This image was sent by IRAF--we don't need to # construct extra fb information for it return n = self.channel_to_frame(chinfo.name) if n == None: return self.logger.debug("new image, frame is %d" % (n)) fb = self.get_frame(n) #image = fitsimage.get_image() newpath = image.get('path', 'NO_PATH') host = socket.getfqdn() newhost = image.get('host', host) # protocol has a bizarre 16-char limit on hostname newhost = newhost[:16] # this is just a placeholder so that IIS_RequestHandler will # report something in this buffer fb.buffer = array.array('B', ' ') # Update IRAF "wcs" info so that IRAF can load this image #print "filling wcs info" fb.ct = iis.coord_tran() image.set(ct=ct) # iis version 1 data fb.ct.valid = 1 fb.ct.a = 1 fb.ct.b = 0 fb.ct.c = 0 fb.ct.d = 1 fb.ct.tx = 0 fb.ct.ty = 0 fb.ct.z1 = 0 fb.ct.z2 = 1 fb.ct.zt = iis.W_UNITARY fb.ct.format = '' fb.ct.imtitle = '' # iis version 1+ data fb.ct.region = 'image' #x1, y1, x2, y2 = fitsimage.get_datarect() #wd, ht = x2-x1, y2-y1 #x1, y1, x2, y2 = x1+1, y1+1, x2+1, y2+1 #fb.ct.sx, fb.ct.sy = float(x1), float(y1) wd, ht = image.get_size() fb.ct.sx, fb.ct.sy = float(1), float(1) fb.ct.snx, fb.ct.sny = wd, ht fb.ct.dx, fb.ct.dy = 1, 1 fb.ct.dnx, fb.ct.dny = wd, ht # ref newref = "!".join([newhost, newpath]) fb.ct.ref = newref # TODO: we shouldn't have to know about this here... if (fb and fb.ct.a != None): wcs = "%s\n%f %f %f %f %f %f %f %f %d\n" % ( fb.ct.imtitle, fb.ct.a, fb.ct.b, fb.ct.c, fb.ct.d, fb.ct.tx, fb.ct.ty, fb.ct.z1, fb.ct.z2, fb.ct.zt) else: wcs = "[NOSUCHWCS]\n" if (fb and fb.ct.sx != None): mapping = "%s %f %f %d %d %d %d %d %d\n%s\n" % ( fb.ct.region, fb.ct.sx, fb.ct.sy, fb.ct.snx, fb.ct.sny, fb.ct.dx, fb.ct.dy, fb.ct.dnx, fb.ct.dny, fb.ct.ref) else: mapping = "" fb.wcs = wcs + mapping
def new_image_cb(self, fitsimage, image, chinfo): if not self.gui_up: return # check if this is an image we received from IRAF or # one that was loaded locally. ct = image.get('ct', None) if ct != None: # This image was sent by IRAF--we don't need to # construct extra fb information for it return n = self.channel_to_frame(chinfo.name) if n == None: return self.logger.debug("new image, frame is %d" % (n)) fb = self.get_frame(n) #image = fitsimage.get_image() newpath = image.get('path', 'NO_PATH') host = socket.getfqdn() newhost = image.get('host', host) # protocol has a bizarre 16-char limit on hostname newhost = newhost[:16] # this is just a placeholder so that IIS_RequestHandler will # report something in this buffer fb.buffer = array.array('B', ' ') # Update IRAF "wcs" info so that IRAF can load this image #print "filling wcs info" fb.ct = iis.coord_tran() image.set(ct=ct) # iis version 1 data fb.ct.valid = 1 fb.ct.a = 1 fb.ct.b = 0 fb.ct.c = 0 fb.ct.d = 1 fb.ct.tx = 0 fb.ct.ty = 0 fb.ct.z1 = 0 fb.ct.z2 = 1 fb.ct.zt = iis.W_UNITARY fb.ct.format = '' fb.ct.imtitle = '' # iis version 1+ data fb.ct.region = 'image' #x1, y1, x2, y2 = fitsimage.get_datarect() #wd, ht = x2-x1, y2-y1 #x1, y1, x2, y2 = x1+1, y1+1, x2+1, y2+1 #fb.ct.sx, fb.ct.sy = float(x1), float(y1) wd, ht = image.get_size() fb.ct.sx, fb.ct.sy = float(1), float(1) fb.ct.snx, fb.ct.sny = wd, ht fb.ct.dx, fb.ct.dy = 1, 1 fb.ct.dnx, fb.ct.dny = wd, ht # ref newref = "!".join([newhost, newpath]) fb.ct.ref = newref # TODO: we shouldn't have to know about this here... if (fb and fb.ct.a != None): wcs = "%s\n%f %f %f %f %f %f %f %f %d\n" % ( fb.ct.imtitle, fb.ct.a, fb.ct.b, fb.ct.c, fb.ct.d, fb.ct.tx, fb.ct.ty, fb.ct.z1, fb.ct.z2, fb.ct.zt) else: wcs = "[NOSUCHWCS]\n" if (fb and fb.ct.sx != None): mapping = "%s %f %f %d %d %d %d %d %d\n%s\n" % ( fb.ct.region, fb.ct.sx, fb.ct.sy, fb.ct.snx, fb.ct.sny, fb.ct.dx, fb.ct.dy, fb.ct.dnx, fb.ct.dny, fb.ct.ref) else: mapping = "" fb.wcs = wcs + mapping
def set_addr_cb(self, w): # get and parse address addr = w.get_text() self.addr = iis.get_interface(addr=addr) addr = str(self.addr.name) self.w.addr.set_text(addr)