def panset(self, fitsimage, chinfo, paninfo): x, y = fitsimage.get_pan() points = fitsimage.get_pan_rect() # calculate pan position point radius image = paninfo.panimage.get_image() width, height = image.get_size() edgew = math.sqrt(width**2 + height**2) radius = int(0.015 * edgew) # Mark pan rectangle and pan position try: obj = paninfo.panimage.getObjectByTag(paninfo.panrect) if obj.kind != 'compound': return True point, bbox = obj.objects self.logger.debug("starting panset") point.x, point.y = x, y point.radius = radius bbox.points = points paninfo.panimage.redraw(whence=3) except KeyError: paninfo.panrect = paninfo.panimage.add(CanvasTypes.CompoundObject( CanvasTypes.Point(x, y, radius=radius), CanvasTypes.Polygon(points)))
def plot_star(self, obj, image=None): if not image: image = self.fitsimage.get_image() x, y = image.radectopix(obj['ra_deg'], obj['dec_deg']) #print "STAR at %d,%d" % (x, y) # TODO: auto-pick a decent radius radius = 10 color = self.table.get_color(obj) #print "color is %s" % str(color) circle = CanvasTypes.Circle(x, y, radius, color=color) point = CanvasTypes.Point(x, y, radius, color=color) ## What is this from? if obj.has_key('pick'): # Some objects returned from the Gen2 star catalog are marked # with the attribute 'pick'. If present then we show the # star with or without the cross, otherwise we always show the # cross if not obj['pick']: star = CanvasTypes.Canvas(circle, point) else: star = CanvasTypes.Canvas(circle) else: star = CanvasTypes.Canvas(circle, point) star.set_data(star=obj) obj.canvobj = star self.canvas.add(star, tagpfx='star', redraw=False)
def add_mark(self, data_x, data_y, radius=None, color=None, style=None): if not radius: radius = self.mark_radius if not color: color = self.mark_color if not style: style = self.mark_style self.logger.debug("Setting mark at %d,%d" % (data_x, data_y)) self.mark_index += 1 tag = 'mark%d' % (self.mark_index) tag = self.canvas.add(CanvasTypes.CompoundObject( CanvasTypes.Point(data_x, data_y, self.mark_radius, style=style, color=color, linestyle='solid'), CanvasTypes.Text(data_x + 10, data_y, "%d" % (self.mark_index), color=color)), tag=tag) self.marks.append(tag) self.w.marks.append_text(tag) self.select_mark(tag, pan=False)
def setpickregion(self, canvas, tag): obj = canvas.getObjectByTag(tag) if obj.kind != 'rectangle': return True canvas.deleteObjectByTag(tag, redraw=False) if self.picktag: try: canvas.deleteObjectByTag(self.picktag, redraw=False) except: pass # determine center of rectangle x = obj.x1 + (obj.x2 - obj.x1) // 2 y = obj.y1 + (obj.y2 - obj.y1) // 2 tag = canvas.add(CanvasTypes.CompoundObject( CanvasTypes.Rectangle(obj.x1, obj.y1, obj.x2, obj.y2, color=self.pickcolor), CanvasTypes.Point(x, y, 10, color='red'), CanvasTypes.Text(obj.x1, obj.y2 + 4, "Pick: calc", color=self.pickcolor)), redraw=False) self.picktag = tag #self.fv.raise_tab("detail") return self.redo()
def update_pick(self, serialnum, objlist, qs, x1, y1, wd, ht, fig, msg): if serialnum != self.get_serial(): return try: image = self.fitsimage.get_image() point = fig.objects[1] text = fig.objects[2] text.text = "Pick" if msg != None: raise Exception(msg) # Mark new peaks, if desired if self.show_candidates: for obj in objlist: tag = self.fitsimage.add(CanvasTypes.Point( x1 + obj.objx, y1 + obj.objy, 5, linewidth=1, color=self.candidate_color), tagpfx='peak', redraw=False) # Add back in offsets into image to get correct values with respect # to the entire image qs.x += x1 qs.y += y1 qs.objx += x1 qs.objy += y1 # Calculate X/Y of center of star obj_x = qs.objx obj_y = qs.objy self.logger.info("object center is x,y=%f,%f" % (obj_x, obj_y)) fwhm = qs.fwhm fwhm_x, fwhm_y = qs.fwhm_x, qs.fwhm_y point.x, point.y = obj_x, obj_y text.color = 'cyan' self.wdetail.fwhm_x.set_text('%.3f' % fwhm_x) self.wdetail.fwhm_y.set_text('%.3f' % fwhm_y) self.wdetail.fwhm.set_text('%.3f' % fwhm) self.wdetail.object_x.set_text('%.3f' % (obj_x + 1)) self.wdetail.object_y.set_text('%.3f' % (obj_y + 1)) self.wdetail.sky_level.set_text('%.3f' % qs.skylevel) self.wdetail.background.set_text('%.3f' % qs.background) self.wdetail.brightness.set_text('%.3f' % qs.brightness) self.w.btn_sky_cut.set_sensitive(True) self.w.btn_bright_cut.set_sensitive(True) # Mark center of object on pick image i1 = point.x - x1 j1 = point.y - y1 self.pickcenter.x = i1 self.pickcenter.y = j1 self.pickcenter.color = 'cyan' self.pick_qs = qs self.pickimage.panset_xy(i1, j1, redraw=False) # Mark object center on image point.color = 'cyan' self.fitsimage.panset_xy(obj_x, obj_y, redraw=False) # Calc RA, DEC, EQUINOX of X/Y center pixel try: ra_txt, dec_txt = image.pixtoradec(obj_x, obj_y, format='str') except Exception, e: ra_txt = 'WCS ERROR' dec_txt = 'WCS ERROR' self.wdetail.ra.set_text(ra_txt) self.wdetail.dec.set_text(dec_txt) equinox = image.get_keyword('EQUINOX', 'UNKNOWN') self.wdetail.equinox.set_text(str(equinox)) # TODO: Get separate FWHM for X and Y try: cdelt1, cdelt2 = image.get_keywords_list('CDELT1', 'CDELT2') starsize = self.iqcalc.starsize(fwhm_x, cdelt1, fwhm_y, cdelt2) self.wdetail.star_size.set_text('%.3f' % starsize) except Exception, e: self.wdetail.star_size.set_text('ERROR') self.fv.show_error("Couldn't calculate star size: %s" % (str(e)), raisetab=False)
def redo(self): serialnum = self.bump_serial() self.ev_intr.set() fig = self.canvas.getObjectByTag(self.picktag) if fig.kind != 'compound': return True bbox = fig.objects[0] point = fig.objects[1] text = fig.objects[2] data_x, data_y = point.x, point.y #self.fitsimage.panset_xy(data_x, data_y, redraw=False) # set the pick image to have the same cut levels and transforms self.fitsimage.copy_attributes(self.pickimage, ['transforms', 'cutlevels', 'rgbmap'], redraw=False) try: image = self.fitsimage.get_image() # sanity check on region width = bbox.x2 - bbox.x1 height = bbox.y2 - bbox.y1 if (width > self.max_side) or (height > self.max_side): errmsg = "Image area (%dx%d) too large!" % (width, height) self.fv.show_error(errmsg) raise Exception(errmsg) # Note: FITS coordinates are 1-based, whereas numpy FITS arrays # are 0-based fits_x, fits_y = data_x + 1, data_y + 1 # Cut and show pick image in pick window #self.pick_x, self.pick_y = data_x, data_y self.logger.debug("bbox %f,%f %f,%f" % (bbox.x1, bbox.y1, bbox.x2, bbox.y2)) x1, y1, x2, y2, data = self.cutdetail(self.fitsimage, self.pickimage, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)) self.logger.debug("cut box %f,%f %f,%f" % (x1, y1, x2, y2)) # calculate center of pick image wd, ht = self.pickimage.get_data_size() xc = wd // 2 yc = ht // 2 if not self.pickcenter: tag = self.pickimage.add( CanvasTypes.Point(xc, yc, 5, linewidth=1, color='red')) self.pickcenter = self.pickimage.getObjectByTag(tag) self.pick_x1, self.pick_y1 = x1, y1 self.pick_data = data self.wdetail.sample_area.set_text('%dx%d' % (x2 - x1, y2 - y1)) point.color = 'red' text.text = 'Pick: calc' self.pickcenter.x = xc self.pickcenter.y = yc self.pickcenter.color = 'red' # clear contour and fwhm plots if have_mpl: self.clear_contours() self.clear_fwhm() # Delete previous peak marks objs = self.fitsimage.getObjectsByTagpfx('peak') self.fitsimage.deleteObjects(objs, redraw=True) # Offload this task to another thread so that GUI remains # responsive self.fv.nongui_do(self.search, serialnum, data, x1, y1, wd, ht, fig) except Exception, e: self.logger.error("Error calculating quality metrics: %s" % (str(e))) return True