def test_pixflat_mask(self): from lvmspec.maskbits import ccdmask pixflat = np.ones((2 * self.ny, 2 * self.nx)) pixflat[0:10, 0:10] = 0.0 pixflat[10:20, 10:20] = 0.05 image = preproc(self.rawimage, self.header, primary_header=self.primary_header, pixflat=pixflat) self.assertTrue(np.all(image.mask[0:10, 0:10] & ccdmask.PIXFLATZERO)) self.assertTrue(np.all(image.mask[10:20, 10:20] & ccdmask.PIXFLATLOW))
def test_pixflat(self): image = preproc(self.rawimage, self.header, primary_header=self.primary_header, pixflat=False) pixflat = np.ones_like(image.pix) image = preproc(self.rawimage, self.header, primary_header=self.primary_header, pixflat=pixflat) fits.writeto(self.calibfile, pixflat) image = preproc(self.rawimage, self.header, primary_header=self.primary_header, pixflat=self.calibfile) with self.assertRaises(ValueError): image = preproc(self.rawimage, self.header, primary_header=self.primary_header, pixflat=pixflat[0:10, 0:10])
def test_bias(self): image = preproc(self.rawimage, self.header, primary_header=self.primary_header, bias=False) bias = np.zeros(self.rawimage.shape) image = preproc(self.rawimage, self.header, primary_header=self.primary_header, bias=bias) fits.writeto(self.calibfile, bias) image = preproc(self.rawimage, self.header, primary_header=self.primary_header, bias=self.calibfile) with self.assertRaises(ValueError): image = preproc(self.rawimage, self.header, primary_header=self.primary_header, bias=bias[0:10, 0:10])
def test_mask(self): image = preproc(self.rawimage, self.header, primary_header=self.primary_header, mask=False) mask = np.random.randint(0, 2, size=image.pix.shape) image = preproc(self.rawimage, self.header, primary_header=self.primary_header, mask=mask) self.assertTrue(np.all(image.mask == mask)) fits.writeto(self.calibfile, mask) image = preproc(self.rawimage, self.header, primary_header=self.primary_header, mask=self.calibfile) self.assertTrue(np.all(image.mask == mask)) with self.assertRaises(ValueError): image = preproc(self.rawimage, self.header, primary_header=self.primary_header, mask=mask[0:10, 0:10])
def test_preproc(self): image = preproc(self.rawimage, self.header, primary_header=self.primary_header) self.assertEqual(image.pix.shape, (2 * self.ny, 2 * self.nx)) self.assertTrue(np.all(image.ivar <= 1 / image.readnoise**2)) for amp in ('1', '2', '3', '4'): pix = image.pix[self.quad[amp]] rdnoise = np.median(image.readnoise[self.quad[amp]]) npixover = self.ny * self.noverscan self.assertAlmostEqual(np.mean(pix), 0.0, delta=3 * rdnoise / np.sqrt(npixover)) self.assertAlmostEqual(np.std(pix), self.rdnoise[amp], delta=0.2) self.assertAlmostEqual(rdnoise, self.rdnoise[amp], delta=0.2)
def test_pedantic(self): with self.assertRaises(ValueError): _parse_sec_keyword('blat') #- should log a warning about large readnoise rawimage = self.rawimage + np.random.normal(scale=2, size=self.rawimage.shape) image = preproc(rawimage, self.header, primary_header=self.primary_header) #- should log an error about huge readnoise rawimage = self.rawimage + np.random.normal(scale=10, size=self.rawimage.shape) image = preproc(rawimage, self.header, primary_header=self.primary_header) #- should log a warning about small readnoise rdnoise = 0.7 * np.mean(list(self.rdnoise.values())) rawimage = np.random.normal(scale=rdnoise, size=self.rawimage.shape) image = preproc(rawimage, self.header, primary_header=self.primary_header) #- should log a warning about tiny readnoise rdnoise = 0.01 * np.mean(list(self.rdnoise.values())) rawimage = np.random.normal(scale=rdnoise, size=self.rawimage.shape) image = preproc(rawimage, self.header, primary_header=self.primary_header) #- Missing expected RDNOISE keywords shouldn't be fatal hdr = self.header.copy() del hdr['RDNOISE1'] del hdr['RDNOISE2'] del hdr['RDNOISE3'] del hdr['RDNOISE4'] image = preproc(self.rawimage, hdr, primary_header=self.primary_header) #- Missing expected GAIN keywords should log error but not crash hdr = self.header.copy() del hdr['GAIN1'] del hdr['GAIN2'] del hdr['GAIN3'] del hdr['GAIN4'] image = preproc(self.rawimage, hdr, primary_header=self.primary_header)
def test_default_mask(self): image = preproc(self.rawimage, self.header, primary_header=self.primary_header, mask=True)
def test_default_pixflat(self): image = preproc(self.rawimage, self.header, primary_header=self.primary_header, pixflat=True)
def test_default_bias(self): image = preproc(self.rawimage, self.header, primary_header=self.primary_header, bias=True)