Image#
- final class lsst.images.Image(array_or_fill: ndarray | int | float = 0, /, *, bbox: Box | None = None, yx0: Sequence[int] | None = None, shape: Sequence[int] | None = None, dtype: type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None = None, unit: UnitBase | None = None, sky_projection: SkyProjection[Any] | None = None, metadata: dict[str, MetadataValue] | None = None)#
Bases:
GeneralizedImageA 2-d array that may be augmented with units and a nonzero origin.
Parameters#
- array_or_fill
Array or fill value for the image. If a fill value,
bboxorshapemust be provided.- bbox
Bounding box for the image.
- yx0
Logical coordinates of the first pixel in the array, ordered
y,x(unless anXYinstance is passed). Ignored ifbboxis provided. Defaults to zeros.- shape
Leading dimensions of the array, ordered
y,x(unless anXYinstance is passed). Only needed ifarray_or_fillis not an array andbboxis not provided. Like the bbox, this does not include the last dimension of the array.- dtype
Pixel data type override.
- unit
Units for the image’s pixel values.
- sky_projection
Projection that maps the pixel grid to the sky.
- metadata
Arbitrary flexible metadata to associate with the image.
Notes#
Indexing the
arrayattribute of anImagedoes not take into account itsyx0offset, but accessing a subimage by indexing anImagewith aBoxdoes, and thebboxof the subimage is set to match its location within the original image.Indexed assignment to a subimage requires consistency between the coordinate systems and units of both operands, but it will automatically select a subimage of the right-hand side and convert compatible units when possible. In other words:
a[box] = b
is a shortcut for
a[box].quantity = b[box].quantity
An ellipsis (
...) can be used instead of aBoxto assign to the full image.Attributes Summary
A proxy object for slicing a generalized image using absolute pixel coordinates.
The low-level array (
numpy.ndarray).An Astropy WCS for this image's pixel array.
Bounding box for the image (
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.
A proxy object for slicing a generalized image using "local" or "array" pixel coordinates.
Arbitrary flexible metadata associated with the image (
dict).The low-level array with units (
astropy.units.Quantity).The projection that maps this image's pixel grid to the sky (
SkyProjection|None).Units for the image's pixel values (
astropy.units.UnitorNone).The coordinates of the first pixel in the array (
YX[int]).Methods Summary
copy()Deep-copy the image and metadata.
from_legacy(legacy[, unit])Convert from an
lsst.afw.image.Imageinstance.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.Image.writeFits.serialize(archive, *[, update_header, ...])Serialize the image to an output archive.
to_legacy(*[, copy])Convert to an
lsst.afw.image.Imageinstance.view(*[, unit, sky_projection, yx0])Make a view of the image, with optional updates.
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
- array#
The low-level array (
numpy.ndarray).Assigning to this attribute modifies the existing array in place; the bounding box and underlying data pointer are never changed.
- 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
- 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()
- quantity#
The low-level array with units (
astropy.units.Quantity).Assigning to this attribute modifies the existing array in place; the bounding box and underlying data pointer are never changed.
- sky_projection#
The projection that maps this image’s pixel grid to the sky (
SkyProjection|None).Notes#
The pixel coordinates used by this projection account for the bounding box
start; they are not just array indices.
- unit#
Units for the image’s pixel values (
astropy.units.UnitorNone).
- yx0#
The coordinates of the first pixel in the array (
YX[int]).
Methods Documentation
- copy() Image#
Deep-copy the image and metadata.
Attached immutable objects (like
SkyProjectioninstances) are not copied.
- static from_legacy(legacy: LegacyImage, unit: astropy.units.UnitBase | None = None) Image#
Convert from an
lsst.afw.image.Imageinstance.Parameters#
- legacy
An
lsst.afw.image.Imageinstance that will share pixel data withthe returned object.
- unit
Units of the image.
- 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, ext: str | int = 1, fits_wcs_frame: Frame | None = None) Image#
Read a FITS file written by
lsst.afw.image.Image.writeFits.Parameters#
- uri
URI or file name.
- preserve_quantization
If
True, ensure that writing the image back out again will exactly preserve quantization-compressed pixel values. This causes the arrays to be marked as read-only and stores the original binary table data for those planes in memory. If theImageis copied, the precompressed pixel values are not transferred to the copy.- ext
Name or index of the FITS HDU to read.
- fits_wcs_frame
If not
Noneand the HDU containing the image has a FITS WCS, attach aSkyProjectionto the returned image by converting that WCS.
- serialize(archive: ~lsst.images.serialization._output_archive.OutputArchive, *, update_header: ~collections.abc.Callable[[~astropy.io.fits.header.Header], None] = <function no_header_updates>, save_projection: bool = True, add_offset_wcs: str | None = 'A', tile_shape: tuple[int, ...] | None = None, options_name: str | None = None) ImageSerializationModel[TypeVar]#
Serialize the image to an output archive.
Parameters#
- archive
Archive to write to.
- update_header
A callback that will be given the FITS header for the HDU containing this image in order to add keys to it. This callback may be provided but will not be called if the output format is not FITS.
- save_projection
If
True, save theSkyProjectionattached to the image, if there is one. This does not affect whether a FITS WCS corresponding to the projection is written (it always is, if available, and ifadd_offset_wcsis not" ").- add_offset_wcs
A FITS WCS single-character suffix to use when adding a linear WCS that maps the FITS array to the logical pixel coordinates defined by
bbox.start. Set toNoneto not write this WCS. If this is set to" ", it will prevent theSkyProjectionfrom being saved as a FITS WCS.- tile_shape
The recommended shape of each tile, if the archive will save the array in distinct tiles for faster subarray retrieval. This is a hint; archives are not required to use this value.
- options_name
Use this name to look up archive options.
- to_legacy(*, copy: bool | None = None) LegacyImage#
Convert to an
lsst.afw.image.Imageinstance.Parameters#
- copy
If
True, always copy the 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.
- view(*, unit: UnitBase | None | ellipsis = Ellipsis, sky_projection: SkyProjection | None | ellipsis = Ellipsis, yx0: Sequence[int] | ellipsis = Ellipsis) Image#
Make a view of the image, with optional updates.
- 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#