예제 #1
0
    def load_file(self, filespec, dstobj=None, **kwargs):
        info = iohelper.get_fileinfo(filespec)
        if not info.ondisk:
            raise ValueError("File does not appear to be on disk: %s" % (
                info.url))

        filepath = info.filepath
        if dstobj is None:
            # Put here to avoid circular import
            from ginga.RGBImage import RGBImage
            dstobj = RGBImage(logger=self.logger)

        header = Header()
        metadata = {'header': header, 'path': filepath}

        data_np = self._imload(filepath, header)

        # TODO: set up the channel order correctly
        dstobj.set_data(data_np, metadata=metadata)

        if dstobj.name is not None:
            dstobj.set(name=dstobj.name)
        else:
            name = iohelper.name_image_from_path(filepath, idx=None)
            dstobj.set(name=name)

        dstobj.set(path=filepath, idx=None, image_loader=self.load_file)
        return dstobj
예제 #2
0
파일: io_rgb.py 프로젝트: karllark/ginga
    def load_file(self, filespec, dstobj=None, **kwargs):
        info = iohelper.get_fileinfo(filespec)
        if not info.ondisk:
            raise ValueError("File does not appear to be on disk: %s" %
                             (info.url))

        filepath = info.filepath
        if dstobj is None:
            # Put here to avoid circular import
            from ginga.RGBImage import RGBImage
            dstobj = RGBImage(logger=self.logger)

        header = Header()
        metadata = {'header': header, 'path': filepath}

        data_np = self.imload(filepath, header)

        # TODO: set up the channel order correctly
        dstobj.set_data(data_np, metadata=metadata)

        if dstobj.name is not None:
            dstobj.set(name=dstobj.name)
        else:
            name = iohelper.name_image_from_path(filepath, idx=None)
            dstobj.set(name=name)

        dstobj.set(path=filepath, idx=None, image_loader=self.load_file)
        return dstobj
예제 #3
0
파일: io_hdf5.py 프로젝트: karllark/ginga
    def load_idx(self, idx, **kwargs):

        if idx is None:
            idx = self.find_first_good_idx()

        typ = self.get_idx_type(idx)
        if typ == 'image':
            from ginga import AstroImage, RGBImage

            header = self.get_header(idx)
            data_np = np.copy(self._f[idx].value)

            if 'PALETTE' in header:
                p_idx = header['PALETTE']
                p_data = self._f[p_idx].value
                data_np = p_data[data_np]
                image = RGBImage.RGBImage(logger=self.logger)
            else:
                image = AstroImage.AstroImage(logger=self.logger)
                image.update_keywords(header)

            image.set_data(data_np)

            name = iohelper.name_image_from_path(self._path, idx=idx)
            image.set(path=self._path, name=name, idx=idx,
                      image_loader=load_file)

            return image

        raise ValueError("I don't know how to read dataset '{}'".format(idx))
예제 #4
0
    def load_file(self, filepath, idx=None, **kwargs):

        data_obj = loader(filepath, logger=self.logger, **kwargs)

        # set important metadata
        name = iohelper.name_image_from_path(filepath, idx=None)
        data_obj.set(path=filepath, name=name, idx=idx,
                     image_loader=self.load_file)

        return data_obj
예제 #5
0
파일: io_asdf.py 프로젝트: karllark/ginga
    def load_file(self, filepath, idx=None, **kwargs):

        with asdf.open(filepath) as asdf_f:
            data_obj = load_asdf(asdf_f, idx=idx, logger=self.logger)

        # set important metadata
        name = iohelper.name_image_from_path(filepath, idx=None)
        data_obj.set(path=filepath, name=name, idx=idx, image_loader=load_file)
        data_obj.io = self

        return data_obj
예제 #6
0
    def load_file(self, filepath, idx=None, **kwargs):

        data_obj = loader(filepath, logger=self.logger, **kwargs)

        # set important metadata
        name = iohelper.name_image_from_path(filepath, idx=None)
        data_obj.set(path=filepath,
                     name=name,
                     idx=idx,
                     image_loader=self.load_file)

        return data_obj
예제 #7
0
    def have_thumbnail(self, fitsimage, image):
        """Returns True if we already have a thumbnail version of this image
        cached, False otherwise.
        """
        chname = self.fv.get_channel_name(fitsimage)

        # Look up our version of the thumb
        idx = image.get('idx', None)
        path = image.get('path', None)
        if path is not None:
            path = os.path.abspath(path)
            name = iohelper.name_image_from_path(path, idx=idx)
        else:
            name = 'NoName'

        # get image name
        name = image.get('name', name)

        thumbkey = self.get_thumb_key(chname, name, path)
        with self.thmblock:
            return thumbkey in self.thumb_dict
예제 #8
0
    def have_thumbnail(self, fitsimage, image):
        """Returns True if we already have a thumbnail version of this image
        cached, False otherwise.
        """
        chname = self.fv.get_channel_name(fitsimage)

        # Look up our version of the thumb
        idx = image.get('idx', None)
        path = image.get('path', None)
        if path is not None:
            path = os.path.abspath(path)
            name = iohelper.name_image_from_path(path, idx=idx)
        else:
            name = 'NoName'

        # get image name
        name = image.get('name', name)

        thumbkey = self.get_thumb_key(chname, name, path)
        with self.thmblock:
            return thumbkey in self.thumb_dict
예제 #9
0
파일: Control.py 프로젝트: jochym/ginga
 def name_image_from_path(self, path, idx=None):
     return iohelper.name_image_from_path(path, idx=idx)
예제 #10
0
 def _add_info(self, channel, filelist):
     for path in filelist:
         name = iohelper.name_image_from_path(path)
         info = Bunch.Bunch(name=name, path=path)
         self.fv.gui_call(channel.add_image_info, info)
예제 #11
0
    def redo(self):
        """Called when an image is set in the channel."""
        image = self.channel.get_current_image()
        if image is None:
            return True

        path = image.get('path', None)
        if path is None:
            self.fv.show_error(
                "Cannot open image: no value for metadata key 'path'")
            return

        # TODO: How to properly reset GUI components?
        #       They are still showing info from prev FITS.
        # No-op for ASDF
        if path.endswith('.asdf'):
            return True

        if path != self.img_path:
            # <-- New file is being looked at
            self.img_path = path

            # close previous file opener, if any
            if self.file_obj is not None:
                try:
                    self.file_obj.close()
                except Exception:
                    pass

            self.file_obj = image.io

            # TODO: specify 'readonly' somehow?
            self.file_obj.open_file(path)
            hdu_dct = self.file_obj.get_directory()

            upper = len(self.file_obj) - 1
            # NOTE: make a set of values, because some values will be in
            # multiple times if known by several indexes
            self.prep_hdu_menu(self.w.hdu, list(set(hdu_dct.values())))
            self.num_hdu = upper
            self.logger.debug("there are %d hdus" % (upper + 1))
            self.w.numhdu.set_text("%d" % (upper + 1))

            self.w.hdu.set_enabled(len(self.file_obj) > 0)
        else:
            hdu_dct = self.file_obj.get_directory()

        name = image.get('name', iohelper.name_image_from_path(path))
        idx = image.get('idx', None)
        # remove index designation from root of name, if any
        match = re.match(r'^(.+)\[(.+)\]$', name)
        if match:
            name = match.group(1)
        self.name_pfx = name

        htype = None
        if idx is not None:
            # set the HDU in the drop down if known
            info = hdu_dct.get(idx, None)
            if info is not None:
                htype = info.htype.lower()
                toc_ent = self._toc_fmt % info
                self.w.hdu.show_text(toc_ent)

        # rebuild the NAXIS controls, if necessary
        # No two images in the same channel can have the same name.
        # Here we keep track of the name to decide if we need to rebuild
        if self.img_name != name:
            self.img_name = name
            dims = [0, 0]
            data = image.get_data()
            if data is None:
                # <- empty data part to this HDU
                self.logger.warning("Empty data part in HDU %s" % (str(idx)))

            elif htype in (
                    'bintablehdu',
                    'tablehdu',
            ):
                pass

            elif htype not in ('imagehdu', 'primaryhdu', 'compimagehdu'):
                self.logger.warning("HDU %s is not an image (%s)" %
                                    (str(idx), htype))

            else:
                mddata = image.get_mddata()
                if mddata is not None:
                    dims = list(mddata.shape)
                    dims.reverse()

            self.build_naxis(dims, image)
예제 #12
0
    def redo(self):
        """Called when an image is set in the channel."""
        image = self.channel.get_current_image()
        if image is None:
            return True

        path = image.get('path', None)
        if path is None:
            self.fv.show_error(
                "Cannot open image: no value for metadata key 'path'")
            return

        # TODO: How to properly reset GUI components?
        #       They are still showing info from prev FITS.
        # No-op for ASDF
        if path.endswith('asdf'):
            return True

        if path != self.img_path:
            # <-- New file is being looked at
            self.img_path = path

            # close previous file opener, if any
            if self.file_obj is not None:
                try:
                    self.file_obj.close()
                except Exception:
                    pass

            self.file_obj = io_fits.get_fitsloader(logger=self.logger)

            # TODO: specify 'readonly' somehow?
            self.file_obj.open_file(path)

            upper = len(self.file_obj) - 1
            self.prep_hdu_menu(self.w.hdu, self.file_obj.hdu_info)
            self.num_hdu = upper
            self.logger.debug("there are %d hdus" % (upper + 1))
            self.w.numhdu.set_text("%d" % (upper + 1))

            self.w.hdu.set_enabled(len(self.file_obj) > 0)

        name = image.get('name', iohelper.name_image_from_path(path))
        idx = image.get('idx', None)
        # remove index designation from root of name, if any
        match = re.match(r'^(.+)\[(.+)\]$', name)
        if match:
            name = match.group(1)
        self.name_pfx = name

        htype = None
        if idx is not None:
            # set the HDU in the drop down if known
            info = self.file_obj.hdu_db.get(idx, None)
            if info is not None:
                htype = info.htype.lower()
                toc_ent = self._toc_fmt % info
                self.w.hdu.show_text(toc_ent)

        # rebuild the NAXIS controls, if necessary
        # No two images in the same channel can have the same name.
        # Here we keep track of the name to decide if we need to rebuild
        if self.img_name != name:
            self.img_name = name
            dims = [0, 0]
            data = image.get_data()
            if data is None:
                # <- empty data part to this HDU
                self.logger.warning("Empty data part in HDU %s" % (str(idx)))

            elif htype in ('bintablehdu', 'tablehdu',):
                pass

            elif htype not in ('imagehdu', 'primaryhdu', 'compimagehdu'):
                self.logger.warning("HDU %s is not an image (%s)" % (
                    str(idx), htype))

            else:
                mddata = image.get_mddata()
                if mddata is not None:
                    dims = list(mddata.shape)
                    dims.reverse()

            self.build_naxis(dims, image)
예제 #13
0
 def _add_info(self, channel, filelist):
     for path in filelist:
         name = iohelper.name_image_from_path(path)
         info = Bunch.Bunch(name=name, path=path)
         self.fv.gui_call(channel.add_image_info, info)