def setUp(self): self.stack = Stacky() self.fits = pyfits.HDUList(pyfits.PrimaryHDU(np.arange(4096).reshape(64,64))) self.onesfits = pyfits.HDUList(pyfits.PrimaryHDU(np.ones(4096).reshape(64,64))) self.nanfits = pyfits.HDUList(pyfits.PrimaryHDU(np.ones(4096).reshape(64,64))) self.nanfits[0].data[0:63][0:63] = np.nan for fits in [self.fits, self.onesfits, self.nanfits]: fits[0].header.update('BUNIT', 'TestUnits', '') fits[0].header.update('CRPIX1', 1, '') fits[0].header.update('CRPIX2', 1, '') fits[0].header.update('CDELT1', -20.0/3600.0, '') fits[0].header.update('CDELT2', 20.0/3600.0, '') fits[0].header.update('CRVAL1', -(32*self.fits[0].header['CDELT1']), '') fits[0].header.update('CRVAL2', -(32*self.fits[0].header['CDELT2']), '') fits[0].header.update('CTYPE1', 'RA-CAR', '') fits[0].header.update('CTYPE2', 'DEC-CAR', '')
class TestStampyStacky(unittest.TestCase): def setUp(self): self.stack = Stacky() self.fits = pyfits.HDUList(pyfits.PrimaryHDU(np.arange(4096).reshape(64,64))) self.onesfits = pyfits.HDUList(pyfits.PrimaryHDU(np.ones(4096).reshape(64,64))) self.nanfits = pyfits.HDUList(pyfits.PrimaryHDU(np.ones(4096).reshape(64,64))) self.nanfits[0].data[0:63][0:63] = np.nan for fits in [self.fits, self.onesfits, self.nanfits]: fits[0].header.update('BUNIT', 'TestUnits', '') fits[0].header.update('CRPIX1', 1, '') fits[0].header.update('CRPIX2', 1, '') fits[0].header.update('CDELT1', -20.0/3600.0, '') fits[0].header.update('CDELT2', 20.0/3600.0, '') fits[0].header.update('CRVAL1', -(32*self.fits[0].header['CDELT1']), '') fits[0].header.update('CRVAL2', -(32*self.fits[0].header['CDELT2']), '') fits[0].header.update('CTYPE1', 'RA-CAR', '') fits[0].header.update('CTYPE2', 'DEC-CAR', '') def testHeaderValues(self): location = (0,0) stamp = Stampy(12, self.onesfits, location, name="testname") self.assertEqual(stamp.header["units"], "TestUnits") self.assertEqual(stamp.header["source"], "testname") self.assertEqual(stamp.header["radec"], location) self.assertEqual(stamp.header["bmean"], 1) self.assertEqual(stamp.header["bmedian"], 1) def testFlag(self): location = (0, 0) badlocation = (64,64) stamp = Stampy(12, self.onesfits, location, maxnoise=2) self.assert_(not stamp.header["flag"]["highnoise"]) self.assert_(not stamp.header["flag"]["hasnans"]) self.assert_(not stamp.header["flag"]["dimensionerror"]) self.assert_(not stamp.header["flag"]["nearsource"]) self.assertEqual(stamp.header["flag"]["errorflag"], 'a') stamp = Stampy(12, self.fits, location, maxnoise=0) self.assert_(stamp.header["flag"]["highnoise"]) self.assert_(not stamp.header["flag"]["hasnans"]) self.assert_(not stamp.header["flag"]["dimensionerror"]) self.assert_(not stamp.header["flag"]["nearsource"]) self.assertEqual(stamp.header["flag"]["errorflag"], 'n') stamp = Stampy(66, self.fits, location) self.assert_(not stamp.header["flag"]["highnoise"]) self.assert_(not stamp.header["flag"]["hasnans"]) self.assert_(stamp.header["flag"]["dimensionerror"]) self.assert_(not stamp.header["flag"]["nearsource"]) self.assertEqual(stamp.header["flag"]["errorflag"], 'd') stamp = Stampy(12, self.fits, badlocation) self.assert_(not stamp.header["flag"]["highnoise"]) self.assert_(not stamp.header["flag"]["hasnans"]) self.assert_(stamp.header["flag"]["dimensionerror"]) self.assert_(not stamp.header["flag"]["nearsource"]) self.assertEqual(stamp.header["flag"]["errorflag"], 'd') stamp = Stampy(12, self.nanfits, location) self.assert_(not stamp.header["flag"]["highnoise"]) self.assert_(stamp.header["flag"]["hasnans"]) self.assert_(not stamp.header["flag"]["dimensionerror"]) self.assert_(not stamp.header["flag"]["nearsource"]) self.assertEqual(stamp.header["flag"]["errorflag"], 'b') def testStackReject(self): location = (0,0) nanstamp = Stampy(12, self.nanfits, location) goodstamp = Stampy(12, self.onesfits, location, maxnoise=2) noisestamp = Stampy(12, self.onesfits, location, maxnoise=0) dimenstamp = Stampy(66, self.onesfits, location, maxnoise=0) self.assertEqual(self.stack.add_stamp(goodstamp), 'a') self.assertEqual(self.stack.add_stamp(noisestamp), 'n') self.assertEqual(self.stack.add_stamp(dimenstamp), 'd') self.assertEqual(self.stack.add_stamp(nanstamp), 'b')