def test_unit_incompatible(self): hdul = self.create_hdu(uncert=True, mask=True) hdul[0].header['BUNIT'] = 'm' with pytest.raises(ValueError): _extract_fits(hdul, hdu_uncertainty='UNCERT', unit_key='BUNIT', unit='adu')
def test_simple_hdulist(self): hdu = self.create_hdu() header = self.create_header('adu', 'BUNIT') f = _extract_fits(hdu) assert_equal(f['data'], 100 * np.ones(self.shape)) for i in header: assert_equal(f['meta'][i], header[i]) assert_equal(f['unit'], 'adu')
def test_hdulist_with_mask(self): hdu = self.create_hdu(mask=True) header = self.create_header('adu', 'BUNIT') f = _extract_fits(hdu, hdu_mask='MASK') assert_equal(f['data'], 100 * np.ones(self.shape)) for i in header: assert_equal(f['meta'][i], header[i]) assert_equal(f['unit'], 'adu') assert_equal(f['mask'], self.mask.astype('uint8'))
def test_hdulist_with_uncertainty(self): hdu = self.create_hdu(uncert=True) header = self.create_header('adu', 'BUNIT') f = _extract_fits(hdu, hdu_uncertainty='UNCERT') assert_equal(f['data'], 100 * np.ones(self.shape)) for i in header: assert_equal(f['meta'][i], header[i]) assert_equal(f['unit'], 'adu') assert_equal(f['uncertainty'], np.ones(self.shape))
def test_file(self, tmpdir): hdu = self.create_hdu(uncert=True, mask=True) header = self.create_header('adu', 'BUNIT') fname = tmpdir.join('test_file.fits').strpath hdu.writeto(fname) f = _extract_fits(fname) assert_equal(f['data'], 100 * np.ones(self.shape)) for i in header: assert_equal(f['meta'][i], header[i]) assert_equal(f['unit'], 'adu') assert_equal(f['uncertainty'], np.ones(self.shape)) assert_equal(f['mask'], self.mask.astype('uint8'))
def test_invalid_type(self): with pytest.raises(TypeError): _extract_fits(None) with pytest.raises(TypeError): _extract_fits(np.array([1, 2, 3])) with pytest.raises(TypeError): _extract_fits(CCDData([1, 2, 3], unit='adu'))
def test_data_in_other_hdu(self, tmpdir): tbl = Table(np.ones(10).reshape(5, 2)) data = 100 * np.ones(self.shape) hdul = fits.HDUList(hdus=[ fits.PrimaryHDU(), fits.TableHDU(tbl.as_array()), fits.ImageHDU(data) ]) fname = tmpdir.join('test_table.fits').strpath hdul.writeto(fname) logs = [] lh = log_to_list(logger, logs, full_record=True) f = _extract_fits(fname) assert_equal(f['data'], 100 * np.ones(self.shape)) assert_equal(f['unit'], None) # ensure log emitting logs = [i for i in logs if i.message == 'First hdu with image data: 2'] assert_equal(len(logs), 1) assert_equal(logs[0].levelname, 'INFO') logger.removeHandler(lh)
def test_no_data_in_hdu(self): hdul = fits.HDUList([fits.PrimaryHDU(), fits.ImageHDU()]) with pytest.raises(ValueError): _extract_fits(hdul, hdu=1)
def test_invalid_unit(self): hdu = self.create_hdu(unit='invalid') with pytest.raises(ValueError): _extract_fits(hdu)