def test_preproc_script(self): io.write_raw(self.rawfile, self.rawimage, self.header, primary_header = self.primary_header, camera='b0') io.write_raw(self.rawfile, self.rawimage, self.header, primary_header = self.primary_header, camera='b1') args = ['--infile', self.rawfile, '--cameras', 'b0', '--outfile', self.pixfile] if os.path.exists(self.pixfile): os.remove(self.pixfile) desispec.scripts.preproc.main(args) img = io.read_image(self.pixfile) self.assertEqual(img.pix.shape, (2*self.ny, 2*self.nx))
def test_preproc_script(self): io.write_raw(self.rawfile, self.rawimage, self.header, camera='b0') io.write_raw(self.rawfile, self.rawimage, self.header, camera='b1') args = ['--infile', self.rawfile, '--cameras', 'b1', '--pixfile', self.pixfile] if os.path.exists(self.pixfile): os.remove(self.pixfile) desispec.scripts.preproc.main(args) img = io.read_image(self.pixfile) self.assertEqual(img.pix.shape, (2*self.ny, 2*self.nx))
def test_32_64(self): ''' 64-bit integers aren't supported for compressed HDUs; make sure we handle that gracefully ''' data64 = np.linspace(0, 2**60, 10, dtype=np.int64) datasmall64 = np.linspace(0, 2**30, 10, dtype=np.int64) data32 = np.linspace(0, 2**30, 10, dtype=np.int32) data16 = np.linspace(0, 2**10, 10, dtype=np.int16) #- Primary HDU should be blank #- Should be written as vanilla ImageHDU io.write_raw(self.rawfile, data64, self.header, camera='b0') #- Should be written as vanilla ImageHDU io.write_raw(self.rawfile, data64, self.header, camera='b1') #- Should be converted to 32-bit CompImageHDU io.write_raw(self.rawfile, datasmall64, self.header, camera='b2') #- Should be 32-bit CompImageHDU io.write_raw(self.rawfile, data32, self.header, camera='b3') #- Should be 16-bit CompImageHDU io.write_raw(self.rawfile, data16, self.header, camera='b4') fx = fits.open(self.rawfile) #- Blank PrimaryHDU should have been inserted self.assertTrue(isinstance(fx[0], fits.PrimaryHDU)) self.assertTrue(fx[0].data == None) #- 64-bit image written uncompressed after blank HDU self.assertTrue(isinstance(fx[1], fits.ImageHDU)) self.assertEqual(fx[1].data.dtype, np.dtype('>i8')) self.assertEqual(fx[1].header['EXTNAME'], 'B0') #- 64-bit image written uncompressed self.assertTrue(isinstance(fx[2], fits.ImageHDU)) self.assertEqual(fx[2].data.dtype, np.dtype('>i8')) self.assertEqual(fx[2].header['EXTNAME'], 'B1') #- 64-bit image with small numbers converted to 32-bit compressed self.assertTrue(isinstance(fx[3], fits.CompImageHDU)) self.assertEqual(fx[3].data.dtype, np.int32) self.assertEqual(fx[3].header['EXTNAME'], 'B2') #- 32-bit image written compressed self.assertTrue(isinstance(fx[4], fits.CompImageHDU)) self.assertEqual(fx[4].data.dtype, np.int32) self.assertEqual(fx[4].header['EXTNAME'], 'B3') #- 16-bit image written compressed self.assertTrue(isinstance(fx[5], fits.CompImageHDU)) self.assertEqual(fx[5].data.dtype, np.int16) self.assertEqual(fx[5].header['EXTNAME'], 'B4')
def test_32_64(self): ''' 64-bit integers aren't supported for compressed HDUs; make sure we handle that gracefully ''' data64 = np.linspace(0, 2**60, 10, dtype=np.int64) datasmall64 = np.linspace(0, 2**30, 10, dtype=np.int64) data32 = np.linspace(0, 2**30, 10, dtype=np.int32) data16 = np.linspace(0, 2**10, 10, dtype=np.int16) #- Primary HDU should be blank #- Should be written as vanilla ImageHDU io.write_raw(self.rawfile, data64, self.header, camera='b0') #- Should be written as vanilla ImageHDU io.write_raw(self.rawfile, data64, self.header, camera='b1') #- Should be converted to 32-bit CompImageHDU io.write_raw(self.rawfile, datasmall64, self.header, camera='b2') #- Should be 32-bit CompImageHDU io.write_raw(self.rawfile, data32, self.header, camera='b3') #- Should be 16-bit CompImageHDU io.write_raw(self.rawfile, data16, self.header, camera='b4') fx = fits.open(self.rawfile) #- Blank PrimaryHDU should have been inserted self.assertTrue(isinstance(fx[0], fits.PrimaryHDU)) self.assertTrue(fx[0].data == None) #- 64-bit image written uncompressed after blank HDU self.assertTrue(isinstance(fx[1], fits.ImageHDU)) self.assertEqual(fx[1].data.dtype, np.dtype('>i8')) self.assertEqual(fx[1].header['EXTNAME'], 'B0') #- 64-bit image written uncompressed self.assertTrue(isinstance(fx[2], fits.ImageHDU)) self.assertEqual(fx[2].data.dtype, np.dtype('>i8')) self.assertEqual(fx[2].header['EXTNAME'], 'B1') #- 64-bit image with small numbers converted to 32-bit compressed self.assertTrue(isinstance(fx[3], fits.CompImageHDU)) self.assertEqual(fx[3].data.dtype, np.int32) self.assertEqual(fx[3].header['EXTNAME'], 'B2') #- 32-bit image written compressed self.assertTrue(isinstance(fx[4], fits.CompImageHDU)) self.assertEqual(fx[4].data.dtype, np.int32) self.assertEqual(fx[4].header['EXTNAME'], 'B3') #- 16-bit image written compressed self.assertTrue(isinstance(fx[5], fits.CompImageHDU)) self.assertEqual(fx[5].data.dtype, np.int16) self.assertEqual(fx[5].header['EXTNAME'], 'B4')
def test_io(self): io.write_raw(self.rawfile, self.rawimage, self.header, primary_header=self.primary_header, camera='b0') io.write_raw(self.rawfile, self.rawimage, self.header, primary_header=self.primary_header, camera='R1') io.write_raw(self.rawfile, self.rawimage, self.header, primary_header=self.primary_header, camera='z9') self.header['CAMERA'] = 'B3' io.write_raw(self.rawfile, self.rawimage, self.header, primary_header=self.primary_header) b0 = io.read_raw(self.rawfile, 'b0') #b1 = io.read_raw(self.rawfile, 'b1') #r1 = io.read_raw(self.rawfile, 'r1') #z9 = io.read_raw(self.rawfile, 'Z9') self.assertEqual(b0.meta['CAMERA'], 'b0')
def test_keywords(self): for keyword in self.header.keys(): #- Missing GAIN* and RDNOISE* are warnings but not errors if keyword.startswith('GAIN') or keyword.startswith('RDNOISE'): continue #- DATE-OBS, NIGHT, and EXPID are also optional #- (but maybe they should be required...) if keyword in ('DATE-OBS', 'NIGHT', 'EXPID'): continue if os.path.exists(self.rawfile): os.remove(self.rawfile) value = self.header[keyword] del self.header[keyword] with self.assertRaises(KeyError): io.write_raw(self.rawfile, self.rawimage, self.header) self.header[keyword] = value dateobs = self.header
def test_keywords(self): for keyword in self.header.keys(): #- Missing GAIN* and RDNOISE* are warnings but not errors if keyword.startswith('GAIN') or keyword.startswith('RDNOISE'): continue #- DATE-OBS, NIGHT, and EXPID are also optional #- (but maybe they should be required...) if keyword in ('DATE-OBS', 'NIGHT', 'EXPID'): continue if os.path.exists(self.rawfile): os.remove(self.rawfile) value = self.header[keyword] del self.header[keyword] with self.assertRaises(KeyError): io.write_raw(self.rawfile, self.rawimage, self.header) self.header[keyword] = value dateobs = self.header
def test_io(self): io.write_raw(self.rawfile, self.rawimage, self.header, camera='b0') io.write_raw(self.rawfile, self.rawimage, self.header, camera='R1') io.write_raw(self.rawfile, self.rawimage, self.header, camera='z9') self.header['CAMERA'] = 'B1' io.write_raw(self.rawfile, self.rawimage, self.header) b0 = io.read_raw(self.rawfile, 'b0') b1 = io.read_raw(self.rawfile, 'b1') r1 = io.read_raw(self.rawfile, 'r1') z9 = io.read_raw(self.rawfile, 'Z9') self.assertEqual(b0.meta['CAMERA'], 'b0') self.assertEqual(b1.meta['CAMERA'], 'b1') self.assertEqual(r1.meta['CAMERA'], 'r1') self.assertEqual(z9.meta['CAMERA'], 'z9')
def test_io(self): io.write_raw(self.rawfile, self.rawimage, self.header, camera='b0') io.write_raw(self.rawfile, self.rawimage, self.header, camera='R1') io.write_raw(self.rawfile, self.rawimage, self.header, camera='z9') self.header['CAMERA'] = 'B1' io.write_raw(self.rawfile, self.rawimage, self.header) b0 = io.read_raw(self.rawfile, 'b0') b1 = io.read_raw(self.rawfile, 'b1') r1 = io.read_raw(self.rawfile, 'r1') z9 = io.read_raw(self.rawfile, 'Z9') self.assertEqual(b0.meta['CAMERA'], 'b0') self.assertEqual(b1.meta['CAMERA'], 'b1') self.assertEqual(r1.meta['CAMERA'], 'r1') self.assertEqual(z9.meta['CAMERA'], 'z9')