read_archive#
- lsst.images.serialization.read_archive(path, cls=None, *, format=None, **kwargs)#
Read an archive whose in-memory type is inferred from its schema.
Dispatches to the appropriate backend based on
path’s extension (or, for stream input, its leading bytes), resolves the registered in-memory type from the file’s schema, and returns the fully deserialized object. Schema-version compatibility is enforced when the model validates the on-disk tree, viamin_read_version. A path with a.gz/.zstcompression suffix is decompressed transparently; stream input must already be decompressed.This is the convenient way to read a whole object. To read individual components, or to reach the metadata and butler info stored alongside the object, use
open_archiveinstead.- Parameters:
path (
Union[str,ParseResult,ResourcePath,Path,IO[bytes]]) – File to read; convertible tolsst.resources.ResourcePath, or a seekable binary stream containing the file’s content (e.g.io.BytesIO(data)for in-memory bytes).cls (
type[Any] |None, default:None) – Optional expected in-memory type. When given, the file’s schema is checked againstclsand the deserialized object is validated withisinstance(raisingTypeErrorotherwise), and the static return type isT.format (
str|None, default:None) – Optional backend name ("fits","ndf", or"json") forcing the backend, instead of dispatching on the path’s extension or the stream’s leading bytes.**kwargs (
Any) – Type-specific keyword arguments forwarded to the object’sdeserialize(e.g.bboxfor an image subset read). Mis-targeted arguments surface asTypeError. Backend-specific open options (e.g.page_size) are not accepted here; useopen_archivefor those.
- Returns:
The deserialized object.
- Return type:
- Raises:
ValueError – Raised by
backend_for_pathif the file extension is not recognized, bybackend_for_streamif a stream’s leading bytes are not recognized, or bybackend_for_nameifformatis not a known backend name.ArchiveReadError – Raised when the file’s
schema_nameis not registered, or propagated from the model’smin_read_versioncheck onmodel_validate*.TypeError – Raised when
clsis given and the file’s schema or the deserialized object is not compatible with it.