MaskedImage#
- class lsst.images.MaskedImage(image: Image, *, mask: Mask | None = None, variance: Image | None = None, mask_schema: MaskSchema | None = None, sky_projection: SkyProjection | 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
SkyProjection, it will be used for all planes unless asky_projectionis passed separately.- mask
A bitmask image that annotates the main image plane. Must have the same bounding box as
imageif provided. Any attachedsky_projectionis 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 attachedsky_projectionis replaced (possibly byNone).- mask_schema
Schema for the mask plane. Must be provided if and only if
maskis not provided.- sky_projection
Projection that maps the pixel grid to the sky.
- 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).The projection that maps the pixel grid to the sky (
SkyProjection|None).The units of the image plane (
astropy.units.Unit|None).The variance plane (
Image).The coordinates of the first pixel in the array (
YX[int]).Methods Summary
copy()Deep-copy the masked image and metadata.
from_hdu_list(hdu_list, *[, fits_wcs_frame])Reconstruct a
MaskedImagefrom a cut-downlsst.imagesFITS HDU list.from_legacy(legacy, *[, unit, plane_map])Convert from an
lsst.afw.image.MaskedImageinstance.read(path, **kwargs)Read an instance of this class from a file.
read_legacy(uri, *[, preserve_quantization, ...])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(path, **kwargs)Write this object to a 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,SkyProjection,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 forsky_projection.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 forsky_projection.This may be an approximation or absent if
sky_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,SkyProjection,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).Assigning a new
Mask(for example one returned byadd_planes) replaces the mask plane. The new mask must share this image’s bounding box; its sky projection is replaced with the image’s.
- 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()
- sky_projection#
The projection that maps the pixel grid to the sky (
SkyProjection|None).
- unit#
The units of the image plane (
astropy.units.Unit|None).
- yx0#
The coordinates of the first pixel in the array (
YX[int]).
Methods Documentation
- copy() MaskedImage#
Deep-copy the masked image and metadata.
- classmethod from_hdu_list(hdu_list: HDUList, *, fits_wcs_frame: Frame | None = GeneralFrame(unit=Unit('pix'), frame_type='GENERAL')) MaskedImage#
Reconstruct a
MaskedImagefrom a cut-downlsst.imagesFITS HDU list.This assumes the
PRIMARY,IMAGE,MASK, andVARIANCEHDUs written for the masked-image cut-outs produced bydax_images_cutout: a reallsst.imagesfile with its JSON-tree, index, and any nested-archive HDUs dropped. The reconstructed object can be re-serialized as a normallsst.imagesfile (with schema and index) so it can be read with the fulllsst.imagesinfrastructure.Parameters#
- hdu_list
HDU list with
IMAGE,MASK, andVARIANCEextensions and a primary HDU.- fits_wcs_frame
Pixel-grid
Framefor theSkyProjectionreconstructed from the FITS WCS. Defaults to a plain pixel frame; passNoneto skip attaching a projection.
Returns#
MaskedImageThe reconstructed masked image.
Raises#
- ValueError
Raised if the
MASKHDU has neitherMSKNnorMP_mask- plane cards, since the mask schema cannot then be reconstructed, or ifhdu_listcontains more than oneMASKHDU (multipleMASKextensions, distinguished byEXTVER, are not handled here and would otherwise be silently dropped).
Notes#
Both mask-plane conventions are supported: the self-describing
MSKN/MSKM/MSKDcards written bylsst.images, and the legacylsst.afw.imageMP_*cards (as produced bydax_images_cutoutfrom afw-written images). Legacy masks are mapped to a new schema with the same plane-guessing used byread_legacy.Unlike
read_legacy, the legacyMP_*mask-plane cards are kept (not stripped) for backwards compatibility, since this path reconstructs a file that may still be read by legacy tooling. They are re-indexed to the reshuffled schema so eachMP_bit matches the plane’s position in the writtenMSKNlayout.The headers of the HDUs in
hdu_listare modified in place: the WCS and mask-schema cards interpreted here are stripped from the caller’s headers.
- static from_legacy(legacy: LegacyMaskedImage, *, unit: astropy.units.UnitBase | 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. If not provided, the right legacy mask plane will be guessed, but this can depend on which mask planes the legacy mask actually has set.
- classmethod read(path: str | ParseResult | ResourcePath | Path, **kwargs: Any) Self#
Read an instance of this class from a file.
A thin convenience wrapper around
lsst.images.serialization.readthat fixes the expected in-memory type to this class. The container format is inferred frompath’s extension.Parameters#
- path
File to read; convertible to
lsst.resources.ResourcePath.- **kwargs
Forwarded to
read(e.g.bboxto read a subimage).
- static read_legacy(uri: str | ParseResult | ResourcePath | Path, *, preserve_quantization: bool = False, plane_map: Mapping[str, MaskPlane] | None = None, component: Literal['image', 'mask', 'variance'] | None = None, fits_wcs_frame: Frame | None = None) Any#
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. If not provided, the right legacy mask plane will be guessed, but this can depend on which mask planes the legacy mask actually has set.
- 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 aSkyProjectionto 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) LegacyMaskedImage#
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, only copy 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(path: str, **kwargs: Any) None#
Write this object to a file.
A thin convenience wrapper around
lsst.images.serialization.write. The container format is chosen frompath’s extension.Parameters#