LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
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 132 of file healSparseMapping.py.

Constructor & Destructor Documentation

◆ __init__()

def 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

◆ 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 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  self.ccd_input_map = hsp.HealSparseMap.make_empty(nside_coverage=self.config.nside_coverage,
156  nside_sparse=self.config.nside,
157  dtype=hsp.WIDE_MASK,
158  wide_mask_maxbits=len(ccds))
159  self._wcs = wcs
160  self._bbox = bbox
161  self._ccds = ccds
162 
163  pixel_scale = wcs.getPixelScale().asArcseconds()
164  hpix_area_arcsec2 = hp.nside2pixarea(self.config.nside, degrees=True)*(3600.**2.)
165  self._min_bad = self.config.bad_mask_min_coverage*hpix_area_arcsec2/(pixel_scale**2.)
166 
167  metadata = {}
168  self._bits_per_visit_ccd = {}
169  self._bits_per_visit = defaultdict(list)
170  for bit, ccd_row in enumerate(ccds):
171  metadata[f"B{bit:04d}CCD"] = ccd_row["ccd"]
172  metadata[f"B{bit:04d}VIS"] = ccd_row["visit"]
173  metadata[f"B{bit:04d}WT"] = ccd_row["weight"]
174 
175  self._bits_per_visit_ccd[(ccd_row["visit"], ccd_row["ccd"])] = bit
176  self._bits_per_visit[ccd_row["visit"]].append(bit)
177 
178  ccd_poly = ccd_row.getValidPolygon()
179  if ccd_poly is None:
180  ccd_poly = afwGeom.Polygon(lsst.geom.Box2D(ccd_row.getBBox()))
181  # Detectors need to be rendered with their own wcs.
182  ccd_poly_radec = self._pixels_to_radec(ccd_row.getWcs(), ccd_poly.convexHull().getVertices())
183 
184  # Create a ccd healsparse polygon
185  poly = hsp.Polygon(ra=ccd_poly_radec[: -1, 0],
186  dec=ccd_poly_radec[: -1, 1],
187  value=[bit])
188  self.ccd_input_map.set_bits_pix(poly.get_pixels(nside=self.ccd_input_map.nside_sparse),
189  [bit])
190 
191  # Cut down to the overall bounding box with associated wcs.
192  bbox_afw_poly = afwGeom.Polygon(lsst.geom.Box2D(bbox))
193  bbox_poly_radec = self._pixels_to_radec(self._wcs,
194  bbox_afw_poly.convexHull().getVertices())
195  bbox_poly = hsp.Polygon(ra=bbox_poly_radec[: -1, 0], dec=bbox_poly_radec[: -1, 1],
196  value=np.arange(self.ccd_input_map.wide_mask_maxbits))
197  bbox_poly_map = bbox_poly.get_map_like(self.ccd_input_map)
198  self.ccd_input_map = hsp.and_intersection([self.ccd_input_map, bbox_poly_map])
199  self.ccd_input_map.metadata = metadata
200 
201  # Create a temporary map to hold the count of bad pixels in each healpix pixel
202  self._ccd_input_pixels = self.ccd_input_map.valid_pixels
203 
204  dtype = [(f"v{visit}", "i4") for visit in self._bits_per_visit.keys()]
205 
206  cov = self.config.nside_coverage
207  ns = self.config.nside
208  self._ccd_input_bad_count_map = hsp.HealSparseMap.make_empty(nside_coverage=cov,
209  nside_sparse=ns,
210  dtype=dtype,
211  primary=dtype[0][0])
212  # Don't set input bad map if there are no ccds which overlap the bbox.
213  if len(self._ccd_input_pixels) > 0:
214  self._ccd_input_bad_count_map[self._ccd_input_pixels] = np.zeros(1, dtype=dtype)
215 
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 270 of file healSparseMapping.py.

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

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

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

Member Data Documentation

◆ 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: