Skip to content

Commit

Permalink
remove deprecated models (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram authored Apr 5, 2024
1 parent f56a505 commit 4041d5f
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 110 deletions.
10 changes: 9 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2.0.0 (unreleased)
===================

- Remove deprecated jwst.datamodels models: DataModel, DrizProductModel,
MIRIRampModel, MultiProductModel [#171]

- Increase CRDS minimum version to 11.17.1 [#171]


1.10.1 (2024-03-25)
===================

Expand Down Expand Up @@ -298,7 +307,6 @@ Other

- Close for opened files [#169]


1.5.0 (2023-05-16)
==================

Expand Down
6 changes: 3 additions & 3 deletions docs/source/jwst/datamodels/attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The current models are as follows:
'NisImgPhotomModel', 'NisSossPhotomModel', 'NisWfssPhotomModel',
'NrsFsPhotomModel', 'NrsMosPhotomModel',
'PsfMaskModel',
'QuadModel', 'RampModel', 'MIRIRampModel',
'QuadModel', 'RampModel',
'RampFitOutputModel', 'ReadnoiseModel',
'ReferenceFileModel', 'ReferenceCubeModel', 'ReferenceImageModel', 'ReferenceQuadModel',
'RegionsModel', 'ResetModel',
Expand Down Expand Up @@ -105,9 +105,9 @@ is stored in a separate image extension). Full-frame data for all other
instruments have four columns or rows of reference pixels on each edge
of the image.

DataModel Base Class
JwstDataModel Base Class
--------------------

.. autoclass:: jwst.datamodels.DataModel
.. autoclass:: jwst.datamodels.JwstDataModel
:members:
:noindex:
12 changes: 6 additions & 6 deletions docs/source/jwst/datamodels/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ use::
In place of `ImageModel`, use the type of data one expects to find in
the file. For example, if spectrographic data is expected, use
`SpecModel`. If it doesn't matter (perhaps the application is only
sorting FITS files into categories) use the base class `DataModel`.
sorting FITS files into categories) use the base class `JwstDataModel`.

An alternative is to use::

Expand Down Expand Up @@ -276,9 +276,9 @@ use the :ref:`metadata` tree.
There is a convenience method, `find_fits_keyword` to find where a
FITS keyword is used in the metadata tree::

>>> from stdatamodels.jwst.datamodels import DataModel
>>> from stdatamodels.jwst.datamodels import JwstDataModel
>>> # First, create a model of the desired type
>>> model = DataModel()
>>> model = JwstDataModel()
>>> model.find_fits_keyword('DATE-OBS')
[u'meta.observation.date']

Expand Down Expand Up @@ -322,20 +322,20 @@ Environment Variables
There are a number of environment variables that affect how models are read.

PASS_INVALID_VALUES
Used by `~jwst.datamodels.DataModel` when instantiating
Used by `~jwst.datamodels.JwstDataModel` when instantiating
a model from a file. If ``True``, values that do not validate the schema will
still be added to the metadata. If ``False``, they will be set to ``None``.
Default is ``False``.

STRICT_VALIDATION
Used by `~jwst.datamodels.DataModel` when instantiating a model from a file.
Used by `~jwst.datamodels.JwstDataModel` when instantiating a model from a file.
If ``True``, schema validation errors will generate an exception.
If ``False``, they will generate a warning.
Default is ``False``.

SKIP_FITS_UPDATE
DEPRECATED: In the future the FITS header will always be used.
Used by `~jwst.datamodels.DataModel` when instantiating a
Used by `~jwst.datamodels.JwstDataModel` when instantiating a
model from a FITS file. When ``False``, models opened from FITS files will
proceed and load the FITS header values into the model. When ``True`` and the
FITS file has an ASDF extension, the loading/validation of the FITS header
Expand Down
14 changes: 7 additions & 7 deletions docs/source/jwst/datamodels/new_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ The model class
Now, let's see how this schema is tied in with a new Python class for
the model.

First, we need to import the `DataModel` class, which is the base
First, we need to import the `JwstDataModel` class, which is the base
class for all models::

from stdatamodels.jwst.datamodels import DataModel
from stdatamodels.jwst.datamodels import JwstDataModel

Then we create a new Python class that inherits from `DataModel`, and
Then we create a new Python class that inherits from `JwstDataModel`, and
set its `schema_url` class member to point to the schema that we just
defined above::

class MiriBadPixelMaskModel(DataModel):
class MiriBadPixelMaskModel(JwstDataModel):
schema_url = "bad_pixel_mask.schema.yaml"

Here, the `schema_url` has all of the "magical" URL abilities
Expand Down Expand Up @@ -234,7 +234,7 @@ elements, by setting `schema_url` to::
Within this class, we'll define a constructor. All model constructors
must take the highly polymorphic ``init`` value as the first argument.
This can be a file, another model, or all kinds of other things. See
the docstring of `jwst.datamodels.DataModel.__init__` for more
the docstring of `jwst.datamodels.JwstDataModel.__init__` for more
information. But we're going to let the base class handle that
anyway.

Expand All @@ -252,7 +252,7 @@ technically writing a new constructor for the model is optional:
Parameters
----------
init : any
Any of the initializers supported by `~jwst.datamodels.DataModel`.
Any of the initializers supported by `~jwst.datamodels.JwstDataModel`.
dq : numpy array
The data quality array.
Expand Down Expand Up @@ -336,7 +336,7 @@ function.
Lastly, remember the ``meta.bad_pixel_count`` element we defined
above? We need some way to make sure that whenever the file is
written out that it has the correct value. The model may have been
loaded and modified. For this, `DataModel` has the `on_save` method
loaded and modified. For this, `JwstDataModel` has the `on_save` method
hook, which may be overridden by the subclass to add anything that
should happen just before saving:

Expand Down
2 changes: 1 addition & 1 deletion docs/source/jwst/datamodels/structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ attribute is not defined, which in turn calls _make_default_array if
the schema says the attribute is an array. All these methods can be
found in properties.py.

The base class for Datamodels isDataModel, in model_base.py. It takes
The base class for Datamodels is JwstDataModel, in model_base.py. It takes
several arguments, the most important of which is init, which as the
name suggests, specifies how to initialize the primary data array of
the model. Init is most usually the name of a file, but can be an
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test = [
"psutil",
"pytest>=4.6.0",
"pytest-doctestplus",
"crds>=11.16.14",
"crds>=11.17.1",
"scipy>=1.5",
]
docs = [
Expand Down
11 changes: 3 additions & 8 deletions src/stdatamodels/jwst/datamodels/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .model_base import JwstDataModel, DataModel
from .model_base import JwstDataModel
from .abvega_offset import ABVegaOffsetModel
from .amilg import AmiLgModel
from .amilgfitmodel import AmiLgFitModel
Expand All @@ -16,7 +16,6 @@
from .dark import DarkModel
from .darkMIRI import DarkMIRIModel
from .drizpars import DrizParsModel
from .drizproduct import DrizProductModel
from .emi import EmiModel
from .extract1dimage import Extract1dImageModel
from .extract1d_spec import Extract1dIFUModel
Expand All @@ -37,12 +36,10 @@
from .level1b import Level1bModel
from .linearity import LinearityModel
from .mask import MaskModel
from .ramp import MIRIRampModel
from .mrsxartcorr import MirMrsXArtCorrModel
from .multicombinedspec import MultiCombinedSpecModel
from .multiexposure import MultiExposureModel
from .multiextract1d import MultiExtract1dImageModel
from .multiprod import MultiProductModel
from .multislit import MultiSlitModel
from .multispec import MultiSpecModel
from .nirspec_flat import NirspecFlatModel, NirspecQuadFlatModel
Expand Down Expand Up @@ -94,7 +91,7 @@

__all__ = [
'open',
'DataModel', 'JwstDataModel',
'JwstDataModel',
'ABVegaOffsetModel',
'AmiLgModel',
'AmiLgFitModel',
Expand All @@ -109,7 +106,6 @@
'DarkModel', 'DarkMIRIModel',
'DisperserModel', 'DistortionModel', 'DistortionMRSModel',
'DrizParsModel',
'DrizProductModel',
'EmiModel',
'Extract1dImageModel',
'Extract1dIFUModel',
Expand All @@ -126,7 +122,6 @@
'LinearityModel', 'MaskModel', 'MSAModel',
'MultiCombinedSpecModel', 'MultiExposureModel',
'MultiExtract1dImageModel', 'MultiSlitModel',
'MultiProductModel',
'MultiSpecModel',
'NIRCAMGrismModel', 'NIRISSGrismModel',
'OTEModel',
Expand All @@ -140,7 +135,7 @@
'NisImgPhotomModel', 'NisSossPhotomModel', 'NisWfssPhotomModel',
'NrsFsPhotomModel', 'NrsMosPhotomModel',
'PsfMaskModel',
'QuadModel', 'RampModel', 'MIRIRampModel',
'QuadModel', 'RampModel',
'RampFitOutputModel', 'ReadnoiseModel',
'ReferenceFileModel', 'ReferenceCubeModel', 'ReferenceImageModel', 'ReferenceQuadModel',
'RegionsModel', 'ResetModel',
Expand Down
11 changes: 0 additions & 11 deletions src/stdatamodels/jwst/datamodels/drizproduct.py

This file was deleted.

8 changes: 1 addition & 7 deletions src/stdatamodels/jwst/datamodels/model_base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import warnings
from astropy.time import Time

from stdatamodels import DataModel as _DataModel


__all__ = ["DataModel", "JwstDataModel"]
__all__ = ["JwstDataModel"]


class JwstDataModel(_DataModel):
Expand Down Expand Up @@ -53,8 +52,3 @@ def on_save(self, init):
super().on_save(init)

self.meta.date = Time.now().isot


class DataModel(JwstDataModel):
def __init_subclass__(cls):
warnings.warn("Class DataModel has been renamed JwstDataModel. It will be removed in v 1.5.", DeprecationWarning, 2)
12 changes: 0 additions & 12 deletions src/stdatamodels/jwst/datamodels/multiprod.py

This file was deleted.

17 changes: 1 addition & 16 deletions src/stdatamodels/jwst/datamodels/ramp.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import warnings

from .model_base import JwstDataModel


__all__ = ['RampModel', 'MIRIRampModel']
__all__ = ['RampModel']


class RampModel(JwstDataModel):
Expand Down Expand Up @@ -43,16 +41,3 @@ def __init__(self, init=None, **kwargs):
self.pixeldq = self.pixeldq
self.groupdq = self.groupdq
self.err = self.err


class MIRIRampModel(RampModel):
"""A data model for 4D MIRI ramps.
This model has been deprecated. Please use `RampModel` instead.
"""
def __init__(self, *args, **kwargs):
warnings.warn(
'"MIRIRampModel" is deprecated and will be removed. Use RampModel',
category=DeprecationWarning,
)
return super(MIRIRampModel, self).__init__(*args, **kwargs)
18 changes: 2 additions & 16 deletions src/stdatamodels/jwst/datamodels/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
import pytest

from stdatamodels.jwst.datamodels import (JwstDataModel, ImageModel, MaskModel, AsnModel,
MultiSlitModel, SlitModel, DataModel,
DrizProductModel, MultiProductModel, MIRIRampModel,
MultiSlitModel, SlitModel,
NirspecFlatModel, NirspecQuadFlatModel,
SlitDataModel, IFUImageModel, ABVegaOffsetModel)
from stdatamodels.jwst import datamodels
Expand Down Expand Up @@ -322,11 +321,7 @@ def test_all_datamodels_init(model):
"""
Test that all current datamodels can be initialized.
"""
if model in (DrizProductModel, MultiProductModel, MIRIRampModel):
with pytest.warns(DeprecationWarning):
model()
else:
model()
model()


def test_meta_date_management(tmp_path):
Expand Down Expand Up @@ -555,15 +550,6 @@ def test_dq_def_roundtrip(tmp_path):
assert total_diff == 0


def test_deprecation_data_model():
""" Tests that inheriting from stdatamodels.jwst.datamodels.DataModel
raises a DeprecationWarning."""

with pytest.deprecated_call():
class Dummy(DataModel):
pass


@pytest.mark.parametrize("shape", [None, 10])
@pytest.mark.parametrize("model", [NirspecFlatModel, NirspecQuadFlatModel])
def test_nirspec_flat_table_migration(tmp_path, model, shape):
Expand Down
27 changes: 6 additions & 21 deletions src/stdatamodels/jwst/datamodels/tests/test_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test datamodel.open
"""

import contextlib
import os
import os.path
from pathlib import Path, PurePath
Expand Down Expand Up @@ -44,22 +43,6 @@ def test_guess(guess):
pass


def test_mirirampmodel_deprecation(tmp_path):
"""Test that a deprecated MIRIRampModel can be opened"""
path = str(tmp_path / "ramp.fits")
# Create a MIRIRampModel, working around the deprecation.
model = datamodels.RampModel((1, 1, 10, 10))
model.save(path)
hduls = fits.open(path, mode='update')
hduls[0].header['datamodl'] = 'MIRIRampModel'
hduls.close()

# Test it.
with pytest.warns(DeprecationWarning):
miri_ramp = datamodels.open(path)
assert isinstance(miri_ramp, datamodels.RampModel)


@pytest.fixture
def mock_get_available_memory(monkeypatch):
def mock(include_swap=True):
Expand Down Expand Up @@ -255,10 +238,12 @@ def test_open_asdf_no_datamodel_class(tmp_path, suffix):
model = DataModel()
model.save(path)

# Note: only the fits open emits a "model_type not found" warning. Both
# fits and asdf should behave the same
ctx = pytest.warns(util.NoTypeWarning) if suffix == 'fits' else contextlib.nullcontext()
with ctx:
# previously, only the fits file issued a NoTypeWarning
# this was a quirk of the deprecated (and now removed) jwst.DataModel
# sharing the same class name as stdatamodels.DataModel (used here)
# now that jwst.DataModel is removed, both the fits and asdf
# files correctly report NoTypeWarning
with pytest.warns(util.NoTypeWarning):
with datamodels.open(path) as m:
assert isinstance(m, DataModel)

Expand Down

0 comments on commit 4041d5f

Please sign in to comment.