Exemplo n.º 1
0
    def save_images(self):
        """Save selected images.

        This uses Astropy FITS package to save the outputs no matter
        what user chose to load the images.

        """
        res_dict = self.treeview.get_selected()
        clobber = self.settings.get('clobber', False)
        self.treeview.clear_selection()  # Automatically disables Save button

        # If user gives empty string, no suffix.
        if self.suffix:
            sfx = '_' + self.suffix
        else:
            sfx = ''

        # Also include channel name in suffix. This is useful if user likes to
        # open the same image in multiple channels.
        if self.settings.get('include_chname', True):
            sfx += '_' + self.chname

        # Process each selected file. Each can have multiple edited extensions.
        for infile in res_dict:
            f_pfx = os.path.splitext(infile)[0]  # prefix
            f_ext = '.fits'  # Only FITS supported
            oname = f_pfx + sfx + f_ext
            outfile = os.path.join(self.outdir, oname)

            self.w.status.set_text(
                'Writing out {0} to {1} ...'.format(shorten_name(infile, 10),
                                                    shorten_name(oname, 10)))
            self.logger.debug(
                'Writing out {0} to {1} ...'.format(infile, oname))

            if os.path.exists(outfile) and not clobber:
                self.logger.error('{0} already exists'.format(outfile))
                continue

            bnch = res_dict[infile]

            if bnch.path is None or not os.path.isfile(bnch.path):
                self._write_mosaic(f_pfx, outfile)
            else:
                shutil.copyfile(bnch.path, outfile)
                self._write_mef(f_pfx, bnch.extlist, outfile)

            self.logger.info('{0} written'.format(outfile))

        self.w.status.set_text('Saving done, see log')
Exemplo n.º 2
0
    def save_images(self):
        """Save selected images.

        This uses Astropy FITS package to save the outputs no matter
        what user chose to load the images.

        """
        res_dict = self.treeview.get_selected()
        clobber = self.settings.get('clobber', False)
        self.treeview.clear_selection()  # Automatically disables Save button

        # If user gives empty string, no suffix.
        if self.suffix:
            sfx = '_' + self.suffix
        else:
            sfx = ''

        # Also include channel name in suffix. This is useful if user likes to
        # open the same image in multiple channels.
        if self.settings.get('include_chname', True):
            sfx += '_' + self.chname

        # Process each selected file. Each can have multiple edited extensions.
        for infile in res_dict:
            f_pfx = os.path.splitext(infile)[0]  # prefix
            f_ext = '.fits'  # Only FITS supported
            oname = f_pfx + sfx + f_ext
            outfile = os.path.join(self.outdir, oname)

            self.w.status.set_text(
                'Writing out {0} to {1} ...'.format(shorten_name(infile, 10),
                                                    shorten_name(oname, 10)))
            self.logger.debug(
                'Writing out {0} to {1} ...'.format(infile, oname))

            if os.path.exists(outfile) and not clobber:
                self.logger.error('{0} already exists'.format(outfile))
                continue

            bnch = res_dict[infile]

            if bnch.path is None or not os.path.isfile(bnch.path):
                self._write_mosaic(f_pfx, outfile)
            else:
                shutil.copyfile(bnch.path, outfile)
                self._write_mef(f_pfx, bnch.extlist, outfile)

            self.logger.info('{0} written'.format(outfile))

        self.w.status.set_text('Saving done, see log')
Exemplo n.º 3
0
    def add_image_cb(self, viewer, chname, image, image_info):
        if not self.gui_up:
            return False

        # image is flagged not to make a thumbnail?
        nothumb = image.get('nothumb', False)
        if nothumb:
            return

        idx = image.get('idx', None)
        # get image path
        path = image_info.path

        if path is not None:
            path = os.path.abspath(path)
        name = image_info.name

        thumbname = name
        self.logger.info("making thumb for %s" % (thumbname))

        future = image_info.image_future

        # Is there a preference set to avoid making thumbnails?
        chinfo = self.fv.get_channelInfo(chname)
        prefs = chinfo.settings
        if not prefs.get('genthumb', False):
            return

        # Is this thumbnail already in the list?
        # NOTE: does not handle two separate images with the same path
        # in the same channel
        thumbkey = self.get_thumb_key(chname, name, path)
        with self.thmblock:
            if thumbkey in self.thumbDict:
                return

        # Get metadata for mouse-over tooltip
        header = image.get_header()
        metadata = {}
        for kwd in self.keywords:
            metadata[kwd] = header.get(kwd, 'N/A')
        metadata[self.settings.get('mouseover_name_key','NAME')] = name

        thumbpath = self.get_thumbpath(path)

        with self.thmblock:
            self.copy_attrs(chinfo.fitsimage)
            self.thumb_generator.set_image(image)
            imgwin = self.thumb_generator.get_image_as_widget()

        label_length = self.settings.get('label_length', None)
        label_cutoff = self.settings.get('label_cutoff', 'right')

        # Shorten thumbnail label, if requested
        if label_length is not None:
            thumbname = iohelper.shorten_name(thumbname, label_length,
                                              side=label_cutoff)

        self.insert_thumbnail(imgwin, thumbkey, thumbname, chname, name, path,
                              thumbpath, metadata, future)
Exemplo n.º 4
0
    def add_image_cb(self, viewer, chname, image, image_info):
        if not self.gui_up:
            return False

        # image is flagged not to make a thumbnail?
        nothumb = image.get('nothumb', False)
        if nothumb:
            return

        idx = image.get('idx', None)
        # get image path
        path = image_info.path

        if path is not None:
            path = os.path.abspath(path)
        name = image_info.name

        thumbname = name
        self.logger.info("making thumb for %s" % (thumbname))

        future = image_info.image_future

        # Is there a preference set to avoid making thumbnails?
        chinfo = self.fv.get_channelInfo(chname)
        prefs = chinfo.settings
        if not prefs.get('genthumb', False):
            return

        # Is this thumbnail already in the list?
        # NOTE: does not handle two separate images with the same path
        # in the same channel
        thumbkey = self.get_thumb_key(chname, name, path)
        with self.thmblock:
            if thumbkey in self.thumbDict:
                return

        # Get metadata for mouse-over tooltip
        header = image.get_header()
        metadata = {}
        for kwd in self.keywords:
            metadata[kwd] = header.get(kwd, 'N/A')
        metadata[self.settings.get('mouseover_name_key','NAME')] = name

        thumbpath = self.get_thumbpath(path)

        with self.thmblock:
            self.copy_attrs(chinfo.fitsimage)
            self.thumb_generator.set_image(image)
            imgwin = self.thumb_generator.get_image_as_widget()

        label_length = self.settings.get('label_length', None)
        label_cutoff = self.settings.get('label_cutoff', 'right')

        # Shorten thumbnail label, if requested
        if label_length is not None:
            thumbname = iohelper.shorten_name(thumbname, label_length,
                                              side=label_cutoff)

        self.insert_thumbnail(imgwin, thumbkey, thumbname, chname, name, path,
                              thumbpath, metadata, future)
Exemplo n.º 5
0
    def show_more(self, widget, res_dict):
        chname = list(res_dict.keys())[0]
        img_dict = res_dict[chname]
        imname = list(img_dict.keys())[0]
        entries = img_dict[imname]
        timestamp = list(entries.keys())[0]
        bnch = entries[timestamp]

        # Display on GUI
        self.w.chname.set_text(chname)
        self.w.imname.set_text(shorten_name(imname, 25))
        self.w.modified.set_text(timestamp)
        self.w.descrip.set_text(bnch.DESCRIP)
Exemplo n.º 6
0
    def show_more(self, widget, res_dict):
        chname = list(res_dict.keys())[0]
        img_dict = res_dict[chname]
        imname = list(img_dict.keys())[0]
        entries = img_dict[imname]
        timestamp = list(entries.keys())[0]
        bnch = entries[timestamp]

        # Display on GUI
        self.w.chname.set_text(chname)
        self.w.imname.set_text(shorten_name(imname, 25))
        self.w.modified.set_text(timestamp)
        self.w.descrip.set_text(bnch.DESCRIP)
Exemplo n.º 7
0
    def show_more(self, widget, res_dict):
        try:
            chname = list(res_dict.keys())[0]
            img_dict = res_dict[chname]
            imname = list(img_dict.keys())[0]
            entries = img_dict[imname]
            timestamp = list(entries.keys())[0]
            bnch = entries[timestamp]
        except Exception:  # The drop-down row is selected, nothing to show
            return

        # Display on GUI
        self.w.chname.set_text(chname)
        self.w.imname.set_text(shorten_name(imname, 25))
        self.w.modified.set_text(timestamp)
        self.w.descrip.set_text(bnch.DESCRIP)
Exemplo n.º 8
0
    def show_more(self, widget, res_dict):
        try:
            chname = list(res_dict.keys())[0]
            img_dict = res_dict[chname]
            imname = list(img_dict.keys())[0]
            entries = img_dict[imname]
            timestamp = list(entries.keys())[0]
            bnch = entries[timestamp]
        except Exception:  # The drop-down row is selected, nothing to show
            return

        # Display on GUI
        self.w.chname.set_text(chname)
        self.w.imname.set_text(shorten_name(imname, 25))
        self.w.modified.set_text(timestamp)
        self.w.descrip.set_text(bnch.DESCRIP)
Exemplo n.º 9
0
    def insert_thumbnail(self, thumb_img, thumbkey, chname,
                         thumbpath, metadata, info):

        thumbname = info.name
        self.logger.debug("inserting thumb %s" % (thumbname))
        # make a context menu
        menu = self._mk_context_menu(thumbkey, chname, info)  # noqa

        # Get any previously stored thumb information in the image info
        thumb_extra = info.setdefault('thumb_extras', Bunch.Bunch())

        # If there is no previously made tooltip, then generate one
        if 'tooltip' in thumb_extra:
            text = thumb_extra.tooltip
        else:
            text = self._mk_tooltip_text(metadata)
            thumb_extra.tooltip = text

        canvas = self.c_view.get_canvas()
        fg = self.settings.get('label_font_color', 'black')
        fontsize = self.settings.get('label_font_size', 10)

        # Shorten thumbnail label, if requested
        label_length = self.settings.get('label_length', None)
        label_cutoff = self.settings.get('label_cutoff', None)

        if label_length is not None:
            if label_cutoff is not None:
                thumbname = iohelper.shorten_name(thumbname, label_length,
                                                  side=label_cutoff)
            else:
                thumbname = thumbname[:label_length]

        with self.thmblock:
            row, col = self.thumb_row_count, self.thumb_col_count
            self.thumb_col_count = (self.thumb_col_count + 1) % self.thumb_num_cols
            if self.thumb_col_count == 0:
                self.thumb_row_count += 1

            xt, yt, xi, yi = self._calc_thumb_pos(row, col)
            l2 = []
            namelbl = canvas.dc.Text(xt, yt, thumbname, color=fg,
                                     fontsize=fontsize, coord='data')
            l2.append(namelbl)

            image = canvas.dc.Image(xi, yi, thumb_img, alpha=1.0,
                                    linewidth=1, color='black', coord='data')
            l2.append(image)

            obj = canvas.dc.CompoundObject(*l2, coord='data')
            obj.pickable = True
            obj.opaque = True
            obj.set_data(row=row, col=col)

            bnch = Bunch.Bunch(widget=obj, image=image, info=info,
                               namelbl=namelbl,
                               chname=chname,
                               thumbpath=thumbpath)

            self.thumb_dict[thumbkey] = bnch
            if thumbkey not in self.thumb_list:
                self.thumb_list.append(thumbkey)

            # set the load callback
            obj.add_callback('pick-down',
                             lambda *args: self.load_file(thumbkey, chname,
                                                          info))
            # set callbacks for tool tips
            obj.add_callback('pick-enter', self.show_tt,
                             thumbkey, chname, info, True)
            obj.add_callback('pick-leave', self.show_tt,
                             thumbkey, chname, info, False)

            # thumb will be added to canvas later in reorder_thumbs()

            sort_order = self.settings.get('sort_order', None)
            if sort_order:
                self.thumb_list.sort()
            self.logger.debug("added thumb for %s" % (info.name))

        self.fv.gui_do_oneshot('thumbs-reorder', self.reorder_thumbs,
                               new_thumbkey=thumbkey)
Exemplo n.º 10
0
    def save_images(self):
        """Save selected images and output XML files.
        """
        output_images = []

        res_dict = self.treeview.get_selected()
        clobber = self.settings.get('clobber', False)
        self.treeview.clear_selection()  # Automatically disables Save button

        # If user gives empty string, no suffix.
        if self.suffix:
            sfx = '_' + self.suffix
        else:
            sfx = ''

        # Also include channel name in suffix. This is useful if user likes to
        # open the same image in multiple channels.
        if self.settings.get('include_chname', True):
            sfx += '_' + self.chname

        # Process each selected file. Each can have multiple edited extensions.
        for infile in res_dict:
            f_pfx = os.path.splitext(infile)[0]  # prefix
            f_ext = '.fits'  # Only FITS supported
            oname = f_pfx + sfx + f_ext
            outfile = os.path.join(self.outdir, oname)

            self.w.status.set_text(
                'Writing out {0} to {1} ...'.format(shorten_name(infile, 10),
                                                    shorten_name(oname, 10)))
            self.logger.debug(
                'Writing out {0} to {1} ...'.format(infile, oname))

            if os.path.exists(outfile) and not clobber:
                self.logger.error('{0} already exists'.format(outfile))
                continue

            bnch = res_dict[infile]

            if bnch.path is None or not os.path.isfile(bnch.path):
                self._write_mosaic(f_pfx, outfile)
            else:
                shutil.copyfile(bnch.path, outfile)
                self._write_mef(f_pfx, bnch.extlist, outfile)

            output_images.append(outfile)
            self.logger.info('{0} written'.format(outfile))

        # Save QUIP Log, which stores change history
        self.logger.info('Saving {0}'.format(self.logfile))
        try:
            self._write_quiplog()
        except Exception as e:
            self.w.status.set_text('Cannot write QUIP log!')
            self.logger.error(str(e))
            return

        # Save QUIP Out, which stores output image list
        self.logger.info('Saving {0}'.format(self.stafile))
        try:
            output_xml(quip_out_dict(images=output_images), self.stafile)
        except Exception as e:
            self.w.status.set_text('Cannot write QUIP out!')
            self.logger.error(str(e))
            return

        self.w.status.set_text('Done! Quit Ginga to exit QUIP')
Exemplo n.º 11
0
    def insert_thumbnail(self, thumb_img, thumbkey, chname,
                         thumbpath, metadata, info):

        thumbname = info.name
        self.logger.debug("inserting thumb %s" % (thumbname))
        # make a context menu
        menu = self._mk_context_menu(thumbkey, chname, info)  # noqa

        # Get any previously stored thumb information in the image info
        thumb_extra = info.setdefault('thumb_extras', Bunch.Bunch())

        # If there is no previously made tooltip, then generate one
        if 'tooltip' in thumb_extra:
            text = thumb_extra.tooltip
        else:
            text = self._mk_tooltip_text(metadata)
            thumb_extra.tooltip = text

        canvas = self.thumb_generator.get_canvas()
        fg = self.settings.get('label_font_color', 'black')
        fontsize = self.settings.get('label_font_size', 10)

        # Shorten thumbnail label, if requested
        label_length = self.settings.get('label_length', None)
        label_cutoff = self.settings.get('label_cutoff', None)

        if label_length is not None:
            if label_cutoff is not None:
                thumbname = iohelper.shorten_name(thumbname, label_length,
                                                  side=label_cutoff)
            else:
                thumbname = thumbname[:label_length]

        with self.thmblock:
            row, col = self.thumb_row_count, self.thumb_col_count
            self.thumb_col_count = (self.thumb_col_count + 1) % self.thumb_num_cols
            if self.thumb_col_count == 0:
                self.thumb_row_count += 1

            xt, yt, xi, yi = self._calc_thumb_pos(row, col)
            l2 = []
            namelbl = canvas.dc.Text(xt, yt, thumbname, color=fg,
                                     fontsize=fontsize, coord='data')
            l2.append(namelbl)

            image = canvas.dc.Image(xi, yi, thumb_img, alpha=1.0,
                                    linewidth=1, color='black', coord='data')
            l2.append(image)

            obj = canvas.dc.CompoundObject(*l2, coord='data')
            obj.pickable = True
            obj.opaque = True
            obj.set_data(row=row, col=col)

            bnch = Bunch.Bunch(widget=obj, image=image, info=info,
                               namelbl=namelbl,
                               chname=chname,
                               thumbpath=thumbpath)

            self.thumb_dict[thumbkey] = bnch
            if thumbkey not in self.thumb_list:
                self.thumb_list.append(thumbkey)

            # set the load callback
            obj.add_callback('pick-down',
                             lambda *args: self.load_file(thumbkey, chname,
                                                          info))
            # set callbacks for tool tips
            obj.add_callback('pick-enter', self.show_tt,
                             thumbkey, chname, info, True)
            obj.add_callback('pick-leave', self.show_tt,
                             thumbkey, chname, info, False)

            # thumb will be added to canvas later in reorder_thumbs()

            sort_order = self.settings.get('sort_order', None)
            if sort_order:
                self.thumb_list.sort()
            self.logger.debug("added thumb for %s" % (info.name))

        self.fv.gui_do_oneshot('thumbs-reorder', self.reorder_thumbs,
                               new_thumbkey=thumbkey)
Exemplo n.º 12
0
    def save_images(self):
        """Save selected images and output XML files.
        """
        output_images = []

        res_dict = self.treeview.get_selected()
        clobber = self.settings.get('clobber', False)
        self.treeview.clear_selection()  # Automatically disables Save button

        # If user gives empty string, no suffix.
        if self.suffix:
            sfx = '_' + self.suffix
        else:
            sfx = ''

        # Also include channel name in suffix. This is useful if user likes to
        # open the same image in multiple channels.
        if self.settings.get('include_chname', True):
            sfx += '_' + self.chname

        # Process each selected file. Each can have multiple edited extensions.
        for infile in res_dict:
            f_pfx = os.path.splitext(infile)[0]  # prefix
            f_ext = '.fits'  # Only FITS supported
            oname = f_pfx + sfx + f_ext
            outfile = os.path.join(self.outdir, oname)

            self.w.status.set_text(
                'Writing out {0} to {1} ...'.format(shorten_name(infile, 10),
                                                    shorten_name(oname, 10)))
            self.logger.debug(
                'Writing out {0} to {1} ...'.format(infile, oname))

            if os.path.exists(outfile) and not clobber:
                self.logger.error('{0} already exists'.format(outfile))
                continue

            bnch = res_dict[infile]

            if bnch.path is None or not os.path.isfile(bnch.path):
                self._write_mosaic(f_pfx, outfile)
            else:
                shutil.copyfile(bnch.path, outfile)
                self._write_mef(f_pfx, bnch.extlist, outfile)

            output_images.append(outfile)
            self.logger.info('{0} written'.format(outfile))

        # Save QUIP Log, which stores change history
        self.logger.info('Saving {0}'.format(self.logfile))
        try:
            self._write_quiplog()
        except Exception as e:
            self.w.status.set_text('Cannot write QUIP log!')
            self.logger.error(str(e))
            return

        # Save QUIP Out, which stores output image list
        self.logger.info('Saving {0}'.format(self.stafile))
        try:
            output_xml(quip_out_dict(images=output_images), self.stafile)
        except Exception as e:
            self.w.status.set_text('Cannot write QUIP out!')
            self.logger.error(str(e))
            return

        self.w.status.set_text('Done! Quit Ginga to exit QUIP')