Esempio n. 1
0
    def from_header(cls, header, hdu_bands=None, format=None):
        """Create a WCS geometry object from a FITS header.

        Parameters
        ----------
        header : `~astropy.io.fits.Header`
            The FITS header
        hdu_bands : `~astropy.io.fits.BinTableHDU`
            The BANDS table HDU.
        format : {'gadf', 'fgst-ccube','fgst-template'}
            FITS format convention.

        Returns
        -------
        wcs : `~WcsGeom`
            WCS geometry object.
        """
        wcs = WCS(header, naxis=2)
        # TODO: see https://github.com/astropy/astropy/issues/9259
        wcs._naxis = wcs._naxis[:2]

        axes = MapAxes.from_table_hdu(hdu_bands, format=format)
        shape = axes.shape

        if hdu_bands is not None and "NPIX" in hdu_bands.columns.names:
            npix = hdu_bands.data.field("NPIX").reshape(shape + (2, ))
            npix = (npix[..., 0], npix[..., 1])
            cdelt = hdu_bands.data.field("CDELT").reshape(shape + (2, ))
            cdelt = (cdelt[..., 0], cdelt[..., 1])
        elif "WCSSHAPE" in header:
            wcs_shape = eval(header["WCSSHAPE"])
            npix = (wcs_shape[0], wcs_shape[1])
            cdelt = None
            wcs.array_shape = npix
        else:
            npix = (header["NAXIS1"], header["NAXIS2"])
            cdelt = None

        if "PSLICE1" in header:
            cutout_info = {}
            cutout_info["parent-slices"] = (
                str_to_slice(header["PSLICE2"]),
                str_to_slice(header["PSLICE1"]),
            )
            cutout_info["cutout-slices"] = (
                str_to_slice(header["CSLICE2"]),
                str_to_slice(header["CSLICE1"]),
            )
        else:
            cutout_info = None

        return cls(wcs, npix, cdelt=cdelt, axes=axes, cutout_info=cutout_info)
Esempio n. 2
0
    def from_header(cls, header, hdu_bands=None):
        """Create a WCS geometry object from a FITS header.

        Parameters
        ----------
        header : `~astropy.io.fits.Header`
            The FITS header
        hdu_bands : `~astropy.io.fits.BinTableHDU`
            The BANDS table HDU.

        Returns
        -------
        wcs : `~WcsGeom`
            WCS geometry object.
        """
        wcs = WCS(header, naxis=2)
        # TODO: see https://github.com/astropy/astropy/issues/9259
        wcs._naxis = wcs._naxis[:2]

        axes = find_and_read_bands(hdu_bands)
        shape = tuple([ax.nbin for ax in axes])

        if hdu_bands is not None and "NPIX" in hdu_bands.columns.names:
            npix = hdu_bands.data.field("NPIX").reshape(shape + (2, ))
            npix = (npix[..., 0], npix[..., 1])
            cdelt = hdu_bands.data.field("CDELT").reshape(shape + (2, ))
            cdelt = (cdelt[..., 0], cdelt[..., 1])
        elif "WCSSHAPE" in header:
            wcs_shape = eval(header["WCSSHAPE"])
            npix = (wcs_shape[0], wcs_shape[1])
            cdelt = None
        else:
            npix = (header["NAXIS1"], header["NAXIS2"])
            cdelt = None

        if "PSLICE1" in header:
            cutout_info = {}
            cutout_info["parent-slices"] = (
                str_to_slice(header["PSLICE2"]),
                str_to_slice(header["PSLICE1"]),
            )
            cutout_info["cutout-slices"] = (
                str_to_slice(header["CSLICE2"]),
                str_to_slice(header["CSLICE1"]),
            )
        else:
            cutout_info = None

        return cls(wcs, npix, cdelt=cdelt, axes=axes, cutout_info=cutout_info)