def auto_mosaic(self): """Create new mosaic using image list from Contents.""" astroimage_obj = AstroImage() self._imlist = {} self._recreate_fp = True self.treeview.clear() self.treeviewsel.clear() # Get image list from Contents, excluding other mosaics file_dict = self.list_plugin_obj.name_dict[self.chname] for bnch in six.itervalues(file_dict): if ((not isinstance(bnch, Bunch.Bunch)) or ('mosaic' in bnch.NAME.lower())): continue # Calculate image footprint, counter-clockwise from # bottom-left. Format is [[X1, Y1], ..., [X4, Y4]] imname = bnch.NAME impath = bnch.path datasrc = self.chinfo.datasrc if imname in datasrc: image = datasrc[imname] else: image = astroimage_obj image.load_file(impath) footprint = image.wcs.wcs.calc_footprint() # Astropy only? self._imlist[imname] = Bunch.Bunch(footprint=footprint, path=impath) if len(self._imlist) == 0: s = 'No images available for mosaic' self.logger.error(s) self.update_status(s) return True # Always start a new mosaic. # Remove duplicates in case an image have multiple extensions opened. images = list(set([bnch.path for bnch in six.itervalues(self._imlist)])) self.fv.nongui_do(self.fv.error_wrap, self.mosaic, images, new_mosaic=True) self.fitsimage.auto_levels() # Only allow this to happen once, otherwise footprint highlighting # gets confusing. self.w.create_mosaic.set_enabled(False) self.w.select_all.set_enabled(True) self.w.deselect_all.set_enabled(True) # Populate table listing. treedict = Bunch.caselessDict() for imname in self._imlist: treedict[imname] = Bunch.Bunch(IMAGE=imname) self.treeview.set_tree(treedict) return True
def hl_table2canvas(self, w, res_dict): """Highlight marking on canvas when user click on table.""" objlist = [] width = self.markwidth + self._dwidth # Remove existing highlight if self.markhltag: try: self.canvas.delete_object_by_tag(self.markhltag, redraw=False) except: pass # Display highlighted entries only in second table self.treeviewsel.set_tree(res_dict) for kstr, sub_dict in iteritems(res_dict): s = kstr.split(',') marktype = s[0] marksize = float(s[1]) markcolor = s[2] for bnch in itervalues(sub_dict): obj = self._get_markobj(bnch.X - self.pixelstart, bnch.Y - self.pixelstart, marktype, marksize, markcolor, width) objlist.append(obj) nsel = len(objlist) self.w.nselected.set_text(str(nsel)) # Draw on canvas if nsel > 0: self.markhltag = self.canvas.add(self.dc.CompoundObject(*objlist)) self.fitsimage.redraw() # Force immediate redraw
def _write_history(self, pfx, hdu, linechar=60, indentchar=2): """Write change history to given HDU header. Limit each HISTORY line to given number of characters. Subsequent lines of the same history will be indented. """ if self.history_obj is None: return channel = self.fv.get_channelInfo() if channel is None: return file_dict = self.history_obj.name_dict[channel.name] chistory = [] ind = ' ' * indentchar # NOTE: List comprehension too slow! for key in file_dict: if not key.startswith(pfx): continue for bnch in itervalues(file_dict[key]): chistory.append('{0} {1}'.format(bnch.MODIFIED, bnch.DESCRIP)) # Add each HISTORY prettily into header, sorted by timestamp for s in sorted(chistory): for i in range(0, len(s), linechar): subs = s[i:i+linechar] if i > 0: subs = ind + subs.lstrip() hdu.header.add_history(subs)
def hl_table2canvas(self, w, res_dict): """Highlight marking on canvas when user click on table.""" objlist = [] width = self.markwidth + self._dwidth # Remove existing highlight if self.markhltag: try: self.canvas.deleteObjectByTag(self.markhltag, redraw=False) except: pass # Display highlighted entries only in second table self.treeviewsel.set_tree(res_dict) for kstr, sub_dict in iteritems(res_dict): s = kstr.split(',') marktype = s[0] marksize = float(s[1]) markcolor = s[2] for bnch in itervalues(sub_dict): obj = self._get_markobj(bnch.X - self.pixelstart, bnch.Y - self.pixelstart, marktype, marksize, markcolor, width) objlist.append(obj) nsel = len(objlist) self.w.nselected.set_text(str(nsel)) # Draw on canvas if nsel > 0: self.markhltag = self.canvas.add(self.dc.CompoundObject(*objlist)) self.fitsimage.redraw() # Force immediate redraw
def hl_table2canvas(self, w, res_dict): """Highlight mask on canvas when user click on table.""" objlist = [] # Remove existing highlight if self.maskhltag: try: self.canvas.delete_object_by_tag(self.maskhltag, redraw=False) except: pass for sub_dict in itervalues(res_dict): for seqno in sub_dict: mobj = self._maskobjs[int(seqno) - 1] dat = self._rgbtomask(mobj) obj = self.dc.Image( 0, 0, masktorgb(dat, color=self.hlcolor, alpha=self.hlalpha)) objlist.append(obj) # Draw on canvas if len(objlist) > 0: self.maskhltag = self.canvas.add(self.dc.CompoundObject(*objlist)) self.fitsimage.redraw() # Force immediate redraw
def auto_mosaic(self): """Create new mosaic using image list from Contents.""" astroimage_obj = AstroImage() self._imlist = {} # Get image list from Contents, excluding other mosaics file_dict = self.list_plugin_obj.name_dict[self.chname] for bnch in itervalues(file_dict): if ((not isinstance(bnch, Bunch.Bunch)) or ('mosaic' in bnch.NAME.lower())): continue # Calculate image footprint, counter-clockwise from # bottom-left. Format is [[X1, Y1], ..., [X4, Y4]] imname = bnch.NAME impath = bnch.path datasrc = self.chinfo.datasrc if imname in datasrc: image = datasrc[imname] else: image = astroimage_obj image.load_file(impath) footprint = image.wcs.wcs.calc_footprint() self._imlist[imname] = Bunch.Bunch( footprint=footprint, path=impath) self.recreate_imlist() if len(self._imlist) == 0: s = 'No images available for mosaic' self.logger.error(s) self.update_status(s) return True # Always start a new mosaic. # Remove duplicates in case an image have multiple extensions opened. images = list(set([bnch.path for bnch in itervalues(self._imlist)])) self.fv.nongui_do(self.fv.error_wrap, self.mosaic, images, new_mosaic=True) self.fitsimage.auto_levels() # Only allow this to happen once, otherwise footprint highlighting # gets confusing. self.w.create_mosaic.set_enabled(False) return True
def recreate_toc(self): self.logger.debug('Recreating table of contents...') self.treeview.set_tree(self.tree_dict) n = 0 for sub_dict in itervalues(self.tree_dict): n += len(sub_dict) self.w.nshown.set_text(str(n))
def _write_history(self, pfx, hdu, linechar=60, indentchar=2): """Write change history to given HDU header. Limit each HISTORY line to given number of characters. Subsequent lines of the same history will be indented. """ channel = self.fv.get_channelInfo(self.chname) if channel is None: return history_plgname = 'ChangeHistory' try: history_obj = self.fv.gpmon.getPlugin(history_plgname) except: self.logger.error( '{0} plugin is not loaded. No HISTORY will be written to ' '{1}.'.format(history_plgname, pfx)) return if channel.name not in history_obj.name_dict: self.logger.error( '{0} channel not found in {1}. No HISTORY will be written to ' '{2}.'.format(channel.name, history_plgname, pfx)) return file_dict = history_obj.name_dict[channel.name] chistory = [] ind = ' ' * indentchar # NOTE: List comprehension too slow! for key in file_dict: if not key.startswith(pfx): continue for bnch in itervalues(file_dict[key]): chistory.append('{0} {1}'.format(bnch.MODIFIED, bnch.DESCRIP)) # Add each HISTORY prettily into header, sorted by timestamp for s in sorted(chistory): for i in range(0, len(s), linechar): subs = s[i:i+linechar] if i > 0: subs = ind + subs.lstrip() hdu.header.add_history(subs)
def set_table_cb(self, viewer, table): """Display the given table object.""" self.clear() tree_dict = OrderedDict() # Extract data as astropy table a_tab = table.get_data() # Fill masked values, if applicable try: a_tab = a_tab.filled() except Exception: # Just use original table pass # This is to get around table widget not sorting numbers properly i_fmt = '{{0:0{0}d}}'.format(len(str(len(a_tab)))) # Table header with units columns = [('Row', '_DISPLAY_ROW')] for c in itervalues(a_tab.columns): col_str = '{0:^s}\n{1:^s}'.format(c.name, str(c.unit)) columns.append((col_str, c.name)) self.widget.setup_table(columns, 1, '_DISPLAY_ROW') # Table contents for i, row in enumerate(a_tab, 1): bnch = Bunch.Bunch(zip(row.colnames, row.as_void())) i_str = i_fmt.format(i) bnch['_DISPLAY_ROW'] = i_str tree_dict[i_str] = bnch self.widget.set_tree(tree_dict) # Resize column widths n_rows = len(tree_dict) if n_rows < self.settings.get('max_rows_for_col_resize', 5000): self.widget.set_optimal_column_widths() self.logger.debug('Resized columns for {0} row(s)'.format(n_rows)) tablename = table.get('name', 'NoName') self.logger.debug('Displayed {0}'.format(tablename))
def _write_history(self, pfx, hdu, linechar=60, indentchar=2): """Write change history to given HDU header. Limit each HISTORY line to given number of characters. Subsequent lines of the same history will be indented. """ channel = self.fv.get_channelInfo(self.chname) if channel is None: return history_plgname = 'ChangeHistory' try: history_obj = self.fv.gpmon.getPlugin(history_plgname) except: self.logger.error( '{0} plugin is not loaded. No HISTORY will be written to ' '{1}.'.format(history_plgname, pfx)) return if channel.name not in history_obj.name_dict: self.logger.error( '{0} channel not found in {1}. No HISTORY will be written to ' '{2}.'.format(channel.name, history_plgname, pfx)) return file_dict = history_obj.name_dict[channel.name] chistory = [] ind = ' ' * indentchar # NOTE: List comprehension too slow! for key in file_dict: if not key.startswith(pfx): continue for bnch in itervalues(file_dict[key]): chistory.append('{0} {1}'.format(bnch.MODIFIED, bnch.DESCRIP)) # Add each HISTORY prettily into header, sorted by timestamp for s in sorted(chistory): for i in range(0, len(s), linechar): subs = s[i:i + linechar] if i > 0: subs = ind + subs.lstrip() hdu.header.add_history(subs)
def hl_table2canvas(self, w, res_dict): """Highlight mask on canvas when user click on table.""" objlist = [] # Remove existing highlight if self.maskhltag: try: self.canvas.delete_object_by_tag(self.maskhltag, redraw=False) except: pass for sub_dict in itervalues(res_dict): for seqno in sub_dict: mobj = self._maskobjs[int(seqno) - 1] dat = self._rgbtomask(mobj) obj = self.dc.Image(0, 0, masktorgb( dat, color=self.hlcolor, alpha=self.hlalpha)) objlist.append(obj) # Draw on canvas if len(objlist) > 0: self.maskhltag = self.canvas.add(self.dc.CompoundObject(*objlist)) self.fitsimage.redraw() # Force immediate redraw