RoundtripFits#

class lsst.images.tests.RoundtripFits(tc: TestCase, original: T, storage_class: str | None = None)#

Bases: Generic

A context manager for testing FITS-based serialization.

Parameters#

tc

A test case object to used for internal checks.

original

The object to serialize.

storage_class

A butler storage class name to use. If not provided (or lsst.daf.butler cannot be imported), the roundtrip will just use a direct write to a temporary file.

Notes#

When entered, this context manager writes the object and reads it back in to the result attribute. When exited, any temporary files or directories are deleted, but the result attribute is still usable. In between the inspect and get methods can be used to perform other tests.

This helper internally tests that butler provenance and metadata are saved with any GeneralizedImage object.

Attributes Summary

filename

The name of the file the object was written to.

serialized

The serialization model for this object (serialization.ArchiveTree).

Methods Summary

get([component, storageClass])

Perform a partial read.

inspect()

Open the FITS file with Astropy.

Attributes Documentation

filename#

The name of the file the object was written to.

serialized#

The serialization model for this object (serialization.ArchiveTree).

Methods Documentation

get(component: str | None = None, storageClass: str | None = None, **kwargs: Any) Any#

Perform a partial read.

Parameters#

component

Component to read instead of the main object. This requires the roundtrip to use a butler, raising unittest.SkipTest otherwise; this generally means these tests should be nested within a subTest context.

storageClass

Override storage class name to affect the type returned by the get. Only used if a butler is active.

**kwargs

Keyword arguments either passed directly to fits.read or used as parameters for a get.

Return#

object

Result of the partial read.

inspect() HDUList#

Open the FITS file with Astropy.