JsonInputArchive#
- class lsst.images.json.JsonInputArchive(indirect: list[Any] | None = None)#
Bases:
InputArchive[JsonRef]An implementation of the
serialization.InputArchiveinterface that reads from JSON files.Parameters#
- indirect
The
serialization.ArchiveTree.indirectattribute of the root serialization model.
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 top-level tree's
schema_url; JSON has no container format version.get_frame_set(ref)Return an already-deserialized frame set from the archive.
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.
open_tree(path, tree_cls, *[, partial])Parse the JSON tree and yield
(archive, tree).Methods Documentation
- deserialize_pointer(pointer: JsonRef, model_type: type[U], deserializer: Callable[[U, InputArchive[JsonRef]], 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_typeand 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 withserialize_direct) because the caller can just call a deserializer function directly on a sub-model of its Pydantic tree.
- get_array(model: ~lsst.images.serialization._asdf_utils.ArrayReferenceModel | ~lsst.images.serialization._asdf_utils.InlineArrayModel, *, 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#
- model
A Pydantic model that references or holds 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_headerargument in the corresponding call toadd_array.
- classmethod get_basic_info(path: str | ParseResult | ResourcePath | Path) ArchiveInfo#
Read the top-level tree’s
schema_url; JSON has no container format version.This parses the whole document. Unlike the FITS and NDF backends there is no cheap header to read:
schema_urlis a computed field serialized after the (potentially large)indirectpayload, and nested trees carry their ownschema_url, so a bounded prefix cannot identify the top-level tree reliably. JSON is not intended for large pixel archives, where FITS or NDF should be used instead.
- get_frame_set(ref: JsonRef) FrameSet#
Return an already-deserialized frame set from the archive.
Parameters#
- ref
Implementation-specific reference to the frame set.
Returns#
- FrameSet
Loaded frame set.
- get_opaque_metadata() OpaqueArchiveMetadata | None#
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.
- get_structured_array(model: ~lsst.images.serialization._tables.TableModel, 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#
- model
A Pydantic model that references or holds the table.
- strip_header
A callable that strips out any FITS header cards added by the
update_headerargument in the corresponding call toadd_structured_array.
Returns#
- numpy.ndarray
The loaded table as a structured array.
- get_table(model: ~lsst.images.serialization._tables.TableModel, strip_header: ~collections.abc.Callable[[~astropy.io.fits.header.Header], None] = <function no_header_updates>) Table#
Load a table from the archive.
Parameters#
- model
A Pydantic model that references or holds the table.
- strip_header
A callable that strips out any FITS header cards added by the
update_headerargument in the corresponding call toadd_table.
Returns#
- astropy.table.Table
The loaded table.
- classmethod open_tree(path: str | ParseResult | ResourcePath | Path, tree_cls: type[ArchiveTree], *, partial: bool = True, **backend_kwargs: Any) Iterator[tuple[Self, ArchiveTree]]#
Parse the JSON tree and yield
(archive, tree).A no-resource context manager: JSON is fully in memory, so
partialis a no-op.tree.indirectis released when the context exits.