How to use the ginga.AstroImage.AstroImage function in ginga

To help you get started, we’ve selected a few ginga examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ejeschke / ginga / ginga / util / dp.py View on Github external
def make_image(data_np, oldimage, header, pfx='dp'):
    # Prepare a new image with the numpy array as data
    image = AstroImage.AstroImage()
    image.set_data(data_np)
    # Set the header to be the old image header updated
    # with items from the new header
    oldhdr = oldimage.get_header()
    oldhdr.update(header)
    image.update_keywords(oldhdr)
    # give the image a name
    get_image_name(image, pfx=pfx)
    return image
github ejeschke / ginga / ginga / rv / plugins / RC.py View on Github external
# Unpack the data
        try:
            # Uncompress data if necessary
            decompress = metadata.get('decompress', None)
            if compressed or (decompress == 'bz2'):
                img_buf = bz2.decompress(img_buf)

            # dtype string works for most instances
            if dtype == '':
                dtype = np.float

            byteswap = metadata.get('byteswap', False)

            # Create image container
            image = AstroImage.AstroImage(logger=self.logger)
            image.load_buffer(img_buf, dims, dtype, byteswap=byteswap,
                              metadata=metadata)
            image.update_keywords(header)
            image.set(name=imname, path=None)

        except Exception as e:
            # Some kind of error unpacking the data
            errmsg = "Error creating image data for '%s': %s" % (
                imname, str(e))
            self.logger.error(errmsg)
            raise GingaPlugin.PluginError(errmsg)

        # Display the image
        channel = self.fv.gui_call(self.fv.get_channel_on_demand, chname)

        # Note: this little hack needed to let window resize in time for
github ejeschke / ginga / ginga / AstroImage.py View on Github external
def info_xy(self, data_x, data_y, settings):
        info = super(AstroImage, self).info_xy(data_x, data_y, settings)

        system = settings.get('wcs_coords', None)
        format = settings.get('wcs_display', 'sexagesimal')
        ra_lbl, dec_lbl = chr(945), chr(948)

        # Calculate WCS coords, if available
        try:
            if self.wcs is None:
                self.logger.debug("No WCS for this image")
                ra_txt = dec_txt = 'NO WCS'

            elif self.wcs.coordsys == 'raw':
                self.logger.debug("No coordinate system determined")
                ra_txt = dec_txt = 'NO WCS'

            elif self.wcs.coordsys == 'pixel':
github ejeschke / ginga / ginga / gtkw / plugins / MultiDim.py View on Github external
def set_hdu(self, idx):
        self.logger.debug("Loading fits hdu #%d" % (idx))
        image = AstroImage.AstroImage(logger=self.logger)
        try:
            hdu = self.fits_f[idx-1]
            dims = list(hdu.data.shape)
            dims.reverse()
            image.load_hdu(hdu)
            image.set(path=self.path)

            self.fitsimage.set_image(image)
            self.build_naxis(dims)
            self.curhdu = idx-1
            self.logger.debug("hdu #%d loaded." % (idx))
        except Exception, e:
            errmsg = "Error loading fits hdu #%d: %s" % (
                idx, str(e))
            self.logger.error(errmsg)
            self.fv.error(errmsg)
github ejeschke / ginga / ginga / util / io / io_asdf.py View on Github external
Currently unused. Reserved for future use in logging

    Returns
    -------
    data : ndarray or `None`
        Image data, if found.

    wcs : obj or `None`
        GWCS object or models, if found.

    ahdr : dict
        Header containing metadata.

    """
    # TODO: support other types, like AstroTable, if ASDF can contain them
    data_obj = AstroImage.AstroImage(logger=logger)

    # TODO: idx may contain info about what part of the file to load
    #  e.g. should we pass as 'data_key' parameter?
    data, wcs, ahdr = load_from_asdf(asdf_obj)

    data_obj.setup_data(data, naxispath=None)

    wcsinfo = wcsmod.get_wcs_class('astropy_ape14')
    data_obj.wcs = wcsinfo.wrapper_class(logger=logger)
    data_obj.wcs.wcs = wcs

    if wcs is not None:
        data_obj.wcs.coordsys = wcs.output_frame.name

    return data_obj
github ejeschke / ginga / experimental / remote_image / plugin / RemoteImage.py View on Github external
def __init__(self, proxy, metadata=None, logger=None,
                 #wcsclass=wcsClass, ioclass=ioClass,
                 inherit_primary_header=False):

        self._proxy = proxy
        self._shape = tuple([])
        self.id = None

        AstroImage.__init__(self, data_np=None, metadata=metadata,
                            logger=logger, #wcsclass=wcsClass, ioclass=ioClass,
                            inherit_primary_header=inherit_primary_header)
        self._data = None
github ejeschke / ginga / ginga / util / io_fits.py View on Github external
def load_hdu(self, hdu, dstobj=None, **kwargs):
        typ = self.get_hdu_type(hdu)

        if typ == 'image':
            # <-- data is an image
            ahdr = AstroHeader()
            self.fromHDU(hdu, ahdr)

            metadata = dict(header=ahdr)

            data = hdu.read()

            if dstobj is None:
                dstobj = AstroImage(logger=self.logger)
                dstobj.load_data(data, metadata=metadata)

            else:
                dstobj.load_data(data, metadata=metadata)

        elif typ == 'table':
            # <-- data is a table
            raise FITSError(
                "FITS tables are not yet readable using ginga/fitsio")

        dstobj.io = self

        return dstobj
github ejeschke / ginga / ginga / qtw / ipg.py View on Github external
def load_file(self, filepath, name):
        image = AstroImage.AstroImage(logger=self.logger)
        image.load_file(filepath)

        fi = self.kapp.namespace[name]
        fi.set_image(image)