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:
GeneralizedImageA 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 aprojectionis passed separately.- mask
A bitmask image that annotates the main image plane. Must have the same bounding box as
imageif provided. Any attached projection is replaced (possibly byNone).- variance
The per-pixel uncertainty of the main image as an image of variance values. Must have the same bounding box as
imageif provided, and its units must be the square ofimage.unitorNone. Values default to1.0. Any attached projection is replaced (possibly byNone).- mask_schema
Schema for the mask plane. Must be provided if and only if
maskis 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
A proxy object for slicing a generalized image using absolute pixel coordinates.
An Astropy WCS for this image's pixel array.
The bounding box shared by all three image planes (
Box).The butler dataset reference for this image (
lsst.daf.butler.SerializedDatasetRef|None).The butler inputs and ID of the task quantum that produced this dataset (
lsst.daf.butler.DatasetProvenance|None)An Astropy FITS WCS for this image's pixel array.
The main image plane (
Image).A proxy object for slicing a generalized image using "local" or "array" pixel coordinates.
The mask plane (
Mask).Arbitrary flexible metadata associated with the image (
dict).General information about the associated observation in standard form.
The projection that maps the pixel grid to the sky (
Projection|None).The units of the image plane (
astropy.units.Unit|None).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.MaskedImageinstance.read_fits(url, *[, bbox])Read an image from a FITS file.
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.MaskedImageinstance.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 mostlsst.imagestypes (e.g.Box,Projection,PointSpreadFunction) operate exclusively in this system.Note that
astropy.wcsandnumpy.ndarrayare not aware of thebbox.startoffset that defines tihs coordinates system; uselocalslicing 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), notbbox.start, as is the case forprojection.This object satisfies the
astropy.wcs.wcsapi.BaseHighLevelWCSandastropy.wcs.wcsapi.BaseLowLevelWCSinterfaces, but it is not anastropy.wcs.WCS(usefits_wcsfor that).
- 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), notbbox.start, as is the case forprojection.This may be an approximation or absent if
projectionis not naturally representable as a FITS WCS.
- 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 byastropy.wcsobjects. 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.imagestypes (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
- 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).
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.MaskedImageinstance.Parameters#
- legacy
An
lsst.afw.image.MaskedImageinstance 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 theMaskedImageis 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
Noneand the HDU containing the image plane has a FITS WCS, attach aProjectionto the returned masked image by converting that WCS. Whencomponentis 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.MaskedImageinstance.Parameters#
- copy
If
True, always copy the image and variance pixel data. IfFalse, return a view, and raiseTypeErrorif the pixel data is read-only (this is not supported by afw). IfNone, 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
imageplane.- mask_compression
Compression options for the
maskplane.- variance_compression
Compression options for the
varianceplane.- compression_seed
A FITS tile compression seed to use whenever the configured compression seed is
Noneor (for backwards compatibility)0. This value is then incremented every time it is used.