InputArchive#

class lsst.images.serialization.InputArchive#

Bases: ABC, Generic

Abstract interface for reading from a file format.

Notes#

An input archive instance is assumed to be paired with a Pydantic model that represents a JSON tree, with the archive used to deserialize data that is not native JSON from data that is (which may just be a reference to binary data stored elsewhere in the file). The archive doesn’t actually hold that model instance because we’d prefer to avoid making the input archive generic over the model type. It is expected that most concrete archive implementations will provide a method to load the paired model from a file, but this is not part of the base class interface.

Methods Summary

deserialize_pointer(pointer, model_type, ...)

Deserialize an object that was saved by serialize_pointer.

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

Load an array from the archive.

get_frame_set(ref)

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(ref[, strip_header])

Load a table from the archive as a structured array.

get_table(ref[, strip_header])

Load a table from the archive.

Methods Documentation

abstract deserialize_pointer(pointer: P, model_type: type[U], deserializer: Callable[[U, InputArchive[P]], V]) V#

Deserialize an object that was saved by serialize_pointer.

Parameters#

pointer

JSON Pointer model to dereference.

model_type

Pydantic model type that the pointer should dereference to.

deserializer

Callable that takes an instance of model_type and an input archive, and returns the deserialized object.

Returns#

V

The deserialized object.

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.

abstract get_array(ref: ~lsst.images.serialization._asdf_utils.ArrayReferenceModel, *, slices: tuple[slice, ...] | ellipsis = Ellipsis, strip_header: ~collections.abc.Callable[[~astropy.io.fits.header.Header], None] = <function no_header_updates>) ndarray#

Load an array from the archive.

Parameters#

ref

A Pydantic model that references the array.

slices

Slices that specify a subset of the original array to read.

strip_header

A callable that strips out any FITS header cards added by the update_header argument in the corresponding call to add_array.

abstract get_frame_set(ref: P) FrameSet#

Return an already-deserialized frame set from the archive.

Parameters#

ref

Implementation-specific reference to the frame set.

Returns#

FrameSet

Loaded frame set.

abstract get_opaque_metadata() OpaqueArchiveMetadata#

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#

OpaqueArchiveMetadata

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

abstract get_structured_array(ref: ~lsst.images.serialization._tables.TableReferenceModel, strip_header: ~collections.abc.Callable[[~astropy.io.fits.header.Header], None] = <function no_header_updates>) ndarray#

Load a table from the archive as a structured array.

Parameters#

ref

A Pydantic model that references the table.

strip_header

A callable that strips out any FITS header cards added by the update_header argument in the corresponding call to add_structured_array.

Returns#

numpy.ndarray

The loaded table as a structured array.

abstract get_table(ref: ~lsst.images.serialization._tables.TableReferenceModel, strip_header: ~collections.abc.Callable[[~astropy.io.fits.header.Header], None] = <function no_header_updates>) Table#

Load a table from the archive.

Parameters#

ref

A Pydantic model that references the table.

strip_header

A callable that strips out any FITS header cards added by the update_header argument in the corresponding call to add_table.

Returns#

astropy.table.Table

The loaded table.