MaskedImage#

class lsst.images.MaskedImage(image: Image, *, mask: Mask | None = None, variance: Image | None = None, mask_schema: MaskSchema | None = None, projection: Projection | None = None, obs_info: ObservationInfo | None = None, metadata: dict[str, MetadataValue] | None = None)#

Bases: GeneralizedImage

A multi-plane image with data (image), mask, and variance planes.

Parameters#

image

The main image plane. If this has a Projection, it will be used for all planes unless a projection is passed separately.

mask

A bitmask image that annotates the main image plane. Must have the same bounding box as image if provided. Any attached projection is replaced (possibly by None).

variance

The per-pixel uncertainty of the main image as an image of variance values. Must have the same bounding box as image if provided, and its units must be the square of image.unit or None. Values default to 1.0. Any attached projection is replaced (possibly by None).

mask_schema

Schema for the mask plane. Must be provided if and only if mask is not provided.

projection

Projection that maps the pixel grid to the sky.

obs_info

General information about the associated observation in standardized form.

metadata

Arbitrary flexible metadata to associate with the image.

Attributes Summary

absolute

A proxy object for slicing a generalized image using absolute pixel coordinates.

astropy_wcs

An Astropy WCS for this image's pixel array.

bbox

The bounding box shared by all three image planes (Box).

butler_dataset

The butler dataset reference for this image (lsst.daf.butler.SerializedDatasetRef | None).

butler_provenance

The butler inputs and ID of the task quantum that produced this dataset (lsst.daf.butler.DatasetProvenance | None)

fits_wcs

An Astropy FITS WCS for this image's pixel array.

image

The main image plane (Image).

local

A proxy object for slicing a generalized image using "local" or "array" pixel coordinates.

mask

The mask plane (Mask).

metadata

Arbitrary flexible metadata associated with the image (dict).

obs_info

General information about the associated observation in standard form.

projection

The projection that maps the pixel grid to the sky (Projection | None).

unit

The units of the image plane (astropy.units.Unit | None).

variance

The variance plane (Image).

Methods Summary

copy()

Deep-copy the masked image and metadata.

deserialize(model, archive, *[, bbox])

Deserialize an image from an input archive.

from_legacy(legacy, *[, unit, plane_map])

Convert from an lsst.afw.image.MaskedImage instance.

read_fits(url, *[, bbox])

Read an image from a FITS file.

read_legacy()

Read a FITS file written by lsst.afw.image.MaskedImage.writeFits.

serialize(archive)

Serialize the masked image to an output archive.

to_legacy(*[, copy, plane_map])

Convert to an lsst.afw.image.MaskedImage instance.

write_fits(filename, *[, image_compression, ...])

Write the image to a FITS file.

Attributes Documentation

absolute#

A proxy object for slicing a generalized image using absolute pixel coordinates.

Notes#

In this convention, the first row and column of the pixel grid is bbox.start. A subimage and its parent image share the same absolute pixel coordinate system, and most lsst.images types (e.g. Box, Projection, PointSpreadFunction) operate exclusively in this system.

Note that astropy.wcs and numpy.ndarray are not aware of the bbox.start offset that defines tihs coordinates system; use local slicing for indices obtained from those.

See Also#

lsst.images.BoxSliceFactory lsst.images.IntervalSliceFactory

astropy_wcs#

An Astropy WCS for this image’s pixel array.

Notes#

As expected for Astropy WCS objects, this defines pixel coordinates such that the first row and column in any associated arrays are (0, 0), not bbox.start, as is the case for projection.

This object satisfies the astropy.wcs.wcsapi.BaseHighLevelWCS and astropy.wcs.wcsapi.BaseLowLevelWCS interfaces, but it is not an astropy.wcs.WCS (use fits_wcs for that).

bbox#

The bounding box shared by all three image planes (Box).

butler_dataset#

The butler dataset reference for this image (lsst.daf.butler.SerializedDatasetRef | None).

butler_provenance#

The butler inputs and ID of the task quantum that produced this dataset (lsst.daf.butler.DatasetProvenance | None)

fits_wcs#

An Astropy FITS WCS for this image’s pixel array.

Notes#

As expected for Astropy WCS objects, this defines pixel coordinates such that the first row and column in any associated arrays are (0, 0), not bbox.start, as is the case for projection.

This may be an approximation or absent if projection is not naturally representable as a FITS WCS.

image#

The main image plane (Image).

local#

A proxy object for slicing a generalized image using “local” or “array” pixel coordinates.

Notes#

In this convention, the first row and column of the pixel grid is always at (0, 0). This is also the convention used by astropy.wcs objects. When a subimage is created from a parent image, its “local” coordinate system is offset from the coordinate systems of the parent image.

Note that most lsst.images types (e.g. Box, Projection, PointSpreadFunction) operate instead in “absolute” coordinates, which is shared by subimage and their parents.

See Also#

lsst.images.BoxSliceFactory lsst.images.IntervalSliceFactory

mask#

The mask plane (Mask).

metadata#

Arbitrary flexible metadata associated with the image (dict).

Notes#

Metadata is shared with subimages and other views. It can be disconnected by reassigning to a copy explicitly:

image.metadata = image.metadata.copy()

obs_info#

General information about the associated observation in standard form. (ObservationInfo | None).

projection#

The projection that maps the pixel grid to the sky (Projection | None).

unit#

The units of the image plane (astropy.units.Unit | None).

variance#

The variance plane (Image).

Methods Documentation

copy() MaskedImage#

Deep-copy the masked image and metadata.

static deserialize(model: MaskedImageSerializationModel[Any], archive: InputArchive[Any], *, bbox: Box | None = None) MaskedImage#

Deserialize an image from an input archive.

Parameters#

model

A Pydantic model representation of the image, holding references to data stored in the archive.

archive

Archive to read from.

bbox

Bounding box of a subimage to read instead.

static from_legacy(legacy: Any, *, unit: Unit | None = None, plane_map: Mapping[str, MaskPlane] | None = None) MaskedImage#

Convert from an lsst.afw.image.MaskedImage instance.

Parameters#

legacy

An lsst.afw.image.MaskedImage instance that will share image and variance (but not mask) pixel data with the returned object.

unit

Units of the image.

plane_map

A mapping from legacy mask plane name to the new plane name and description.

classmethod read_fits(url: str | ParseResult | ResourcePath | Path, *, bbox: Box | None = None) MaskedImage#

Read an image from a FITS file.

Parameters#

url

URL of the file to read; may be any type supported by lsst.resources.ResourcePath.

bbox

Bounding box of a subimage to read instead.

static read_legacy(uri: str | ParseResult | ResourcePath | Path, *, preserve_quantization: bool = False, component: Literal['image'], fits_wcs_frame: Frame | None = None) Image#
static read_legacy(uri: str | ParseResult | ResourcePath | Path, *, plane_map: Mapping[str, MaskPlane] | None = None, component: Literal['mask'], fits_wcs_frame: Frame | None = None) Mask
static read_legacy(uri: str | ParseResult | ResourcePath | Path, *, preserve_quantization: bool = False, component: Literal['variance'], fits_wcs_frame: Frame | None = None) Image
static read_legacy(uri: str | ParseResult | ResourcePath | Path, *, preserve_quantization: bool = False, plane_map: Mapping[str, MaskPlane] | None = None, component: None = None, fits_wcs_frame: Frame | None = None) MaskedImage

Read a FITS file written by lsst.afw.image.MaskedImage.writeFits.

Parameters#

uri

URI or file name.

preserve_quantization

If True, ensure that writing the masked image back out again will exactly preserve quantization-compressed pixel values. This causes the image and variance plane arrays to be marked as read-only and stores the original binary table data for those planes in memory. If the MaskedImage is copied, the precompressed pixel values are not transferred to the copy.

plane_map

A mapping from legacy mask plane name to the new plane name and description.

component

A component to read instead of the full image.

fits_wcs_frame

If not None and the HDU containing the image plane has a FITS WCS, attach a Projection to the returned masked image by converting that WCS. When component is one of "image", "mask", or "variance", a FITS WCS from the component HDU is used instead (all three should have the same WCS).

serialize(archive: OutputArchive[Any]) MaskedImageSerializationModel#

Serialize the masked image to an output archive.

Parameters#

archive

Archive to write to.

to_legacy(*, copy: bool | None = None, plane_map: Mapping[str, MaskPlane] | None = None) Any#

Convert to an lsst.afw.image.MaskedImage instance.

Parameters#

copy

If True, always copy the image and variance pixel data. If False, return a view, and raise TypeError if the pixel data is read-only (this is not supported by afw). If None, onyl if the pixel data is read-only. Mask pixel data is always copied.

plane_map

A mapping from legacy mask plane name to the new plane name and description.

write_fits(filename: str, *, image_compression: ~lsst.images.fits._common.FitsCompressionOptions | None = FitsCompressionOptions(algorithm=<FitsCompressionAlgorithm.GZIP_2: 'GZIP_2'>, tile_shape=None, quantization=None), mask_compression: ~lsst.images.fits._common.FitsCompressionOptions | None = FitsCompressionOptions(algorithm=<FitsCompressionAlgorithm.GZIP_2: 'GZIP_2'>, tile_shape=None, quantization=None), variance_compression: ~lsst.images.fits._common.FitsCompressionOptions | None = FitsCompressionOptions(algorithm=<FitsCompressionAlgorithm.GZIP_2: 'GZIP_2'>, tile_shape=None, quantization=None), compression_seed: int | None = None) None#

Write the image to a FITS file.

Parameters#

filename

Name of the file to write to. Must be a local file.

image_compression

Compression options for the image plane.

mask_compression

Compression options for the mask plane.

variance_compression

Compression options for the variance plane.

compression_seed

A FITS tile compression seed to use whenever the configured compression seed is None or (for backwards compatibility) 0. This value is then incremented every time it is used.