LSST Applications g04e9c324dd+8c5ae1fdc5,g0644efc3f0+366663dc37,g123d84c11c+8c5ae1fdc5,g1ec0fe41b4+6ec6b74de1,g1fd858c14a+1be88e80db,g3533f9d6cb+366663dc37,g35bb328faa+8c5ae1fdc5,g35ef7ab7cf+285dd5b202,g53246c7159+8c5ae1fdc5,g60b5630c4e+366663dc37,g663da51e9b+41529343ca,g6735e52a0d+29de3d959a,g67b6fd64d1+57193d00fb,g7605de067c+8f72e4d2dc,g78460c75b0+7e33a9eb6d,g786e29fd12+668abc6043,g844c57033c+03ddc13274,g8852436030+e345a59dd4,g89139ef638+57193d00fb,g989de1cb63+57193d00fb,g9a0bdda227+852181cf57,g9f33ca652e+a2d35689ce,ga1e959baac+5fbc491aed,ga2f891cd6c+366663dc37,gabe3b4be73+8856018cbb,gabf8522325+cc757f8247,gac2eed3f23+57193d00fb,gb1101e3267+f6b489998a,gb89ab40317+57193d00fb,gcf25f946ba+e345a59dd4,gd107969129+227687db21,gd6cbbdb0b4+8e46defd2a,gde0f65d7ad+2dad650f79,ge278dab8ac+2322f1d6ea,ge410e46f29+57193d00fb,gf30d85a44d+8e3077faf9,gf5e32f922b+8c5ae1fdc5,gff02db199a+5c78c1866e,w.2025.28
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 310 of file healSparseMapping.py.

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

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

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

◆ 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(bad_pixels[1].astype(np.float64),
269 bad_pixels[0].astype(np.float64),
270 degrees=True)
271 bad_hpix = hpg.angle_to_pixel(self.config.nside, bad_ra, bad_dec)
272
273 # Check if any of these "bad" pixels are in the valid footprint.
274 match_input, match_bad = esutil.numpy_util.match(self._ccd_input_pixels, bad_hpix, presorted=True)
275 if len(match_bad) == 0:
276 return
277
278 bad_hpix = bad_hpix[match_bad]
279
280 # Create a view of the column we need to add to.
281 count_map_visit = self._ccd_input_bad_count_map[f"v{visit}"]
282 # Add the bad pixels to the accumulator. Note that the view
283 # cannot append pixels, but the match above ensures we are
284 # only adding to pixels that are already in the coverage
285 # map and initialized.
286 count_map_visit.update_values_pix(bad_hpix, 1, operation="add")
287

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: