LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask Class Reference
Inheritance diagram for lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask:

Public Member Functions

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

Public Attributes

 ccd_input_map
 

Static Public Attributes

 ConfigClass = HealSparseInputMapConfig
 

Detailed Description

Task for making a HealSparse input map.

Definition at line 131 of file healSparseMapping.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 137 of file healSparseMapping.py.

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

Member Function Documentation

◆ build_ccd_input_map()

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

142  def build_ccd_input_map(self, bbox, wcs, ccds):
143  """Build a map from ccd valid polygons or bounding boxes.
144 
145  Parameters
146  ----------
147  bbox : `lsst.geom.Box2I`
148  Bounding box for region to build input map.
149  wcs : `lsst.afw.geom.SkyWcs`
150  WCS object for region to build input map.
151  ccds : `lsst.afw.table.ExposureCatalog`
152  Exposure catalog with ccd data from coadd inputs.
153  """
154  self.ccd_input_map = hsp.HealSparseMap.make_empty(nside_coverage=self.config.nside_coverage,
155  nside_sparse=self.config.nside,
156  dtype=hsp.WIDE_MASK,
157  wide_mask_maxbits=len(ccds))
158  self._wcs = wcs
159  self._bbox = bbox
160  self._ccds = ccds
161 
162  pixel_scale = wcs.getPixelScale().asArcseconds()
163  hpix_area_arcsec2 = hp.nside2pixarea(self.config.nside, degrees=True)*(3600.**2.)
164  self._min_bad = self.config.bad_mask_min_coverage*hpix_area_arcsec2/(pixel_scale**2.)
165 
166  metadata = {}
167  self._bits_per_visit_ccd = {}
168  self._bits_per_visit = defaultdict(list)
169  for bit, ccd_row in enumerate(ccds):
170  metadata[f"B{bit:04d}CCD"] = ccd_row["ccd"]
171  metadata[f"B{bit:04d}VIS"] = ccd_row["visit"]
172  metadata[f"B{bit:04d}WT"] = ccd_row["weight"]
173 
174  self._bits_per_visit_ccd[(ccd_row["visit"], ccd_row["ccd"])] = bit
175  self._bits_per_visit[ccd_row["visit"]].append(bit)
176 
177  ccd_poly = ccd_row.getValidPolygon()
178  if ccd_poly is None:
179  ccd_poly = afwGeom.Polygon(lsst.geom.Box2D(ccd_row.getBBox()))
180  # Detectors need to be rendered with their own wcs.
181  ccd_poly_radec = self._pixels_to_radec(ccd_row.getWcs(), ccd_poly.convexHull().getVertices())
182 
183  # Create a ccd healsparse polygon
184  poly = hsp.Polygon(ra=ccd_poly_radec[: -1, 0],
185  dec=ccd_poly_radec[: -1, 1],
186  value=[bit])
187  self.ccd_input_map.set_bits_pix(poly.get_pixels(nside=self.ccd_input_map.nside_sparse),
188  [bit])
189 
190  # Cut down to the overall bounding box with associated wcs.
191  bbox_afw_poly = afwGeom.Polygon(lsst.geom.Box2D(bbox))
192  bbox_poly_radec = self._pixels_to_radec(self._wcs,
193  bbox_afw_poly.convexHull().getVertices())
194  bbox_poly = hsp.Polygon(ra=bbox_poly_radec[: -1, 0], dec=bbox_poly_radec[: -1, 1],
195  value=np.arange(self.ccd_input_map.wide_mask_maxbits))
196  bbox_poly_map = bbox_poly.get_map_like(self.ccd_input_map)
197  self.ccd_input_map = hsp.and_intersection([self.ccd_input_map, bbox_poly_map])
198  self.ccd_input_map.metadata = metadata
199 
200  # Create a temporary map to hold the count of bad pixels in each healpix pixel
201  self._ccd_input_pixels = self.ccd_input_map.valid_pixels
202 
203  dtype = [(f"v{visit}", "i4") for visit in self._bits_per_visit.keys()]
204 
205  cov = self.config.nside_coverage
206  ns = self.config.nside
207  self._ccd_input_bad_count_map = hsp.HealSparseMap.make_empty(nside_coverage=cov,
208  nside_sparse=ns,
209  dtype=dtype,
210  primary=dtype[0][0])
211  # Don't set input bad map if there are no ccds which overlap the bbox.
212  if len(self._ccd_input_pixels) > 0:
213  self._ccd_input_bad_count_map[self._ccd_input_pixels] = np.zeros(1, dtype=dtype)
214 
Cartesian polygons.
Definition: Polygon.h:59
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33

◆ finalize_ccd_input_map_mask()

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

269  def finalize_ccd_input_map_mask(self):
270  """Use accumulated mask information to finalize the masking of
271  ccd_input_map.
272 
273  Raises
274  ------
275  RuntimeError : Raised if build_ccd_input_map was not run first.
276  """
277  if self.ccd_input_map is None:
278  raise RuntimeError("Must run build_ccd_input_map before finalize_ccd_input_map_mask.")
279 
280  count_map_arr = self._ccd_input_bad_count_map[self._ccd_input_pixels]
281  for visit in self._bits_per_visit:
282  to_mask, = np.where(count_map_arr[f"v{visit}"] > self._min_bad)
283  if to_mask.size == 0:
284  continue
285  self.ccd_input_map.clear_bits_pix(self._ccd_input_pixels[to_mask],
286  self._bits_per_visit[visit])
287 
288  # Clear memory
289  self._ccd_input_bad_count_map = None
290 

◆ mask_warp_bbox()

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

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

Member Data Documentation

◆ ccd_input_map

lsst.pipe.tasks.healSparseMapping.HealSparseInputMapTask.ccd_input_map

Definition at line 140 of file healSparseMapping.py.

◆ ConfigClass

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

Definition at line 134 of file healSparseMapping.py.


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