LSST Applications g0265f82a02+d6b5cd48b5,g02d81e74bb+a41d3748ce,g1470d8bcf6+6be6c9203b,g2079a07aa2+14824f138e,g212a7c68fe+a4f2ea4efa,g2305ad1205+72971fe858,g295015adf3+ab2c85acae,g2bbee38e9b+d6b5cd48b5,g337abbeb29+d6b5cd48b5,g3ddfee87b4+31b3a28dff,g487adcacf7+082e807817,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+b2918d57ae,g5a732f18d5+66d966b544,g64a986408d+a41d3748ce,g858d7b2824+a41d3748ce,g8a8a8dda67+a6fc98d2e7,g99cad8db69+7fe4acdf18,g9ddcbc5298+d4bad12328,ga1e77700b3+246acaaf9c,ga8c6da7877+84af8b3ff8,gb0e22166c9+3863383f4c,gb6a65358fc+d6b5cd48b5,gba4ed39666+9664299f35,gbb8dafda3b+d8d527deb2,gc07e1c2157+b2dbe6b631,gc120e1dc64+61440b2abb,gc28159a63d+d6b5cd48b5,gcf0d15dbbd+31b3a28dff,gdaeeff99f8+a38ce5ea23,ge6526c86ff+39927bb362,ge79ae78c31+d6b5cd48b5,gee10cc3b42+a6fc98d2e7,gf1cff7945b+a41d3748ce,v24.1.5.rc1
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask Class Reference
Inheritance diagram for lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask:

Public Member Functions

 __init__ (self, **kwargs)
 
 build_ccd_input_map (self, bbox, wcs, ccds)
 
 mask_warp_bbox (self, bbox, visit, mask, bit_mask_value)
 
 finalize_ccd_input_map_mask (self)
 

Public Attributes

 ccd_input_map
 

Static Public Attributes

 ConfigClass = HealSparseInputMapConfig
 

Protected Member Functions

 _pixels_to_radec (self, wcs, pixels)
 

Protected Attributes

 _wcs
 
 _bbox
 
 _ccds
 
 _min_bad
 
 _bits_per_visit_ccd
 
 _bits_per_visit
 
 _ccd_input_pixels
 
 _ccd_input_bad_count_map
 

Static Protected Attributes

str _DefaultName = "healSparseInputMap"
 

Detailed Description

Task for making a HealSparse input map.

Definition at line 132 of file healSparseMapping.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask.__init__ ( self,
** kwargs )

Definition at line 138 of file healSparseMapping.py.

138 def __init__(self, **kwargs):
139 pipeBase.Task.__init__(self, **kwargs)
140
141 self.ccd_input_map = None
142

Member Function Documentation

◆ _pixels_to_radec()

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._pixels_to_radec ( self,
wcs,
pixels )
protected
Convert pixels to ra/dec positions using a wcs.

Parameters
----------
wcs : `lsst.afw.geom.SkyWcs`
    WCS object.
pixels : `list` [`lsst.geom.Point2D`]
    List of pixels to convert.

Returns
-------
radec : `numpy.ndarray`
    Nx2 array of ra/dec positions associated with pixels.

Definition at line 305 of file healSparseMapping.py.

305 def _pixels_to_radec(self, wcs, pixels):
306 """Convert pixels to ra/dec positions using a wcs.
307
308 Parameters
309 ----------
310 wcs : `lsst.afw.geom.SkyWcs`
311 WCS object.
312 pixels : `list` [`lsst.geom.Point2D`]
313 List of pixels to convert.
314
315 Returns
316 -------
317 radec : `numpy.ndarray`
318 Nx2 array of ra/dec positions associated with pixels.
319 """
320 sph_pts = wcs.pixelToSky(pixels)
321 return np.array([(sph.getRa().asDegrees(), sph.getDec().asDegrees())
322 for sph in sph_pts])
323
324

◆ build_ccd_input_map()

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask.build_ccd_input_map ( self,
bbox,
wcs,
ccds )
Build a map from ccd valid polygons or bounding boxes.

Parameters
----------
bbox : `lsst.geom.Box2I`
    Bounding box for region to build input map.
wcs : `lsst.afw.geom.SkyWcs`
    WCS object for region to build input map.
ccds : `lsst.afw.table.ExposureCatalog`
    Exposure catalog with ccd data from coadd inputs.

Definition at line 143 of file healSparseMapping.py.

143 def build_ccd_input_map(self, bbox, wcs, ccds):
144 """Build a map from ccd valid polygons or bounding boxes.
145
146 Parameters
147 ----------
148 bbox : `lsst.geom.Box2I`
149 Bounding box for region to build input map.
150 wcs : `lsst.afw.geom.SkyWcs`
151 WCS object for region to build input map.
152 ccds : `lsst.afw.table.ExposureCatalog`
153 Exposure catalog with ccd data from coadd inputs.
154 """
155 with warnings.catch_warnings():
156 # Healsparse will emit a warning if nside coverage is greater than
157 # 128. In the case of generating patch input maps, and not global
158 # maps, high nside coverage works fine, so we can suppress this
159 # warning.
160 warnings.simplefilter("ignore")
161 self.ccd_input_map = hsp.HealSparseMap.make_empty(nside_coverage=self.config.nside_coverage,
162 nside_sparse=self.config.nside,
163 dtype=hsp.WIDE_MASK,
164 wide_mask_maxbits=len(ccds))
165 self._wcs = wcs
166 self._bbox = bbox
167 self._ccds = ccds
168
169 pixel_scale = wcs.getPixelScale().asArcseconds()
170 hpix_area_arcsec2 = hpg.nside_to_pixel_area(self.config.nside, degrees=True)*(3600.**2.)
171 self._min_bad = self.config.bad_mask_min_coverage*hpix_area_arcsec2/(pixel_scale**2.)
172
173 metadata = {}
174 self._bits_per_visit_ccd = {}
175 self._bits_per_visit = defaultdict(list)
176 for bit, ccd_row in enumerate(ccds):
177 metadata[f"B{bit:04d}CCD"] = ccd_row["ccd"]
178 metadata[f"B{bit:04d}VIS"] = ccd_row["visit"]
179 metadata[f"B{bit:04d}WT"] = ccd_row["weight"]
180
181 self._bits_per_visit_ccd[(ccd_row["visit"], ccd_row["ccd"])] = bit
182 self._bits_per_visit[ccd_row["visit"]].append(bit)
183
184 ccd_poly = ccd_row.getValidPolygon()
185 if ccd_poly is None:
186 ccd_poly = afwGeom.Polygon(lsst.geom.Box2D(ccd_row.getBBox()))
187 # Detectors need to be rendered with their own wcs.
188 ccd_poly_radec = self._pixels_to_radec(ccd_row.getWcs(), ccd_poly.convexHull().getVertices())
189
190 # Create a ccd healsparse polygon
191 poly = hsp.Polygon(ra=ccd_poly_radec[: -1, 0],
192 dec=ccd_poly_radec[: -1, 1],
193 value=[bit])
194 self.ccd_input_map.set_bits_pix(poly.get_pixels(nside=self.ccd_input_map.nside_sparse),
195 [bit])
196
197 # Cut down to the overall bounding box with associated wcs.
198 bbox_afw_poly = afwGeom.Polygon(lsst.geom.Box2D(bbox))
199 bbox_poly_radec = self._pixels_to_radec(self._wcs,
200 bbox_afw_poly.convexHull().getVertices())
201 bbox_poly = hsp.Polygon(ra=bbox_poly_radec[: -1, 0], dec=bbox_poly_radec[: -1, 1],
202 value=np.arange(self.ccd_input_map.wide_mask_maxbits))
203 with warnings.catch_warnings():
204 warnings.simplefilter("ignore")
205 bbox_poly_map = bbox_poly.get_map_like(self.ccd_input_map)
206 self.ccd_input_map = hsp.and_intersection([self.ccd_input_map, bbox_poly_map])
207 self.ccd_input_map.metadata = metadata
208
209 # Create a temporary map to hold the count of bad pixels in each healpix pixel
210 self._ccd_input_pixels = self.ccd_input_map.valid_pixels
211
212 dtype = [(f"v{visit}", np.int64) for visit in self._bits_per_visit.keys()]
213
214 with warnings.catch_warnings():
215 # Healsparse will emit a warning if nside coverage is greater than
216 # 128. In the case of generating patch input maps, and not global
217 # maps, high nside coverage works fine, so we can suppress this
218 # warning.
219 warnings.simplefilter("ignore")
220 self._ccd_input_bad_count_map = hsp.HealSparseMap.make_empty(
221 nside_coverage=self.config.nside_coverage,
222 nside_sparse=self.config.nside,
223 dtype=dtype,
224 primary=dtype[0][0])
225
226 # Don't set input bad map if there are no ccds which overlap the bbox.
227 if len(self._ccd_input_pixels) > 0:
228 self._ccd_input_bad_count_map[self._ccd_input_pixels] = np.zeros(1, dtype=dtype)
229
Cartesian polygons.
Definition Polygon.h:59
A floating-point coordinate rectangle geometry.
Definition Box.h:413

◆ finalize_ccd_input_map_mask()

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask.finalize_ccd_input_map_mask ( self)
Use accumulated mask information to finalize the masking of
ccd_input_map.

Raises
------
RuntimeError : Raised if build_ccd_input_map was not run first.

Definition at line 283 of file healSparseMapping.py.

283 def finalize_ccd_input_map_mask(self):
284 """Use accumulated mask information to finalize the masking of
285 ccd_input_map.
286
287 Raises
288 ------
289 RuntimeError : Raised if build_ccd_input_map was not run first.
290 """
291 if self.ccd_input_map is None:
292 raise RuntimeError("Must run build_ccd_input_map before finalize_ccd_input_map_mask.")
293
294 count_map_arr = self._ccd_input_bad_count_map[self._ccd_input_pixels]
295 for visit in self._bits_per_visit:
296 to_mask, = np.where(count_map_arr[f"v{visit}"] > self._min_bad)
297 if to_mask.size == 0:
298 continue
299 self.ccd_input_map.clear_bits_pix(self._ccd_input_pixels[to_mask],
300 self._bits_per_visit[visit])
301
302 # Clear memory
303 self._ccd_input_bad_count_map = None
304

◆ mask_warp_bbox()

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask.mask_warp_bbox ( self,
bbox,
visit,
mask,
bit_mask_value )
Mask a subregion from a visit.
This must be run after build_ccd_input_map initializes
the overall map.

Parameters
----------
bbox : `lsst.geom.Box2I`
    Bounding box from region to mask.
visit : `int`
    Visit number corresponding to warp with mask.
mask : `lsst.afw.image.MaskX`
    Mask plane from warp exposure.
bit_mask_value : `int`
    Bit mask to check for bad pixels.

Raises
------
RuntimeError : Raised if build_ccd_input_map was not run first.

Definition at line 230 of file healSparseMapping.py.

230 def mask_warp_bbox(self, bbox, visit, mask, bit_mask_value):
231 """Mask a subregion from a visit.
232 This must be run after build_ccd_input_map initializes
233 the overall map.
234
235 Parameters
236 ----------
237 bbox : `lsst.geom.Box2I`
238 Bounding box from region to mask.
239 visit : `int`
240 Visit number corresponding to warp with mask.
241 mask : `lsst.afw.image.MaskX`
242 Mask plane from warp exposure.
243 bit_mask_value : `int`
244 Bit mask to check for bad pixels.
245
246 Raises
247 ------
248 RuntimeError : Raised if build_ccd_input_map was not run first.
249 """
250 if self.ccd_input_map is None:
251 raise RuntimeError("Must run build_ccd_input_map before mask_warp_bbox")
252
253 # Find the bad pixels and convert to healpix
254 bad_pixels = np.where(mask.array & bit_mask_value)
255 if len(bad_pixels[0]) == 0:
256 # No bad pixels
257 return
258
259 # Bad pixels come from warps which use the overall wcs.
260 bad_ra, bad_dec = self._wcs.pixelToSkyArray(bad_pixels[1].astype(np.float64),
261 bad_pixels[0].astype(np.float64),
262 degrees=True)
263 bad_hpix = hpg.angle_to_pixel(self.config.nside, bad_ra, bad_dec)
264
265 # Count the number of bad image pixels in each healpix pixel
266 min_bad_hpix = bad_hpix.min()
267 bad_hpix_count = np.zeros(bad_hpix.max() - min_bad_hpix + 1, dtype=np.int32)
268 np.add.at(bad_hpix_count, bad_hpix - min_bad_hpix, 1)
269
270 # Add these to the accumulator map.
271 # We need to make sure that the "primary" array has valid values for
272 # this pixel to be registered in the accumulator map.
273 pix_to_add, = np.where(bad_hpix_count > 0)
274 count_map_arr = self._ccd_input_bad_count_map[min_bad_hpix + pix_to_add]
275 primary = self._ccd_input_bad_count_map.primary
276 count_map_arr[primary] = np.clip(count_map_arr[primary], 0, None)
277
278 count_map_arr[f"v{visit}"] = np.clip(count_map_arr[f"v{visit}"], 0, None)
279 count_map_arr[f"v{visit}"] += bad_hpix_count[pix_to_add]
280
281 self._ccd_input_bad_count_map[min_bad_hpix + pix_to_add] = count_map_arr
282

Member Data Documentation

◆ _bbox

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._bbox
protected

Definition at line 166 of file healSparseMapping.py.

◆ _bits_per_visit

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._bits_per_visit
protected

Definition at line 175 of file healSparseMapping.py.

◆ _bits_per_visit_ccd

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._bits_per_visit_ccd
protected

Definition at line 174 of file healSparseMapping.py.

◆ _ccd_input_bad_count_map

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._ccd_input_bad_count_map
protected

Definition at line 220 of file healSparseMapping.py.

◆ _ccd_input_pixels

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._ccd_input_pixels
protected

Definition at line 210 of file healSparseMapping.py.

◆ _ccds

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._ccds
protected

Definition at line 167 of file healSparseMapping.py.

◆ _DefaultName

str lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._DefaultName = "healSparseInputMap"
staticprotected

Definition at line 136 of file healSparseMapping.py.

◆ _min_bad

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._min_bad
protected

Definition at line 171 of file healSparseMapping.py.

◆ _wcs

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._wcs
protected

Definition at line 165 of file healSparseMapping.py.

◆ ccd_input_map

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask.ccd_input_map

Definition at line 141 of file healSparseMapping.py.

◆ ConfigClass

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask.ConfigClass = HealSparseInputMapConfig
static

Definition at line 135 of file healSparseMapping.py.


The documentation for this class was generated from the following file: