open_archive#
- lsst.images.serialization.open_archive(path: ResourcePathExpression | IO[bytes], cls: type[T], *, format: str | None = None, partial: bool = True, **backend_kwargs: Any) AbstractContextManager[Reader[T]]#
- lsst.images.serialization.open_archive(path: ResourcePathExpression | IO[bytes], cls: None = None, *, format: str | None = None, partial: bool = True, **backend_kwargs: Any) AbstractContextManager[Reader[Any]]
Open an
lsst.imagesfile for incremental, component-wise reads.Dispatches to the appropriate backend by file extension (or, for stream input, by the leading bytes), resolves the registered in-memory type from the file’s schema, and returns a
Readercontext manager.A path with a
.gz/.zstcompression suffix is stream-decompressed into an anonymous temporary file first (in bounded-memory chunks, since compressed data has no random access;partialis ignored for it). zstd requires Python >= 3.14 or thezstandardpackage. Stream input must already be decompressed: whoever produced the stream knows how it was compressed.Parameters#
- path
File to read; convertible to
lsst.resources.ResourcePath, or a seekable binary stream containing the file’s content.- cls
Optional expected in-memory type. When given,
open_archivevalidates that the file’s schema resolves to a subclass ofcls(raisingTypeErrorotherwise) and the returnedReaderis typed accordingly, soReader.readneeds no cast.- format
Optional backend name (
"fits","ndf", or"json") forcing the backend, instead of dispatching on the path’s extension or the stream’s leading bytes.- partial
Forwarded to the backend
open_tree; defaults toTrue(a reader is for incremental access). A no-op for the JSON and NDF backends and for stream input.- **backend_kwargs
Backend-specific open options (e.g.
page_sizefor FITS).
Raises#
- ValueError
If the file extension or the stream’s leading bytes are not recognized, or
formatis not a known backend name.- ArchiveReadError
If the file’s schema is not registered.
- TypeError
If
clsis given and the file’s schema resolves to an incompatible type.