Skip to content

Commit 2d5fe0a

Browse files
emolterhayescr
authored andcommitted
JP-3721: Simplify ModelContainer (spacetelescope#8831)
1 parent bc38872 commit 2d5fe0a

File tree

21 files changed

+203
-303
lines changed

21 files changed

+203
-303
lines changed

changes/8831.datamodels.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove memory-saving options from ModelContainer

docs/jwst/stpipe/devel_io_design.rst

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,47 @@ Many of the JWST calibration steps and pipelines expect an
163163
:ref:`Association <associations>` file as input. When opened with
164164
:meth:`~jwst.stpipe.step.Step.open_model`, a
165165
:class:`~jwst.datamodels.ModelContainer` is returned. `ModelContainer`
166-
is, among other features, a list-like object where each element is the
167-
`DataModel` of each member of the association. The `meta.asn_table` is
166+
is a list-like object where each element is the
167+
`DataModel` of each member of the association. The `asn_table` attribute is
168168
populated with the association data structure, allowing direct access
169169
to the association itself. The association file, as well as the files
170170
listed in the association file, must be in the input directory.
171171

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

175+
ModelContainer vs ModelLibrary
176+
``````````````````````````````
177+
178+
Some steps in the pipeline, namely any steps involved in the Stage 3 Imaging pipeline,
179+
rely on the :class:`~jwst.datamodels.ModelLibrary` class instead of the
180+
:class:`~jwst.datamodels.ModelContainer` class to process association-type data.
181+
The `ModelLibrary` class is purpose-built for enabling memory-saving options in the
182+
image3 pipeline and is only recommended when working with large associations.
183+
Additional documentation on the `ModelLibrary` class can be found in the
184+
`stpipe ModelLibrary documentation <https://stpipe.readthedocs.io/en/latest/model_library.html>`_.
185+
186+
ModelContainer Changes in JWST 1.17
187+
```````````````````````````````````
188+
189+
In JWST 1.17, the `ModelContainer` class was de-scoped in light of the introduction of the
190+
`ModelLibrary` class in JWST 1.16. The `ModelContainer` class is still the recommended class
191+
for handling association-type data, but it is no longer a subclass of `JWSTDataModel`. The
192+
following changes in behavior are noteworthy:
193+
194+
* The `ModelContainer` class no longer has a `meta` attribute. The association data is now
195+
stored in the top-level `asn_table` attribute, along with several other association-relevant
196+
attributes including `asn_table_name`, `asn_pool_name`, `asn_exptypes`, `asn_n_members`,
197+
`asn_file_path`. Note that `asn_table` is now a dictionary, not an `ObjectNode`.
198+
* All infrastructure that attempted memory savings in the `ModelContainer` class has been removed.
199+
Use the `ModelLibrary` class if memory-saving options are needed.
200+
* A `ModelContainer` object can no longer hold a list of `ModelContainer` objects.
201+
* The `ModelContainer` class is still list-like, and can be indexed and sliced like a list.
202+
* The `ModelContainer` class is still the default class returned by stdatamodels `open()`
203+
for association-type input data, e.g. a .json file or dict.
204+
* The `ModelContainer` class can still be used as a context manager, such that `with open(asn_file.json)`
205+
still works.
206+
175207
Input Source
176208
------------
177209

jwst/badpix_selfcal/badpix_selfcal_step.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class BadpixSelfcalStep(Step):
3535
"""
3636

3737
def save_model(self, model, *args, **kwargs):
38-
"""Override save_model to suppress index 0 when save_model is True
39-
"""
38+
"""Override save_model to suppress index 0 when save_model is True"""
4039
kwargs["idx"] = None
4140
return Step.save_model(self, model, *args, **kwargs)
4241

jwst/cube_build/data_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self, input, single, output_file, output_dir):
8989
self.output_name = 'Temp'
9090
self.input_models = input_models
9191
if not single: # find the name of the output file from the association
92-
self.output_name = input_models.meta.asn_table.products[0].name
92+
self.output_name = input_models.asn_table["products"][0]["name"]
9393
else:
9494
# close files opened above
9595
self.close()

0 commit comments

Comments
 (0)