def test_replace_table(): from astropy.io import fits schema_narrow = { "allOf": [ mschema.load_schema(os.path.join(os.path.dirname(__file__), "../schemas/core.schema.yaml"), resolve_references=True), { "type": "object", "properties": { "data": { "title": "relative sensitivity table", "fits_hdu": "RELSENS", "datatype": [{ "name": "TYPE", "datatype": ["ascii", 16] }, { "name": "T_OFFSET", "datatype": "float32" }, { "name": "DECAY_PEAK", "datatype": "float32" }, { "name": "DECAY_FREQ", "datatype": "float32" }, { "name": "TAU", "datatype": "float32" }] } } } ] } schema_wide = { "allOf": [ mschema.load_schema(os.path.join(os.path.dirname(__file__), "../schemas/core.schema.yaml"), resolve_references=True), { "type": "object", "properties": { "data": { "title": "relative sensitivity table", "fits_hdu": "RELSENS", "datatype": [{ "name": "TYPE", "datatype": ["ascii", 16] }, { "name": "T_OFFSET", "datatype": "float64" }, { "name": "DECAY_PEAK", "datatype": "float64" }, { "name": "DECAY_FREQ", "datatype": "float64" }, { "name": "TAU", "datatype": "float64" }] } } } ] } x = np.array([("string", 1., 2., 3., 4.)], dtype=[('TYPE', 'S16'), ('T_OFFSET', np.float32), ('DECAY_PEAK', np.float32), ('DECAY_FREQ', np.float32), ('TAU', np.float32)]) m = DataModel(schema=schema_narrow) m.data = x m.to_fits(TMP_FITS, overwrite=True) with fits.open(TMP_FITS, memmap=False) as hdulist: assert records_equal(x, np.asarray(hdulist[1].data)) assert hdulist[1].data.dtype[1].str == '>f4' assert hdulist[1].header['TFORM2'] == 'E' with DataModel(TMP_FITS, schema=schema_wide) as m: m.to_fits(TMP_FITS2, overwrite=True) with fits.open(TMP_FITS2, memmap=False) as hdulist: assert records_equal(x, np.asarray(hdulist[1].data)) assert hdulist[1].data.dtype[1].str == '>f8' assert hdulist[1].header['TFORM2'] == 'D'
def test_replace_table(tmp_path): file_path = tmp_path / "test.fits" file_path2 = tmp_path / "test2.fits" schema_narrow = { "allOf": [ asdf.schema.load_schema("http://example.com/schemas/core_metadata", resolve_references=True), { "type": "object", "properties": { "data": { "title": "relative sensitivity table", "fits_hdu": "RELSENS", "datatype": [{ "name": "TYPE", "datatype": ["ascii", 16] }, { "name": "T_OFFSET", "datatype": "float32" }, { "name": "DECAY_PEAK", "datatype": "float32" }, { "name": "DECAY_FREQ", "datatype": "float32" }, { "name": "TAU", "datatype": "float32" }] } } } ] } schema_wide = { "allOf": [ asdf.schema.load_schema("http://example.com/schemas/core_metadata", resolve_references=True), { "type": "object", "properties": { "data": { "title": "relative sensitivity table", "fits_hdu": "RELSENS", "datatype": [{ "name": "TYPE", "datatype": ["ascii", 16] }, { "name": "T_OFFSET", "datatype": "float64" }, { "name": "DECAY_PEAK", "datatype": "float64" }, { "name": "DECAY_FREQ", "datatype": "float64" }, { "name": "TAU", "datatype": "float64" }] } } } ] } x = np.array([("string", 1., 2., 3., 4.)], dtype=[('TYPE', 'S16'), ('T_OFFSET', np.float32), ('DECAY_PEAK', np.float32), ('DECAY_FREQ', np.float32), ('TAU', np.float32)]) m = DataModel(schema=schema_narrow) m.data = x m.to_fits(file_path, overwrite=True) with fits.open(file_path, memmap=False) as hdulist: assert records_equal(x, np.asarray(hdulist[1].data)) assert hdulist[1].data.dtype[1].str == '>f4' assert hdulist[1].header['TFORM2'] == 'E' with DataModel(file_path, schema=schema_wide) as m: m.to_fits(file_path2, overwrite=True) with fits.open(file_path2, memmap=False) as hdulist: assert records_equal(x, np.asarray(hdulist[1].data)) assert hdulist[1].data.dtype[1].str == '>f8' assert hdulist[1].header['TFORM2'] == 'D'