open

stdatamodels.jwst.datamodels.open(init=None, guess=True, **kwargs)

Load a data model, list of models, or association from file.

Parameters:
initshape tuple, file path, astropy.io.fits.HDUList, numpy array, dict, None
  • file path: Initialize from the given file (FITS, JSON or ASDF)

  • dict: Dictionary representing an association. The association will be returned as a ModelContainer with the models loaded from the files specified in the association dict.

  • list[str]: Initialize from a list of files. The list will be returned as a ModelContainer with the models loaded from the specified files.

  • JwstDataModel: Initialize from an existing model. The output model will be a shallow copy of the input model. This is supported for pipeline code convenience, but is not recommended for general use as it may cause unexpected behavior.

  • None: Deprecated; use the DataModel constructor directly instead. A default data model with no shape.

  • tuple: Deprecated; use the DataModel constructor directly instead. Initialize with empty data of the given shape.

  • np.ndarray: Deprecated; use the DataModel constructor directly instead. Initialize a model with primary array attribute (typically ‘data’) set to the input array. For 2-D input an ImageModel is created, for 3-D a CubeModel, and for 4-D a QuadModel.

  • HDUList: Deprecated; save the HDUList to file and then call open on the file instead. Initialize from the given HDUList.

guessbool

Guess as to the model type if the model type is not specifically known from the file. If not guess and the model type is not explicit, raise a TypeError.

**kwargs

Additional keyword arguments passed to the DataModel constructor. Some arguments are general, others are file format-specific. Arguments of note are:

  • validate_arrays : bool If True, arrays will be validated against ndim, max_ndim, and datatype validators in the schemas.

Returns:
DataModel

A new model instance.

Warning

The open function is primarily intended for opening files and creating models from them, and is not intended for creating models from scratch. Init types of None, shape tuple, and numpy array are deprecated and will raise a TypeError in the future. Use the DataModel constructors directly instead, i.e. JwstDataModel for a generic model or one of the many model subclasses (e.g. ImageModel, MultiSlitModel) for specific applications. None, shape tuple, and numpy array are all valid inputs to those constructors. See the documentation for each model class for details on how to use them.