Beispiel #1
0
def setup_module():
    """Create objects once and re-use throughout this module."""
    global img_dict

    if minversion(astropy, '3.1'):
        USE_APE14 = True
    else:
        USE_APE14 = False

    img_dict = {}
    for modname in _wcsmods:
        if modname == 'astropy_ape14' and not USE_APE14:
            continue
        if not wcsmod.use(modname, raise_err=False):
            continue
        img_dict[modname] = {}
        for dim in _hdr.keys():
            w = wcsmod.WCS(_logger)
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                w.load_header(_hdr[dim])
            img = AstroImage.AstroImage(logger=_logger)
            img.wcs = w
            if dim == '2d':
                img.revnaxis = []
                img.naxispath = []
            else:  # 3d
                img.revnaxis = [0]
                img.naxispath = [0]
            img_dict[modname][dim] = img
Beispiel #2
0
    def test_radectopix_scalar(self, modname):
        if not wcsmod.use(modname, raise_err=False):
            pytest.skip("WCS '{}' not available".format(modname))
        wcs = wcsmod.WCS(self.logger)
        #if wcs.wcs is None:
        #    pytest.skip("WCS '{}' not available".format(modname))
        wcs.load_header(self.header)
        img = AstroImage.AstroImage(logger=self.logger)
        img.wcs = wcs
        img.naxispath = []

        x_v1 = 120
        y_v1 = 100

        x, y = img.radectopix(300.2308791294835, 22.691653517073615)
        np.testing.assert_allclose(x, x_v1)
        np.testing.assert_allclose(y, y_v1)
Beispiel #3
0
    def test_pixtoradec_scalar(self, modname):
        if not wcsmod.use(modname, raise_err=False):
            pytest.skip("WCS '{}' not available".format(modname))
        wcs = wcsmod.WCS(self.logger)
        #if wcs.wcs is None:
        #    pytest.skip("WCS '{}' not available".format(modname))
        wcs.load_header(self.header)
        img = AstroImage.AstroImage(logger=self.logger)
        img.wcs = wcs
        img.revnaxis = []

        ra_deg_v1 = 300.2308791294835
        dec_deg_v1 = 22.691653517073615

        ra_deg, dec_deg = img.pixtoradec(120, 100)
        np.testing.assert_allclose(ra_deg, ra_deg_v1),
        np.testing.assert_allclose(dec_deg, dec_deg_v1)
Beispiel #4
0
    def radectopix_scalar_runtest(self, modname):
        if not wcsmod.use(modname, raise_err=False):
            return False
        wcs = wcsmod.WCS(self.logger)
        wcs.load_header(self.header)
        img = AstroImage.AstroImage(logger=self.logger)
        img.wcs = wcs
        img.naxispath = []

        x_v1 = 120
        y_v1 = 100

        x, y = img.radectopix(300.2308791294835, 22.691653517073615)
        assert numpy.isclose(x, x_v1), \
               ValueError("x does not match (%f != %f)" % (x, x_v1))
        assert numpy.isclose(y, y_v1), \
               ValueError("y does not match (%f != %f)" % (y, y_v1))
        return True
Beispiel #5
0
    def pixtoradec_scalar_runtest(self, modname):
        if not wcsmod.use(modname, raise_err=False):
            return False
        wcs = wcsmod.WCS(self.logger)
        wcs.load_header(self.header)
        img = AstroImage.AstroImage(logger=self.logger)
        img.wcs = wcs
        img.revnaxis = []

        ra_deg_v1 = 300.2308791294835
        dec_deg_v1 = 22.691653517073615

        ra_deg, dec_deg = img.pixtoradec(120, 100)
        assert numpy.isclose(ra_deg, ra_deg_v1), \
               ValueError("RA deg does not match (%f != %f)" % (ra_deg,
                                                                ra_deg_v1))
        assert numpy.isclose(dec_deg, dec_deg_v1), \
               ValueError("DEC deg does not match (%f != %f)" % (dec_deg,
                                                                 dec_deg_v1))
        return True
Beispiel #6
0
    def load_nddata(self, ndd, naxispath=None):
        """Load from an astropy.nddata.NDData object.
        """
        self.clear_metadata()

        # Make a header based on any NDData metadata
        ahdr = self.get_header()
        ahdr.update(ndd.meta)

        self.setup_data(ndd.data, naxispath=naxispath)

        if ndd.wcs is None:
            # no wcs in ndd obj--let's try to make one from the header
            self.wcs = wcsmod.WCS(logger=self.logger)
            self.wcs.load_header(ahdr)
        else:
            # already have a valid wcs in the ndd object
            # we assume it needs an astropy compatible wcs
            wcsinfo = wcsmod.get_wcs_class('astropy')
            self.wcs = wcsinfo.wrapper_class(logger=self.logger)
            self.wcs.load_nddata(ndd)