NdfInputArchive#

class lsst.images.ndf.NdfInputArchive(file)#

Bases: InputArchive[NdfPointerModel]

Reads HDS-on-HDF5 NDF files written by NdfOutputArchive.

Instances should only be constructed via the open() context manager.

Parameters:

file (File) – Open h5py.File handle. Owned by the caller of open(); the archive does not close it.

Attributes Summary

info

Schema/format info read from the open document's DATA_MODEL (serialization.ArchiveInfo).

Methods Summary

deserialize_pointer(pointer, model_type, ...)

Deserialize an object that was saved by serialize_pointer.

get_array(model, *[, slices, strip_header])

Load an array from the archive.

get_basic_info(path)

Read the schema URL from the DATA_MODEL scalar and the FORMAT_VERSION primitive without deserializing pixel data.

get_frame_set(pointer)

Return an already-deserialized frame set from the archive.

get_opaque_metadata()

Return opaque metadata loaded from the file that should be saved if another version of the object is saved to the same file format.

get_structured_array(model[, strip_header])

Load a table from the archive as a structured array.

get_table(model[, strip_header])

Load a table from the archive.

get_tree(model_type)

Read and validate the main Pydantic tree at /MORE/LSST/JSON.

open(cls, path)

Open an NDF file for reading and yield an NdfInputArchive.

open_tree(cls, path, *[, partial])

Open the NDF file and yield (archive, tree, info).

Attributes Documentation

info#

Schema/format info read from the open document’s DATA_MODEL (serialization.ArchiveInfo).

Methods Documentation

deserialize_pointer(pointer, model_type, deserializer)#

Deserialize an object that was saved by serialize_pointer.

Parameters:
Returns:

The deserialized object.

Return type:

V

Notes

Implementations are required to remember previously-deserialized objects and return them when the same pointer is passed in multiple times.

There is no deserialize_direct (to pair with serialize_direct) because the caller can just call a deserializer function directly on a sub-model of its Pydantic tree.

get_array(model, *, slices=Ellipsis, strip_header=<function no_header_updates>)#

Load an array from the archive.

Parameters:
  • model (ArrayReferenceModel | InlineArrayModel) – A Pydantic model that references or holds the array.

  • slices (tuple[slice, ...] | EllipsisType, default: Ellipsis) – Slices that specify a subset of the original array to read.

  • strip_header (Callable[[Header], None], default: <function no_header_updates at 0x7f27576196c0>) – A callable that strips out any FITS header cards added by the update_header argument in the corresponding call to add_array.

Return type:

ndarray

classmethod get_basic_info(path)#

Read the schema URL from the DATA_MODEL scalar and the FORMAT_VERSION primitive without deserializing pixel data.

Reading the datasets directly from the HDF5 file avoids building the full internal model, which would eagerly read the (potentially large) JSON tree.

Parameters:

path (str | ParseResult | ResourcePath | Path) – Path to the archive to read.

Return type:

ArchiveInfo

get_frame_set(pointer)#

Return an already-deserialized frame set from the archive.

Parameters:
  • ref – Implementation-specific reference to the frame set.

  • pointer (NdfPointerModel)

Returns:

Loaded frame set.

Return type:

FrameSet

get_opaque_metadata()#

Return opaque metadata loaded from the file that should be saved if another version of the object is saved to the same file format.

Returns:

Opaque metadata specific to this archive type that should be round-tripped if it is saved in the same format.

Return type:

OpaqueArchiveMetadata

get_structured_array(model, strip_header=<function no_header_updates>)#

Load a table from the archive as a structured array.

Parameters:
  • model (TableModel) – A Pydantic model that references or holds the table.

  • strip_header (Callable[[Header], None], default: <function no_header_updates at 0x7f27576196c0>) – A callable that strips out any FITS header cards added by the update_header argument in the corresponding call to add_structured_array.

Returns:

The loaded table as a structured array.

Return type:

numpy.ndarray

get_table(model, strip_header=<function no_header_updates>)#

Load a table from the archive.

Parameters:
  • model (TableModel) – A Pydantic model that references or holds the table.

  • strip_header (Callable[[Header], None], default: <function no_header_updates at 0x7f27576196c0>) – A callable that strips out any FITS header cards added by the update_header argument in the corresponding call to add_table.

Returns:

The loaded table.

Return type:

astropy.table.Table

get_tree(model_type)#

Read and validate the main Pydantic tree at /MORE/LSST/JSON.

Parameters:

model_type (type[TypeVar(T, bound= ArchiveTree)]) – Archive tree model type to validate the JSON tree against.

Return type:

TypeVar(T, bound= ArchiveTree)

classmethod open(cls, path)#

Open an NDF file for reading and yield an NdfInputArchive.

Remote ResourcePaths are materialised locally first; fsspec-direct h5py reads are a deferred follow-up.

Parameters:

path (Union[str, ParseResult, ResourcePath, Path, IO[bytes]]) – Path to the NDF file to open, or a seekable binary stream containing the file’s content.

Return type:

Iterator[Self]

classmethod open_tree(cls, path, *, partial=True, **backend_kwargs)#

Open the NDF file and yield (archive, tree, info).

The schema is read from the open document’s DATA_MODEL rather than a separate get_basic_info open. Requires the symmetric LSST JSON tree; partial is accepted but not meaningful, since h5py reads lazily regardless.

Parameters:
  • path (Union[str, ParseResult, ResourcePath, Path, IO[bytes]]) – The file resource to open, or a seekable binary stream containing the file’s content.

  • partial (bool, default: True) – Accepted for interface compatibility but not meaningful; h5py reads lazily regardless.

  • **backend_kwargs (Any) – Backend-specific options; none are currently used.

Return type:

Iterator[tuple[Self, ArchiveTree, ArchiveInfo]]

This page was last modified on .