LSST Applications g00274db5b6+edbf708997,g00d0e8bbd7+edbf708997,g199a45376c+5137f08352,g1fd858c14a+1d4b6db739,g262e1987ae+f4d9505c4f,g29ae962dfc+7156fb1a53,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3e17d7035e+5b3adc59f5,g3fd5ace14f+852fa6fbcb,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+9f17e571f4,g67b6fd64d1+6dc8069a4c,g74acd417e5+ae494d68d9,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+536efcc10a,g7cc15d900a+d121454f8d,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d7436a09f+28c28d8d6d,g8ea07a8fe4+db21c37724,g92c671f44c+9f17e571f4,g98df359435+b2e6376b13,g99af87f6a8+b0f4ad7b8d,gac66b60396+966efe6077,gb88ae4c679+7dec8f19df,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gc24b5d6ed1+9f17e571f4,gca7fc764a6+6dc8069a4c,gcc769fe2a4+97d0256649,gd7ef33dd92+6dc8069a4c,gdab6d2f7ff+ae494d68d9,gdbb4c4dda9+9f17e571f4,ge410e46f29+6dc8069a4c,geaed405ab2+e194be0d2b,w.2025.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
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 = None
 

Static Public Attributes

 ConfigClass = HealSparseInputMapConfig
 

Protected Member Functions

 _pixels_to_radec (self, wcs, pixels)
 

Protected Attributes

 _wcs = wcs
 
 _bbox = bbox
 
 _ccds = ccds
 
 _min_bad = self.config.bad_mask_min_coverage*hpix_area_arcsec2/(pixel_scale**2.)
 
dict _bits_per_visit_ccd = {}
 
 _bits_per_visit = defaultdict(list)
 
 _ccd_input_bad_count_map
 
 _ccd_input_pixels = self.ccd_input_map.valid_pixels
 

Static Protected Attributes

str _DefaultName = "healSparseInputMap"
 

Detailed Description

Task for making a HealSparse input map.

Definition at line 133 of file healSparseMapping.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 139 of file healSparseMapping.py.

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

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 312 of file healSparseMapping.py.

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

◆ 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 144 of file healSparseMapping.py.

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

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

◆ 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 234 of file healSparseMapping.py.

234 def mask_warp_bbox(self, bbox, visit, mask, bit_mask_value):
235 """Mask a subregion from a visit.
236 This must be run after build_ccd_input_map initializes
237 the overall map.
238
239 Parameters
240 ----------
241 bbox : `lsst.geom.Box2I`
242 Bounding box from region to mask.
243 visit : `int`
244 Visit number corresponding to warp with mask.
245 mask : `lsst.afw.image.MaskX`
246 Mask plane from warp exposure.
247 bit_mask_value : `int`
248 Bit mask to check for bad pixels.
249
250 Raises
251 ------
252 RuntimeError : Raised if build_ccd_input_map was not run first.
253 """
254 if self.ccd_input_map is None:
255 raise RuntimeError("Must run build_ccd_input_map before mask_warp_bbox")
256
257 if len(self._ccd_input_pixels) == 0:
258 # This tract has no coverage, so there is nothing to do.
259 return
260
261 # Find the bad pixels and convert to healpix
262 bad_pixels = np.where(mask.array & bit_mask_value)
263 if len(bad_pixels[0]) == 0:
264 # No bad pixels
265 return
266
267 # Bad pixels come from warps which use the overall wcs.
268 bad_ra, bad_dec = self._wcs.pixelToSkyArray(
269 bad_pixels[1].astype(np.float64) + bbox.getMinX(),
270 bad_pixels[0].astype(np.float64) + bbox.getMinY(),
271 degrees=True,
272 )
273 bad_hpix = hpg.angle_to_pixel(self.config.nside, bad_ra, bad_dec)
274
275 # Check if any of these "bad" pixels are in the valid footprint.
276 match_input, match_bad = esutil.numpy_util.match(self._ccd_input_pixels, bad_hpix, presorted=True)
277 if len(match_bad) == 0:
278 return
279
280 bad_hpix = bad_hpix[match_bad]
281
282 # Create a view of the column we need to add to.
283 count_map_visit = self._ccd_input_bad_count_map[f"v{visit}"]
284 # Add the bad pixels to the accumulator. Note that the view
285 # cannot append pixels, but the match above ensures we are
286 # only adding to pixels that are already in the coverage
287 # map and initialized.
288 count_map_visit.update_values_pix(bad_hpix, 1, operation="add")
289

Member Data Documentation

◆ _bbox

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

Definition at line 167 of file healSparseMapping.py.

◆ _bits_per_visit

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._bits_per_visit = defaultdict(list)
protected

Definition at line 176 of file healSparseMapping.py.

◆ _bits_per_visit_ccd

dict lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._bits_per_visit_ccd = {}
protected

Definition at line 175 of file healSparseMapping.py.

◆ _ccd_input_bad_count_map

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._ccd_input_bad_count_map
protected
Initial value:
= hsp.HealSparseMap.make_empty(
nside_coverage=self.config.nside_coverage,
nside_sparse=self.config.nside,
dtype=dtype,
primary=dtype[0][0])

Definition at line 219 of file healSparseMapping.py.

◆ _ccd_input_pixels

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._ccd_input_pixels = self.ccd_input_map.valid_pixels
protected

Definition at line 225 of file healSparseMapping.py.

◆ _ccds

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

Definition at line 168 of file healSparseMapping.py.

◆ _DefaultName

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

Definition at line 137 of file healSparseMapping.py.

◆ _min_bad

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask._min_bad = self.config.bad_mask_min_coverage*hpix_area_arcsec2/(pixel_scale**2.)
protected

Definition at line 172 of file healSparseMapping.py.

◆ _wcs

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

Definition at line 166 of file healSparseMapping.py.

◆ ccd_input_map

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask.ccd_input_map = None

Definition at line 142 of file healSparseMapping.py.

◆ ConfigClass

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

Definition at line 136 of file healSparseMapping.py.


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