Skip to content

Commit

Permalink
JP-3721: Simplify ModelContainer (spacetelescope#8831)
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter authored and hayescr committed Oct 29, 2024
1 parent bc38872 commit 2d5fe0a
Show file tree
Hide file tree
Showing 21 changed files with 203 additions and 303 deletions.
1 change: 1 addition & 0 deletions changes/8831.datamodels.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove memory-saving options from ModelContainer
36 changes: 34 additions & 2 deletions docs/jwst/stpipe/devel_io_design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,47 @@ Many of the JWST calibration steps and pipelines expect an
:ref:`Association <associations>` file as input. When opened with
:meth:`~jwst.stpipe.step.Step.open_model`, a
:class:`~jwst.datamodels.ModelContainer` is returned. `ModelContainer`
is, among other features, a list-like object where each element is the
`DataModel` of each member of the association. The `meta.asn_table` is
is a list-like object where each element is the
`DataModel` of each member of the association. The `asn_table` attribute is
populated with the association data structure, allowing direct access
to the association itself. The association file, as well as the files
listed in the association file, must be in the input directory.

To read in a list of files, or an association file, as an association,
use the `load_as_level2_asn` or `load_as_level3_asn` methods.

ModelContainer vs ModelLibrary
``````````````````````````````

Some steps in the pipeline, namely any steps involved in the Stage 3 Imaging pipeline,
rely on the :class:`~jwst.datamodels.ModelLibrary` class instead of the
:class:`~jwst.datamodels.ModelContainer` class to process association-type data.
The `ModelLibrary` class is purpose-built for enabling memory-saving options in the
image3 pipeline and is only recommended when working with large associations.
Additional documentation on the `ModelLibrary` class can be found in the
`stpipe ModelLibrary documentation <https://stpipe.readthedocs.io/en/latest/model_library.html>`_.

ModelContainer Changes in JWST 1.17
```````````````````````````````````

In JWST 1.17, the `ModelContainer` class was de-scoped in light of the introduction of the
`ModelLibrary` class in JWST 1.16. The `ModelContainer` class is still the recommended class
for handling association-type data, but it is no longer a subclass of `JWSTDataModel`. The
following changes in behavior are noteworthy:

* The `ModelContainer` class no longer has a `meta` attribute. The association data is now
stored in the top-level `asn_table` attribute, along with several other association-relevant
attributes including `asn_table_name`, `asn_pool_name`, `asn_exptypes`, `asn_n_members`,
`asn_file_path`. Note that `asn_table` is now a dictionary, not an `ObjectNode`.
* All infrastructure that attempted memory savings in the `ModelContainer` class has been removed.
Use the `ModelLibrary` class if memory-saving options are needed.
* A `ModelContainer` object can no longer hold a list of `ModelContainer` objects.
* The `ModelContainer` class is still list-like, and can be indexed and sliced like a list.
* The `ModelContainer` class is still the default class returned by stdatamodels `open()`
for association-type input data, e.g. a .json file or dict.
* The `ModelContainer` class can still be used as a context manager, such that `with open(asn_file.json)`
still works.

Input Source
------------

Expand Down
3 changes: 1 addition & 2 deletions jwst/badpix_selfcal/badpix_selfcal_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class BadpixSelfcalStep(Step):
"""

def save_model(self, model, *args, **kwargs):
"""Override save_model to suppress index 0 when save_model is True
"""
"""Override save_model to suppress index 0 when save_model is True"""
kwargs["idx"] = None
return Step.save_model(self, model, *args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion jwst/cube_build/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, input, single, output_file, output_dir):
self.output_name = 'Temp'
self.input_models = input_models
if not single: # find the name of the output file from the association
self.output_name = input_models.meta.asn_table.products[0].name
self.output_name = input_models.asn_table["products"][0]["name"]
else:
# close files opened above
self.close()
Expand Down
Loading

0 comments on commit 2d5fe0a

Please sign in to comment.