ModelLibrary
- class jwst.datamodels.library.ModelLibrary(init, asn_exptypes=None, asn_n_members=None, on_disk=False, temp_directory=None, **datamodels_open_kwargs)[source]
Bases:
AbstractModelLibrary
JWST implementation of the ModelLibrary.
ModelLibrary is a container designed to allow efficient processing of datamodel instances created from an association. See the stpipe library documentation for more information.
Create a new ModelLibrary based on the provided “init”.
- Parameters:
- initstr or Path or list (of DataModels)
If a string or Path this should point to a valid association file. If a list of models consider continuing to use the list instead of making a library (the list will be more efficient and easier to use).
- asn_exptypeslist of str, optional
List of “exptypes” to load from the “init” value. Any association member with a “exptype” that matches (case insensitive) a value in this list will be available through the library.
- asn_n_membersint, optional
Number of association members to include in the library. This filtering will occur after “asn_exptypes” is applied. By default all members will be included.
- on_diskbool, optional, default=False
When enabled, keep the models in the library “on disk”, writing out temporary files when the models are “shelved”. This option is only compatible with models loaded from an association (not a list of models).
- temp_directorystr or Path, optional
The temporary directory in which to store models when “on_disk” is enabled. By default a
tempfile.TemporaryDirectory
will be created in the working directory.- **datamodels_open_kwargsdict
Keyword arguments that will provided to
_datamodels_open
when models are opened.
Attributes Summary
Return the directory from which the association was loaded.
Return the observatory name for CRDS queries.
List exposure types for all members in the library.
Return the library's on_disk attribute.
Methods Summary
Override base method so lazy-loading of metadata can be used to get CRDS parameters.
indices_for_exptype
(exptype)Determine the indices of models corresponding to
exptype
.read_metadata
(idx[, flatten])Read metadata for a model at the given index.
Attributes Documentation
- asn_dir
Return the directory from which the association was loaded.
- Returns:
- str
The directory from which the association was loaded.
- crds_observatory
Return the observatory name for CRDS queries.
- Returns:
- str
The observatory name for CRDS queries.
- exptypes
List exposure types for all members in the library.
- Returns:
- list
List of exposure types for all members in the library.
- on_disk
Return the library’s on_disk attribute.
If True, the library is using temporary files to store the models when not in use. If False, the library is storing the models in memory.
- Returns:
- bool
Whether the library is on disk.
Methods Documentation
- get_crds_parameters()[source]
Override base method so lazy-loading of metadata can be used to get CRDS parameters.
- Get the “crds_parameters” from either:
the first “science” member (based on exptype)
the first model (if no “science” member is found)
If no “science” members are found in the library a
UserWarning
will be issued.- Returns:
- crds_parametersdict
The result of
get_crds_parameters
called on the selected model.
- indices_for_exptype(exptype)[source]
Determine the indices of models corresponding to
exptype
.- Parameters:
- exptypestr
Exposure type as defined in an association, e.g. “science”. case-insensitive
- Returns:
- indlist
Indices of models in ModelLibrary with member exposure types matching
exptype
.
Notes
Library does NOT need to be open (i.e., this can be called outside the
with
context)