LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
_exposureContinued.py
Go to the documentation of this file.
1# This file is part of afw.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
21
22__all__ = ["Exposure"]
23
24import numpy as np
25
26from lsst.utils import TemplateMeta
27from lsst.utils.deprecated import deprecate_pybind11
28
29from ..image._slicing import supportSlicing
30from ..image._disableArithmetic import disableImageArithmetic
31from ..image._fitsIoWithOptions import imageReadFitsWithOptions, exposureWriteFitsWithOptions
32from ._exposure import ExposureI, ExposureF, ExposureD, ExposureU, ExposureL
33from .exposureUtils import bbox_to_convex_polygon, bbox_contains_sky_coords
34
35
36class Exposure(metaclass=TemplateMeta):
37
38 def _set(self, index, value, origin):
39 """Set the pixel at the given index to a triple (value, mask, variance).
40
41 Parameters
42 ----------
43 index : `geom.Point2I`
44 Position of the pixel to assign to.
45 value : `tuple`
46 A tuple of (value, mask, variance) scalars.
47 origin : `ImageOrigin`
48 Coordinate system of ``index`` (`PARENT` or `LOCAL`).
49 """
50 self.maskedImage._set(index, value=value, origin=origin)
51
52 def _get(self, index, origin):
53 """Return a triple (value, mask, variance) at the given index.
54
55 Parameters
56 ----------
57 index : `geom.Point2I`
58 Position of the pixel to assign to.
59 origin : `ImageOrigin`
60 Coordinate system of ``index`` (`PARENT` or `LOCAL`).
61 """
62 return self.maskedImage._get(index, origin=origin)
63
64 def __reduce__(self):
65 from lsst.afw.fits import reduceToFits
66 return reduceToFits(self)
67
68 def convertF(self):
69 return ExposureF(self, deep=True)
70
71 def convertD(self):
72 return ExposureD(self, deep=True)
73
74 def getImage(self):
75 return self.maskedImage.image
76
77 def setImage(self, image):
78 self.maskedImage.image = image
79
80 image = property(getImage, setImage)
81
82 def getMask(self):
83 return self.maskedImage.mask
84
85 def setMask(self, mask):
86 self.maskedImage.mask = mask
87
88 mask = property(getMask, setMask)
89
90 def getVariance(self):
91 return self.maskedImage.variance
92
93 def setVariance(self, variance):
94 self.maskedImage.variance = variance
95
96 variance = property(getVariance, setVariance)
97
98 def getConvexPolygon(self, padding=10):
99 """Get the convex polygon associated with the bounding box corners.
100
101 The returned polygon has additional padding to ensure that the
102 bounding box is entirely contained within it. To ensure a set
103 of coordinates are entirely contained within an exposure, run
104 ``exposure.containsSkyCoords()``. The default padding
105 size was chosen to be sufficient for the most warped detectors at
106 the edges of the HyperSuprimeCam focal plane.
107
108 Parameters
109 ----------
110 padding : `int`
111 Pixel padding to ensure that bounding box is entirely contained
112 within the resulting polygon.
113
114 Returns
115 -------
116 convexPolygon : `lsst.sphgeom.ConvexPolygon`
117 Returns `None` if exposure does not have a valid WCS.
118 """
119 if self.wcs is None:
120 return None
121
122 return bbox_to_convex_polygon(self.getBBox(), self.wcs, padding=padding)
123
124 convex_polygon = property(getConvexPolygon)
125
126 def containsSkyCoords(self, ra, dec, padding=10):
127 """Check if a set of sky positions is in the pixel bounding box.
128
129 The default padding size was chosen to be sufficient for the
130 most warped detectors at the edges of the HyperSuprimeCam focal plane.
131
132 Parameters
133 ----------
134 ra : `astropy.Quantity`, (N,)
135 Array of Right Ascension, angular units.
136 dec : `astropy.Quantity`, (N,)
137 Array of Declination, angular units.
138 padding : `int`, optional
139 Pixel padding to ensure that bounding box is entirely contained
140 within the sky polygon (see ``getConvexPolygon()``).
141
142 Returns
143 -------
144 contained : `np.ndarray`, (N,)
145 Boolean array indicating which points are contained in the
146 bounding box.
147
148 Raises
149 ------
150 ValueError if exposure does not have a valid wcs.
151 """
152 if self.wcs is None:
153 raise ValueError("Exposure does not have a valid WCS.")
154
156 self.getBBox(),
157 self.wcs,
158 ra,
159 dec,
160 padding=padding)
161
162 readFitsWithOptions = classmethod(imageReadFitsWithOptions)
163
164 writeFitsWithOptions = exposureWriteFitsWithOptions
165
166
167Exposure.register(np.int32, ExposureI)
168Exposure.register(np.float32, ExposureF)
169Exposure.register(np.float64, ExposureD)
170Exposure.register(np.uint16, ExposureU)
171Exposure.register(np.uint64, ExposureL)
172Exposure.alias("I", ExposureI)
173Exposure.alias("F", ExposureF)
174Exposure.alias("D", ExposureD)
175Exposure.alias("U", ExposureU)
176Exposure.alias("L", ExposureL)
177
178for cls in set(Exposure.values()):
179 supportSlicing(cls)
181 cls.getFilterLabel = deprecate_pybind11(
182 cls.getFilterLabel,
183 reason="Replaced by getFilter. Will be removed after v24.",
184 version="v24.0")
185 cls.setFilterLabel = deprecate_pybind11(
186 cls.setFilterLabel,
187 reason="Replaced by setFilter. Will be removed after v24.",
188 version="v24.0")
189 # Can't attach deprecation warning to filterLabel property.
ConvexPolygon is a closed convex polygon on the unit sphere.
Definition: ConvexPolygon.h:57
daf::base::PropertySet * set
Definition: fits.cc:912
def bbox_contains_sky_coords(bbox, wcs, ra, dec, padding=10)
def bbox_to_convex_polygon(bbox, wcs, padding=10)
afw::image::Exposure< float > ExposureF
Definition: VeresModel.cc:36