CellCoadd#
- class lsst.images.cells.CellCoadd(image, *, mask=None, variance=None, mask_fractions=None, noise_realizations=(), mask_schema=None, sky_projection=None, band=None, psf, aperture_corrections=None, patch=None, provenance=None, backgrounds=None)#
Bases:
MaskedImageA coadd comprised of cells on a regular grid.
- Parameters:
image (
Image) – The main image plane. If this has aSkyProjection, it will be used for all planes unless asky_projectionis passed separately.mask (
Mask|None, default:None) – A bitmask image that annotates the main image plane. Must have the same bounding box asimageif provided. Any attachedsky_projectionis replaced (possibly byNone).variance (
Image|None, default:None) – The per-pixel uncertainty of the main image as an image of variance values. Must have the same bounding box asimageif provided, and its units must be the square ofimage.unitorNone. Values default to1.0. Any attachedsky_projectionis replaced (possibly byNone).mask_fractions (
Mapping[str,Image] |None, default:None) – A mapping from an input-image mask plane name to an image of the weights sums of that plane.noise_realizations (
Sequence[Image], default:()) – A sequence of images with Monte Carlo realizations of the noise in the coadd.mask_schema (
MaskSchema|None, default:None) – Schema for the mask plane. Must be provided if and only ifmaskis not provided.sky_projection (
Optional[SkyProjection[TractFrame]], default:None) – Projection that maps the pixel grid to the sky. Can only beNoneif a projection is already attached toimage.psf (
CellPointSpreadFunction) – Effective point-spread function for the coadd. The missing cells reported bypsf.boundsare assumed to apply to all image data for that cell as well (i.e. there is a PSF for a cell if and only if there is image data for that cell).aperture_corrections (
Mapping[str,CellField] |None, default:None) – Aperture corrections for different photometry algorithms.patch (
PatchDefinition|None, default:None) – Identifiers and geometry of the full patch, if the image is confined to a single patch. When present, the cell grid of the PSF and provenance (if provideD) must be the full patch grid, even if its bounds select a subset of that area.provenance (
CoaddProvenance|None, default:None) – Information about the images that went into the coadd.backgrounds (
BackgroundMap|None, default:None) – Background models associated with this image.
Attributes Summary
A proxy object for slicing a generalized image using absolute pixel coordinates.
Aperture corrections for different photometry algorithms (
dict[str,CellField]).An Astropy WCS for this image's pixel array.
A mapping of backgrounds associated with this image (
BackgroundMap).The bounding box shared by all three image planes (
Box).The grid of cells that overlap this coadd and a set of missing cells (
CellGridBounds).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 grid of cells that overlap this coadd (
CellGrid).The main image plane (
Image).A proxy object for slicing a generalized image using "local" or "array" pixel coordinates.
The mask plane (
Mask).A mapping from an input-image mask plane name to an image of the weights sums of that plane (
Mapping[str,Image]).Arbitrary flexible metadata associated with the image (
dict).A sequence of images with Monte Carlo realizations of the noise in the coadd (
Sequence[Image]).Identifiers and geometry of the full patch, if the image is confined to a single patch (
PatchDefinition).Information about the images that went into the coadd (
CoaddProvenanceorNone).Effective point-spread function for the coadd (
CellPointSpreadFunction).The projection that maps the pixel grid to the sky (
SkyProjection[TractFrame]).Name of the skymap (
str).ID of the tract (
int).The units of the image plane (
astropy.units.Unit).The variance plane (
Image).The coordinates of the first pixel in the array (
YX[int]).Methods Summary
apply_background(name)Subtract the background with the given name, modifying the image in place.
bbox_from_sky_circle(center, radius[, clip])Calculate the bounding box on this image corresponding to a circular region on the sky.
copy()Deep-copy the coadd.
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.from_legacy_cell_coadd(legacy, *[, ...])Convert from a
lsst.cell_coadds.MultipleCellCoaddinstance.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 image to an output archive.
to_legacy([copy, plane_map])Convert to a
lsst.afw.image.Exposureinstance.to_legacy_cell_coadd([copy, plane_map])Convert to a
lsst.cell_coadds.MultipleCellCoaddinstance.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.
- aperture_corrections#
Aperture corrections for different photometry algorithms (
dict[str,CellField]).
- 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).
- backgrounds#
A mapping of backgrounds associated with this image (
BackgroundMap).
- bounds#
The grid of cells that overlap this coadd and a set of missing cells (
CellGridBounds).
- 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.
- 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.
- mask_fractions#
A mapping from an input-image mask plane name to an image of the weights sums of that plane (
Mapping[str,Image]).
- 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()
- noise_realizations#
A sequence of images with Monte Carlo realizations of the noise in the coadd (
Sequence[Image]).
- patch#
Identifiers and geometry of the full patch, if the image is confined to a single patch (
PatchDefinition).
- provenance#
Information about the images that went into the coadd (
CoaddProvenanceorNone).
- psf#
Effective point-spread function for the coadd (
CellPointSpreadFunction).
- sky_projection#
The projection that maps the pixel grid to the sky (
SkyProjection[TractFrame]).
- unit#
The units of the image plane (
astropy.units.Unit).
Methods Documentation
- apply_background(name)#
Subtract the background with the given name, modifying the image in place.
If
nameisNone, restore the original background.
- bbox_from_sky_circle(center, radius, clip=False)#
Calculate the bounding box on this image corresponding to a circular region on the sky.
- Parameters:
center (
SkyCoord) – The center of the circle, as a scalarastropy.coordinates.SkyCoordin any frame.radius (
Angle) – Radius of the circle, as a scalarastropy.coordinates.Angle.clip (
bool, default:False) – IfTrue(Falseis default), clip pixel bounds when the circle extends outside the image. IfFalsean exception is raised if any part of the circle is off the image.
- Returns:
Bounding box enclosing the circle in this image’s pixel coordinates.
- Return type:
- Raises:
NotContainedError – Raised if the requested region is entirely off the image or if any part of the region is off the image and clipping is
False.ValueError – Raised if
centerorradiusis not scalar, or if this image has no sky projection.
- classmethod from_hdu_list(hdu_list, *, fits_wcs_frame=GeneralFrame(unit=Unit('pix'), frame_type='GENERAL'))#
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 (
HDUList) – HDU list withIMAGE,MASK, andVARIANCEextensions and a primary HDU.fits_wcs_frame (
Frame|None, default:GeneralFrame(unit=Unit("pix"), frame_type='GENERAL')) – Pixel-gridFramefor theSkyProjectionreconstructed from the FITS WCS. Defaults to a plain pixel frame; passNoneto skip attaching a projection.
- Returns:
The reconstructed masked image.
- Return type:
- 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, *, unit=None, plane_map=None, sky_projection=None)#
Convert from an
lsst.afw.image.MaskedImageinstance.- Parameters:
legacy (
TypeAliasType) – Anlsst.afw.image.MaskedImageinstance that will share image and variance (but not mask) pixel data with the returned object.plane_map (
Mapping[str,MaskPlane] |None, default:None) – 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.sky_projection (
Optional[SkyProjection[Any]], default:None) – Projection from pixels to xky.
- Return type:
- static from_legacy_cell_coadd(legacy, *, plane_map=None, tract_info, bbox=None)#
Convert from a
lsst.cell_coadds.MultipleCellCoaddinstance.- Parameters:
legacy (
TypeAliasType) – Alsst.cell_coadds.MultipleCellCoaddinstance to convert.plane_map (
Mapping[str,MaskPlane] |None, default:None) – A mapping from legacy mask plane name to the new plane name and description.tract_info (
TypeAliasType) – Information about the full tract.bbox (
Box|None, default:None) – Bounding box of the image. The default is to include just the bounding box of the valid cells, which may not cover a full patch.
- Return type:
- classmethod read(path, **kwargs)#
Read an instance of this class from a file.
A thin convenience wrapper around
lsst.images.serialization.read_archivethat fixes the expected in-memory type to this class. The container format is inferred frompath’s extension.- Parameters:
path (
str|ParseResult|ResourcePath|Path) – File to read; convertible tolsst.resources.ResourcePath.**kwargs (
Any) – Forwarded toread_archive(e.g.bboxto read a subimage).
- Return type:
Self
- static read_legacy(uri, *, preserve_quantization=False, plane_map=None, component=None, fits_wcs_frame=None)#
Read a FITS file written by
lsst.afw.image.MaskedImage.writeFits.- Parameters:
uri (
str|ParseResult|ResourcePath|Path) – URI or file name.preserve_quantization (
bool, default:False) – IfTrue, 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 (
Mapping[str,MaskPlane] |None, default:None) – 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 (
Optional[Literal['image','mask','variance']], default:None) – A component to read instead of the full image.fits_wcs_frame (
Frame|None, default:None) – If notNoneand 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).
- Return type:
- serialize(archive)#
Serialize the image to an output archive.
- Parameters:
archive (
OutputArchive[Any]) – Archive to write to.- Return type:
- to_legacy(copy=None, plane_map=None)#
Convert to a
lsst.afw.image.Exposureinstance.- Parameters:
copy (
bool|None, default:None) – IfTrue, 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 (
Mapping[str,MaskPlane] |None, default:None) – A mapping from legacy mask plane name to the new plane name and description.
- Returns:
A legacy representation of the coadd. This will have its
wcs,psf,filter,photoCalib, andmetadatacomponents set. TheapCorrMapcomponent is not set, because there is no truelsst.afw.math.BoundedFieldrepresentation for cell-coadd aperture corrections, and thecoaddInputscomponent is not set because that data structure cannot fully capture cell-coadd provenance.- Return type:
lsst.afw.image.Exposure
Notes
This method requires the
provenanceattribute to have been populated at construction.
- to_legacy_cell_coadd(copy=None, plane_map=None)#
Convert to a
lsst.cell_coadds.MultipleCellCoaddinstance.- Parameters:
copy (
bool|None, default:None) – IfTrue, 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 (
Mapping[str,MaskPlane] |None, default:None) – A mapping from legacy mask plane name to the new plane name and description.
- Return type:
TypeAliasType
- write(path, **kwargs)#
Write this object to a file.
A thin convenience wrapper around
lsst.images.serialization.write_archive. The container format is chosen frompath’s extension.- Parameters:
path (
str) – Destination file path. Must not already exist.**kwargs (
Any) – Forwarded towrite_archive(e.g.compression_optionsandcompression_seedfor FITS).
- Return type: