diff --git a/pyproject.toml b/pyproject.toml index e5051f3d..480f68c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ dependencies = [ "numpy >=1.22", "astropy >=5.3.0", # "rad >= 0.21.0", - "rad @ git+https://github.com/spacetelescope/rad.git", + "rad @ git+https://github.com/WilliamJamieson/rad.git@feature/remove_ref_units", "asdf-standard >=1.1.0", ] dynamic = ["version"] diff --git a/src/roman_datamodels/maker_utils/_common_meta.py b/src/roman_datamodels/maker_utils/_common_meta.py index b756860a..ca074511 100644 --- a/src/roman_datamodels/maker_utils/_common_meta.py +++ b/src/roman_datamodels/maker_utils/_common_meta.py @@ -689,9 +689,6 @@ def mk_ref_distoriton_meta(**kwargs): """ meta = mk_ref_common("DISTORTION", **kwargs) - meta["input_units"] = kwargs.get("input_units", u.pixel) - meta["output_units"] = kwargs.get("output_units", u.arcsec) - return meta @@ -700,8 +697,8 @@ def _mk_ref_photometry_meta(**kwargs): Create the photometry meta data for pixelarea reference files """ meta = {} - meta["pixelarea_steradians"] = kwargs.get("pixelarea_steradians", float(NONUM) * u.sr) - meta["pixelarea_arcsecsq"] = kwargs.get("pixelarea_arcsecsq", float(NONUM) * u.arcsec**2) + meta["pixelarea_steradians"] = kwargs.get("pixelarea_steradians", float(NONUM)) + meta["pixelarea_arcsecsq"] = kwargs.get("pixelarea_arcsecsq", float(NONUM)) return meta @@ -730,9 +727,6 @@ def mk_ref_units_dn_meta(reftype_, **kwargs): """ meta = mk_ref_common(reftype_, **kwargs) - meta["input_units"] = kwargs.get("input_units", u.DN) - meta["output_units"] = kwargs.get("output_units", u.DN) - return meta diff --git a/src/roman_datamodels/maker_utils/_ref_files.py b/src/roman_datamodels/maker_utils/_ref_files.py index f7504b4d..36aec680 100644 --- a/src/roman_datamodels/maker_utils/_ref_files.py +++ b/src/roman_datamodels/maker_utils/_ref_files.py @@ -1,7 +1,6 @@ import warnings import numpy as np -from astropy import units as u from astropy.modeling import models from roman_datamodels import stnode @@ -197,14 +196,10 @@ def mk_dark(*, shape=(2, 4096, 4096), filepath=None, **kwargs): darkref = stnode.DarkRef() darkref["meta"] = mk_ref_dark_meta(**kwargs.get("meta", {})) - darkref["data"] = kwargs.get("data", u.Quantity(np.zeros(shape, dtype=np.float32), u.DN, dtype=np.float32)) + darkref["data"] = kwargs.get("data", np.zeros(shape, dtype=np.float32)) darkref["dq"] = kwargs.get("dq", np.zeros(shape[1:], dtype=np.uint32)) - darkref["dark_slope"] = kwargs.get( - "dark_slope", u.Quantity(np.zeros(shape[1:], dtype=np.float32), u.DN / u.s, dtype=np.float32) - ) - darkref["dark_slope_error"] = kwargs.get( - "dark_slope_error", u.Quantity(np.zeros(shape[1:], dtype=np.float32), u.DN / u.s, dtype=np.float32) - ) + darkref["dark_slope"] = kwargs.get("dark_slope", np.zeros(shape[1:], dtype=np.float32)) + darkref["dark_slope_error"] = kwargs.get("dark_slope_error", np.zeros(shape[1:], dtype=np.float32)) return save_node(darkref, filepath=filepath) @@ -291,7 +286,7 @@ def mk_gain(*, shape=(4096, 4096), filepath=None, **kwargs): gainref = stnode.GainRef() gainref["meta"] = mk_ref_common("GAIN", **kwargs.get("meta", {})) - gainref["data"] = kwargs.get("data", u.Quantity(np.zeros(shape, dtype=np.float32), u.electron / u.DN, dtype=np.float32)) + gainref["data"] = kwargs.get("data", np.zeros(shape, dtype=np.float32)) return save_node(gainref, filepath=filepath) @@ -464,11 +459,11 @@ def _mk_phot_table_entry(key, **kwargs): } else: entry = { - "photmjsr": kwargs.get("photmjsr", 1.0e-15 * u.megajansky / u.steradian), - "uncertainty": kwargs.get("uncertainty", 1.0e-16 * u.megajansky / u.steradian), + "photmjsr": kwargs.get("photmjsr", 1.0e-15), + "uncertainty": kwargs.get("uncertainty", 1.0e-16), } - entry["pixelareasr"] = kwargs.get("pixelareasr", 1.0e-13 * u.steradian) + entry["pixelareasr"] = kwargs.get("pixelareasr", 1.0e-13) return entry @@ -528,7 +523,7 @@ def mk_readnoise(*, shape=(4096, 4096), filepath=None, **kwargs): readnoiseref = stnode.ReadnoiseRef() readnoiseref["meta"] = mk_ref_readnoise_meta(**kwargs.get("meta", {})) - readnoiseref["data"] = kwargs.get("data", u.Quantity(np.zeros(shape, dtype=np.float32), u.DN, dtype=np.float32)) + readnoiseref["data"] = kwargs.get("data", np.zeros(shape, dtype=np.float32)) return save_node(readnoiseref, filepath=filepath) @@ -560,7 +555,7 @@ def mk_saturation(*, shape=(4096, 4096), filepath=None, **kwargs): saturationref["meta"] = mk_ref_common("SATURATION", **kwargs.get("meta", {})) saturationref["dq"] = kwargs.get("dq", np.zeros(shape, dtype=np.uint32)) - saturationref["data"] = kwargs.get("data", u.Quantity(np.zeros(shape, dtype=np.float32), u.DN, dtype=np.float32)) + saturationref["data"] = kwargs.get("data", np.zeros(shape, dtype=np.float32)) return save_node(saturationref, filepath=filepath) diff --git a/tests/test_models.py b/tests/test_models.py index 300aed3b..80021c58 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -412,9 +412,7 @@ def test_make_dark(): assert dark.data.dtype == np.float32 assert dark.dq.dtype == np.uint32 assert dark.dq.shape == (8, 8) - assert dark.data.unit == u.DN assert dark.dark_slope.dtype == np.float32 - assert dark.dark_slope.unit == u.DN / u.s assert dark.dark_slope_error.dtype == np.float32 assert dark.dark_slope_error.shape == (8, 8) @@ -427,8 +425,6 @@ def test_make_dark(): def test_make_distortion(): distortion = utils.mk_distortion() assert distortion.meta.reftype == "DISTORTION" - assert distortion["meta"]["input_units"] == u.pixel - assert distortion["meta"]["output_units"] == u.arcsec assert isinstance(distortion["coordinate_distortion_transform"], Model) # Test validation @@ -456,7 +452,6 @@ def test_make_gain(): gain = utils.mk_gain(shape=(8, 8)) assert gain.meta.reftype == "GAIN" assert gain.data.dtype == np.float32 - assert gain.data.unit == u.electron / u.DN # Test validation gain_model = datamodels.GainRefModel(gain) @@ -515,8 +510,6 @@ def test_make_mask(): def test_make_pixelarea(): pixearea = utils.mk_pixelarea(shape=(8, 8)) assert pixearea.meta.reftype == "AREA" - assert isinstance(pixearea.meta.photometry.pixelarea_steradians, u.Quantity) - assert isinstance(pixearea.meta.photometry.pixelarea_arcsecsq, u.Quantity) assert pixearea.data.dtype == np.float32 # Test validation @@ -529,7 +522,6 @@ def test_make_readnoise(): readnoise = utils.mk_readnoise(shape=(8, 8)) assert readnoise.meta.reftype == "READNOISE" assert readnoise.data.dtype == np.float32 - assert readnoise.data.unit == u.DN # Test validation readnoise_model = datamodels.ReadnoiseRefModel(readnoise) @@ -575,7 +567,6 @@ def test_make_saturation(): assert saturation.meta.reftype == "SATURATION" assert saturation.dq.dtype == np.uint32 assert saturation.data.dtype == np.float32 - assert saturation.data.unit == u.DN # Test validation saturation_model = datamodels.SaturationRefModel(saturation) @@ -609,30 +600,15 @@ def test_make_refpix(): assert refpix.zeta.shape == (8, 8) assert refpix.alpha.shape == (8, 8) - assert refpix.meta.input_units == u.DN - assert refpix.meta.output_units == u.DN - # WFI Photom tests def test_make_wfi_img_photom(): wfi_img_photom = utils.mk_wfi_img_photom() assert wfi_img_photom.meta.reftype == "PHOTOM" - assert isinstance(wfi_img_photom.phot_table.F146.photmjsr, u.Quantity) - assert wfi_img_photom.phot_table.F146.photmjsr.unit == u.megajansky / u.steradian - assert isinstance(wfi_img_photom.phot_table.F184.photmjsr, u.Quantity) - - assert isinstance(wfi_img_photom.phot_table.F146.uncertainty, u.Quantity) - assert isinstance(wfi_img_photom.phot_table.F184.uncertainty, u.Quantity) - assert wfi_img_photom.phot_table.F184.uncertainty.unit == u.megajansky / u.steradian - - assert isinstance(wfi_img_photom.phot_table.F184.pixelareasr, u.Quantity) - assert isinstance(wfi_img_photom.phot_table.F146.pixelareasr, u.Quantity) - assert wfi_img_photom.phot_table.GRISM.pixelareasr.unit == u.steradian assert wfi_img_photom.phot_table.PRISM.photmjsr is None assert wfi_img_photom.phot_table.PRISM.uncertainty is None - assert isinstance(wfi_img_photom.phot_table.PRISM.pixelareasr, u.Quantity) # Test validation wfi_img_photom_model = datamodels.WfiImgPhotomRefModel(wfi_img_photom) @@ -761,7 +737,6 @@ def test_make_fps(): fps = utils.mk_fps(shape=shape) assert fps.data.dtype == np.uint16 - assert fps.data.unit == u.DN # Test validation fps_model = datamodels.FpsModel(fps) diff --git a/tests/test_stnode.py b/tests/test_stnode.py index 4e6449ce..f25a716f 100644 --- a/tests/test_stnode.py +++ b/tests/test_stnode.py @@ -2,7 +2,6 @@ from contextlib import nullcontext import asdf -import astropy.units as u import pytest from asdf.exceptions import ValidationError @@ -171,34 +170,18 @@ def test_set_pattern_properties(): # This model uses includes a patternProperty mdl = maker_utils.mk_wfi_img_photom() - # This should be invalid because it is not a quantity - with pytest.raises(asdf.ValidationError): - mdl.phot_table.F062.photmjsr = 3.14 - with pytest.raises(asdf.ValidationError): - mdl.phot_table.F062.uncertainty = 3.14 - with pytest.raises(asdf.ValidationError): - mdl.phot_table.F062.pixelareasr = 3.14 - # This is invalid because it is not a scalar with pytest.raises(asdf.ValidationError): - mdl.phot_table.F062.photmjsr = [37.0] * (u.MJy / u.sr) - with pytest.raises(asdf.ValidationError): - mdl.phot_table.F062.uncertainty = [37.0] * (u.MJy / u.sr) - with pytest.raises(asdf.ValidationError): - mdl.phot_table.F062.pixelareasr = [37.0] * u.sr - - # This should be invalid because it has the wrong unit - with pytest.raises(asdf.ValidationError): - mdl.phot_table.F062.photmjsr = 3.14 * u.m + mdl.phot_table.F062.photmjsr = [37.0] with pytest.raises(asdf.ValidationError): - mdl.phot_table.F062.uncertainty = 3.14 * u.m + mdl.phot_table.F062.uncertainty = [37.0] with pytest.raises(asdf.ValidationError): - mdl.phot_table.F062.pixelareasr = 3.14 * u.m + mdl.phot_table.F062.pixelareasr = [37.0] # Test some valid values (including the rest of the patternProperties) - mdl.phot_table.F062.photmjsr = 3.14 * (u.MJy / u.sr) - mdl.phot_table.F062.uncertainty = 0.1 * (u.MJy / u.sr) - mdl.phot_table.F062.pixelareasr = 37.0 * u.sr + mdl.phot_table.F062.photmjsr = 3.14 + mdl.phot_table.F062.uncertainty = 0.1 + mdl.phot_table.F062.pixelareasr = 37.0 # Test it can be None (including the rest of the patternProperties) mdl.phot_table.F062.photmjsr = None