def testwritetoConvienceFunction(self):
        """Test the writeto convience function in both the fits and stpyfits
           namespace."""

        hdul = stpyfits.open(self.data('cdva2.fits'))
        hdul1 = fits.open(self.data('cdva2.fits'))

        header = hdul[0].header.copy()
        header['NAXIS'] = 0

        stpyfits.writeto(self.temp('new.fits'), hdul[0].data, header,
                         clobber=True)
        fits.writeto(self.temp('new1.fits'), hdul1[0].data,hdul1[0].header,
                     clobber=True)

        hdul.close()
        hdul1.close()

        info1 = fits.info(self.temp('new.fits'), output=False)
        info2 = stpyfits.info(self.temp('new.fits'), output=False)
        info3 = fits.info(self.temp('new1.fits'), output=False)
        info4 = stpyfits.info(self.temp('new1.fits'), output=False)

        assert_equal(info1, [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', '')])
        assert_equal(info2,
            [(0, 'PRIMARY', 'PrimaryHDU', 6, (10, 10), 'int32', '')])
        assert_equal(info3, [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', '')])
        assert_equal(info4,
            [(0, 'PRIMARY', 'PrimaryHDU', 6, (10, 10), 'uint8', '')])
示例#2
0
    def testwritetoConvienceFunction(self):
        """Test the writeto convience function in both the fits and stpyfits
           namespace."""

        hdul = stpyfits.open(self.data('cdva2.fits'))
        hdul1 = fits.open(self.data('cdva2.fits'))

        header = hdul[0].header.copy()
        header['NAXIS'] = 0

        stpyfits.writeto(self.temp('new.fits'),
                         hdul[0].data,
                         header,
                         clobber=True)
        fits.writeto(self.temp('new1.fits'),
                     hdul1[0].data,
                     hdul1[0].header,
                     clobber=True)

        hdul.close()
        hdul1.close()

        info1 = fits.info(self.temp('new.fits'), output=False)
        info2 = stpyfits.info(self.temp('new.fits'), output=False)
        info3 = fits.info(self.temp('new1.fits'), output=False)
        info4 = stpyfits.info(self.temp('new1.fits'), output=False)

        assert_equal(info1, [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', '')])
        assert_equal(info2,
                     [(0, 'PRIMARY', 'PrimaryHDU', 6, (10, 10), 'int32', '')])
        assert_equal(info3, [(0, 'PRIMARY', 'PrimaryHDU', 6, (), '', '')])
        assert_equal(info4,
                     [(0, 'PRIMARY', 'PrimaryHDU', 6, (10, 10), 'uint8', '')])
示例#3
0
    def testPrimaryHDUConstructor(self):
        """Test the PrimaryHDU constructor in both the fits and stpyfits
           namespace.  Although stpyfits does not reimplement the
           constructor, it does add _ConstantValueImageBaseHDU to the
           inheritance hierarchy of fits.PrimaryHDU when accessed through the
           stpyfits namespace.  This method tests that that inheritance is
           working"""

        n = np.zeros(10)
        n = n + 1

        hdu = stpyfits.PrimaryHDU(n)
        hdu.header.set('PIXVALUE', 1.0, 'Constant pixel value', after='EXTEND')
        hdu.header.set('NAXIS', 0)
        stpyfits.writeto(self.temp('new.fits'),
                         hdu.data,
                         hdu.header,
                         clobber=True)
        hdul = stpyfits.open(self.temp('new.fits'))
        hdul1 = fits.open(self.temp('new.fits'))

        assert_equal(hdul[0].header['NAXIS'], 1)
        assert_equal(hdul[0].header['NAXIS1'], 10)
        assert_equal(hdul[0].header['PIXVALUE'], 1.0)

        assert_raises(KeyError, lambda: hdul[0].header['NPIX1'])

        assert_true((hdul[0].data == np.ones(10, dtype=np.float32)).all())

        assert_equal(hdul1[0].header['NAXIS'], 0)
        assert_equal(hdul1[0].header['NPIX1'], 10)
        assert_equal(hdul1[0].header['PIXVALUE'], 1.0)

        assert_raises(KeyError, lambda: hdul1[0].header['NAXIS1'])

        assert_equal(hdul1[0].data, None)

        hdul.close()
        hdul1.close()
    def testPrimaryHDUConstructor(self):
        """Test the PrimaryHDU constructor in both the fits and stpyfits
           namespace.  Although stpyfits does not reimplement the
           constructor, it does add _ConstantValueImageBaseHDU to the
           inheritance hierarchy of fits.PrimaryHDU when accessed through the
           stpyfits namespace.  This method tests that that inheritance is
           working"""

        n = np.zeros(10)
        n = n + 1

        hdu = stpyfits.PrimaryHDU(n)
        hdu.header.set('PIXVALUE', 1.0, 'Constant pixel value', after='EXTEND')
        hdu.header.set('NAXIS', 0)
        stpyfits.writeto(self.temp('new.fits'), hdu.data, hdu.header,
                         clobber=True)
        hdul = stpyfits.open(self.temp('new.fits'))
        hdul1 = fits.open(self.temp('new.fits'))

        assert_equal(hdul[0].header['NAXIS'], 1)
        assert_equal(hdul[0].header['NAXIS1'], 10)
        assert_equal(hdul[0].header['PIXVALUE'], 1.0)

        assert_raises(KeyError, lambda: hdul[0].header['NPIX1'])

        assert_true((hdul[0].data == np.ones(10, dtype=np.float32)).all())

        assert_equal(hdul1[0].header['NAXIS'], 0)
        assert_equal(hdul1[0].header['NPIX1'], 10)
        assert_equal(hdul1[0].header['PIXVALUE'], 1.0)

        assert_raises(KeyError, lambda: hdul1[0].header['NAXIS1'])

        assert_equal(hdul1[0].data, None)

        hdul.close()
        hdul1.close()
    def testupdateConvienceFunction(self):
        """Test the update convience function in both the fits and stpyfits
           namespace."""

        hdul = stpyfits.open(self.data('cdva2.fits'))
        hdul1 = fits.open(self.data('cdva2.fits'))

        header = hdul[0].header.copy()
        header['NAXIS'] = 0
        stpyfits.writeto(self.temp('new.fits'), hdul[0].data, header,
                         clobber=True)

        hdu = stpyfits.ImageHDU()
        hdu1 = fits.ImageHDU()

        hdu.data = hdul[0].data
        hdu1.data = hdul1[0].data
        hdu.header.set('BITPIX', 32)
        hdu1.header.set('BITPIX', 32)
        hdu.header.set('NAXIS', 0)
        hdu.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT')
        hdu1.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT')
        hdu.header.set('NPIX1', 10, 'length of constant array axis 1',
                       after='GCOUNT')
        hdu.header.set('NPIX2', 10, 'length of constant array axis 2',
                       after='NPIX1')
        stpyfits.append(self.temp('new.fits'), hdu.data, hdu.header)

        d = hdu.data * 0

        stpyfits.update(self.temp('new.fits'), d, hdu.header, 1)

        assert_equal(fits.info(self.temp('new.fits'), output=False),
            [(0, 'PRIMARY', 'PrimaryHDU', 7, (), '', ''),
             (1, '', 'ImageHDU', 8, (), '', '')])
        assert_equal(stpyfits.info(self.temp('new.fits'), output=False),
            [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', ''),
             (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')])

        hdul7 = stpyfits.open(self.temp('new.fits'))
        assert_equal(hdul7[1].header['NAXIS'], 2)
        assert_equal(hdul7[1].header['NAXIS1'], 10)
        assert_equal(hdul7[1].header['NAXIS2'], 10)
        assert_equal(hdul7[1].header['PIXVALUE'], 0)

        assert_raises(KeyError, lambda: hdul7[1].header['NPIX1'])
        assert_raises(KeyError, lambda: hdul7[1].header['NPIX2'])

        assert_true((hdul7[1].data ==
                     np.zeros((10, 10), dtype=np.int32)).all())

        hdul8 = fits.open(self.temp('new.fits'))
        assert_equal(hdul8[1].header['NAXIS'], 0)
        assert_equal(hdul8[1].header['NPIX1'], 10)
        assert_equal(hdul8[1].header['NPIX2'], 10)
        assert_equal(hdul8[1].header['PIXVALUE'], 0)

        assert_raises(KeyError, lambda: hdul8[1].header['NAXIS1'])
        assert_raises(KeyError, lambda: hdul8[1].header['NAXIS2'])

        assert_equal(hdul8[1].data, None)

        hdul7.close()
        hdul8.close()
        hdul.close()
        hdul1.close()
示例#6
0
    def testupdateConvienceFunction(self):
        """Test the update convience function in both the fits and stpyfits
           namespace."""

        hdul = stpyfits.open(self.data('cdva2.fits'))
        hdul1 = fits.open(self.data('cdva2.fits'))

        header = hdul[0].header.copy()
        header['NAXIS'] = 0
        stpyfits.writeto(self.temp('new.fits'),
                         hdul[0].data,
                         header,
                         clobber=True)

        hdu = stpyfits.ImageHDU()
        hdu1 = fits.ImageHDU()

        hdu.data = hdul[0].data
        hdu1.data = hdul1[0].data
        hdu.header.set('BITPIX', 32)
        hdu1.header.set('BITPIX', 32)
        hdu.header.set('NAXIS', 0)
        hdu.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT')
        hdu1.header.set('PIXVALUE', 1, 'Constant pixel value', after='GCOUNT')
        hdu.header.set('NPIX1',
                       10,
                       'length of constant array axis 1',
                       after='GCOUNT')
        hdu.header.set('NPIX2',
                       10,
                       'length of constant array axis 2',
                       after='NPIX1')
        stpyfits.append(self.temp('new.fits'), hdu.data, hdu.header)

        d = hdu.data * 0

        stpyfits.update(self.temp('new.fits'), d, hdu.header, 1)

        assert_equal(fits.info(self.temp('new.fits'), output=False),
                     [(0, 'PRIMARY', 'PrimaryHDU', 7, (), '', ''),
                      (1, '', 'ImageHDU', 8, (), '', '')])
        assert_equal(stpyfits.info(self.temp('new.fits'), output=False),
                     [(0, 'PRIMARY', 'PrimaryHDU', 7, (10, 10), 'int32', ''),
                      (1, '', 'ImageHDU', 8, (10, 10), 'int32', '')])

        hdul7 = stpyfits.open(self.temp('new.fits'))
        assert_equal(hdul7[1].header['NAXIS'], 2)
        assert_equal(hdul7[1].header['NAXIS1'], 10)
        assert_equal(hdul7[1].header['NAXIS2'], 10)
        assert_equal(hdul7[1].header['PIXVALUE'], 0)

        assert_raises(KeyError, lambda: hdul7[1].header['NPIX1'])
        assert_raises(KeyError, lambda: hdul7[1].header['NPIX2'])

        assert_true((hdul7[1].data == np.zeros((10, 10),
                                               dtype=np.int32)).all())

        hdul8 = fits.open(self.temp('new.fits'))
        assert_equal(hdul8[1].header['NAXIS'], 0)
        assert_equal(hdul8[1].header['NPIX1'], 10)
        assert_equal(hdul8[1].header['NPIX2'], 10)
        assert_equal(hdul8[1].header['PIXVALUE'], 0)

        assert_raises(KeyError, lambda: hdul8[1].header['NAXIS1'])
        assert_raises(KeyError, lambda: hdul8[1].header['NAXIS2'])

        assert_equal(hdul8[1].data, None)

        hdul7.close()
        hdul8.close()
        hdul.close()
        hdul1.close()