LSST Applications g044012fb7c+6976b5ec80,g04a91732dc+88a5fc122b,g07dc498a13+7e3c5f68a2,g114c6a66ad+09472d7a76,g1409bbee79+7e3c5f68a2,g1a7e361dbc+7e3c5f68a2,g1fd858c14a+3a43eabc0e,g35bb328faa+fcb1d3bbc8,g3bd4b5ce2c+2647bb081c,g4e0f332c67+5d362be553,g53246c7159+fcb1d3bbc8,g5477a8d5ce+b19c77c7ae,g58d0cdf3ff+4a2e102ff8,g60b5630c4e+09472d7a76,g623d845a50+09472d7a76,g6f0c2978f1+fcf1c0bcd6,g71fabbc107+09472d7a76,g75b6c65c88+d0b1dc44cc,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g8852436030+349c7e81d4,g89139ef638+7e3c5f68a2,g9125e01d80+fcb1d3bbc8,g95236ca021+f7a31438ed,g989de1cb63+7e3c5f68a2,g9f33ca652e+f17d666fbc,gaaedd4e678+7e3c5f68a2,gabe3b4be73+1e0a283bba,gb1101e3267+f870f33517,gb58c049af0+f03b321e39,gc99c83e5f0+76d20ab76d,gcf25f946ba+349c7e81d4,gd0fa69b896+f3a65fa83c,gd6cbbdb0b4+c8606af20c,gde0f65d7ad+5bd27d919f,ge278dab8ac+932305ba37,gfba249425e+fcb1d3bbc8,w.2025.07
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.pipe.tasks.skyCorrection.SkyCorrectionTask Class Reference
Inheritance diagram for lsst.pipe.tasks.skyCorrection.SkyCorrectionTask:

Public Member Functions

 __init__ (self, *args, **kwargs)
 
 runQuantum (self, butlerQC, inputRefs, outputRefs)
 
 run (self, calExps, calBkgs, skyFrames, camera)
 

Static Public Attributes

 ConfigClass = SkyCorrectionConfig
 

Protected Member Functions

 _restoreOriginalBackgroundRefineMask (self, calExps, calBkgs)
 
 _undoInitialBackground (self, calExps, calBkgs, initialBackgroundIndex)
 
 _subtractVisitBackground (self, calExps, calBkgs, camera, config)
 
 _subtractDetectorBackground (self, calExp, bgModel)
 
 _subtractSkyFrame (self, calExps, skyFrames, calBkgs)
 
 _binAndMosaic (self, exposures, camera, binning, ids=None, refExps=None)
 

Static Protected Attributes

str _DefaultName = "skyCorr"
 

Detailed Description

Perform a full focal plane sky correction.

Definition at line 224 of file skyCorrection.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pipe.tasks.skyCorrection.SkyCorrectionTask.__init__ ( self,
* args,
** kwargs )

Definition at line 230 of file skyCorrection.py.

230 def __init__(self, *args, **kwargs):
231 super().__init__(**kwargs)
232 self.makeSubtask("sky")
233 self.makeSubtask("maskObjects")
234

Member Function Documentation

◆ _binAndMosaic()

lsst.pipe.tasks.skyCorrection.SkyCorrectionTask._binAndMosaic ( self,
exposures,
camera,
binning,
ids = None,
refExps = None )
protected
Bin input exposures and mosaic across the entire focal plane.

Input exposures are binned and then mosaicked at the position of
the detector in the focal plane of the camera.

Parameters
----------
exposures : `list`
    Detector level list of either calexp `ExposureF` types or
    calexpBackground `BackgroundList` types.
camera : `lsst.afw.cameraGeom.Camera`
    Camera matching the input data to process.
binning : `int`
    Binning size to be applied to input images.
ids : `list` [`int`], optional
    List of detector ids to iterate over.
refExps : `list` [`lsst.afw.image.ExposureF`], optional
    If supplied, mask planes from these reference images will be used.
Returns
-------
mosaicImage : `lsst.afw.image.ExposureF`
    Mosaicked full focal plane image.

Definition at line 592 of file skyCorrection.py.

592 def _binAndMosaic(self, exposures, camera, binning, ids=None, refExps=None):
593 """Bin input exposures and mosaic across the entire focal plane.
594
595 Input exposures are binned and then mosaicked at the position of
596 the detector in the focal plane of the camera.
597
598 Parameters
599 ----------
600 exposures : `list`
601 Detector level list of either calexp `ExposureF` types or
602 calexpBackground `BackgroundList` types.
603 camera : `lsst.afw.cameraGeom.Camera`
604 Camera matching the input data to process.
605 binning : `int`
606 Binning size to be applied to input images.
607 ids : `list` [`int`], optional
608 List of detector ids to iterate over.
609 refExps : `list` [`lsst.afw.image.ExposureF`], optional
610 If supplied, mask planes from these reference images will be used.
611 Returns
612 -------
613 mosaicImage : `lsst.afw.image.ExposureF`
614 Mosaicked full focal plane image.
615 """
616 refExps = np.resize(refExps, len(exposures)) # type: ignore
617 binnedImages = []
618 for exp, refExp in zip(exposures, refExps):
619 try:
620 nativeImage = exp.getMaskedImage()
621 except AttributeError:
622 nativeImage = afwImage.makeMaskedImage(exp.getImage())
623 if refExp:
624 nativeImage.setMask(refExp.getMask())
625 binnedImage = afwMath.binImage(nativeImage, binning)
626 binnedImages.append(binnedImage)
627 mosConfig = VisualizeMosaicExpConfig()
628 mosConfig.binning = binning
629 mosTask = VisualizeMosaicExpTask(config=mosConfig)
630 imageStruct = mosTask.run(binnedImages, camera, inputIds=ids)
631 mosaicImage = imageStruct.outputData
632 return mosaicImage
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename std::shared_ptr< Image< ImagePixelT > > image, typename std::shared_ptr< Mask< MaskPixelT > > mask=Mask< MaskPixelT >(), typename std::shared_ptr< Image< VariancePixelT > > variance=Image< VariancePixelT >())
A function to return a MaskedImage of the correct type (cf.
std::shared_ptr< ImageT > binImage(ImageT const &inImage, int const binX, int const binY, lsst::afw::math::Property const flags=lsst::afw::math::MEAN)
Definition binImage.cc:44

◆ _restoreOriginalBackgroundRefineMask()

lsst.pipe.tasks.skyCorrection.SkyCorrectionTask._restoreOriginalBackgroundRefineMask ( self,
calExps,
calBkgs )
protected
Restore original background to each calexp and invert the related
background model; optionally refine the mask plane.

The original visit-level background is restored to each calibrated
exposure and the existing background model is inverted in-place. If
doMaskObjects is True, the mask map associated with the exposure will
be iteratively updated (over nIter loops) by re-estimating the
background each iteration and redetecting footprints.

The background model modified in-place in this method will comprise the
first N elements of the skyCorr dataset type, i.e., these N elements
are the inverse of the calexpBackground model. All subsequent elements
appended to skyCorr will be additive such that, when skyCorr is
subtracted from a calexp, the net result will be to undo the initial
per-detector background solution and then apply the skyCorr model
thereafter. Adding skyCorr to a calexpBackground will effectively
negate the calexpBackground, returning only the additive background
components of the skyCorr background model.

Parameters
----------
calExps : `lsst.afw.image.ExposureF`
    Detector level calexp images to process.
calBkgs : `lsst.afw.math.BackgroundList`
    Detector level background lists associated with the calexps.

Returns
-------
calExps : `lsst.afw.image.ExposureF`
    The calexps with the originally subtracted background restored.
skyCorrBases : `lsst.afw.math.BackgroundList`
    The inverted original background models; the genesis for skyCorrs.

Definition at line 351 of file skyCorrection.py.

351 def _restoreOriginalBackgroundRefineMask(self, calExps, calBkgs):
352 """Restore original background to each calexp and invert the related
353 background model; optionally refine the mask plane.
354
355 The original visit-level background is restored to each calibrated
356 exposure and the existing background model is inverted in-place. If
357 doMaskObjects is True, the mask map associated with the exposure will
358 be iteratively updated (over nIter loops) by re-estimating the
359 background each iteration and redetecting footprints.
360
361 The background model modified in-place in this method will comprise the
362 first N elements of the skyCorr dataset type, i.e., these N elements
363 are the inverse of the calexpBackground model. All subsequent elements
364 appended to skyCorr will be additive such that, when skyCorr is
365 subtracted from a calexp, the net result will be to undo the initial
366 per-detector background solution and then apply the skyCorr model
367 thereafter. Adding skyCorr to a calexpBackground will effectively
368 negate the calexpBackground, returning only the additive background
369 components of the skyCorr background model.
370
371 Parameters
372 ----------
373 calExps : `lsst.afw.image.ExposureF`
374 Detector level calexp images to process.
375 calBkgs : `lsst.afw.math.BackgroundList`
376 Detector level background lists associated with the calexps.
377
378 Returns
379 -------
380 calExps : `lsst.afw.image.ExposureF`
381 The calexps with the originally subtracted background restored.
382 skyCorrBases : `lsst.afw.math.BackgroundList`
383 The inverted original background models; the genesis for skyCorrs.
384 """
385 skyCorrBases = []
386 for calExp, calBkg in zip(calExps, calBkgs):
387 image = calExp.getMaskedImage()
388
389 # Invert all elements of the existing bg model; restore in calexp
390 for calBkgElement in calBkg:
391 statsImage = calBkgElement[0].getStatsImage()
392 statsImage *= -1
393 skyCorrBase = calBkg.getImage()
394 image -= skyCorrBase
395
396 # Iteratively subtract bg, re-detect sources, and add bg back on
397 if self.config.doMaskObjects:
398 self.maskObjects.findObjects(calExp)
399
400 stats = np.nanpercentile(skyCorrBase.array, [50, 75, 25])
401 self.log.info(
402 "Detector %d: Original background restored; BG median = %.1f counts, BG IQR = %.1f counts",
403 calExp.getDetector().getId(),
404 -stats[0],
405 np.subtract(*stats[1:]),
406 )
407 skyCorrBases.append(skyCorrBase)
408 return calExps, skyCorrBases
409

◆ _subtractDetectorBackground()

lsst.pipe.tasks.skyCorrection.SkyCorrectionTask._subtractDetectorBackground ( self,
calExp,
bgModel )
protected
Generate CCD background model and subtract from image.

Translate the full focal plane background into CCD coordinates and
subtract from the original science exposure image.

Parameters
----------
calExp : `lsst.afw.image.ExposureF`
    Exposure to subtract the background model from.
bgModel : `lsst.pipe.tasks.background.FocalPlaneBackground`
    Full focal plane camera-level background model.

Returns
-------
calExp : `lsst.afw.image.ExposureF`
    Background subtracted input exposure.
calBkgElement : `lsst.afw.math.BackgroundList`
    Detector level realization of the full focal plane bg model.

Definition at line 524 of file skyCorrection.py.

524 def _subtractDetectorBackground(self, calExp, bgModel):
525 """Generate CCD background model and subtract from image.
526
527 Translate the full focal plane background into CCD coordinates and
528 subtract from the original science exposure image.
529
530 Parameters
531 ----------
532 calExp : `lsst.afw.image.ExposureF`
533 Exposure to subtract the background model from.
534 bgModel : `lsst.pipe.tasks.background.FocalPlaneBackground`
535 Full focal plane camera-level background model.
536
537 Returns
538 -------
539 calExp : `lsst.afw.image.ExposureF`
540 Background subtracted input exposure.
541 calBkgElement : `lsst.afw.math.BackgroundList`
542 Detector level realization of the full focal plane bg model.
543 """
544 image = calExp.getMaskedImage()
545 with warnings.catch_warnings():
546 warnings.filterwarnings("ignore", r"invalid value encountered")
547 calBkgElement = bgModel.toCcdBackground(calExp.getDetector(), image.getBBox())
548 image -= calBkgElement.getImage()
549 return calExp, calBkgElement
550

◆ _subtractSkyFrame()

lsst.pipe.tasks.skyCorrection.SkyCorrectionTask._subtractSkyFrame ( self,
calExps,
skyFrames,
calBkgs )
protected
Determine the full focal plane sky frame scale factor relative to
an input list of calibrated exposures and subtract.

This method measures the sky frame scale on all inputs, resulting in
values equal to the background method solveScales(). The sky frame is
then subtracted as in subtractSkyFrame() using the appropriate scale.

Input calExps and calBkgs are updated in-place, returning sky frame
subtracted calExps and sky frame updated calBkgs, respectively.

Parameters
----------
calExps : `list` [`lsst.afw.image.ExposureF`]
    Calibrated exposures to be background subtracted.
skyFrames : `list` [`lsst.afw.image.ExposureF`]
    Sky frame calibration data for the input detectors.
calBkgs : `list` [`lsst.afw.math.BackgroundList`]
    Background lists associated with the input calibrated exposures.

Returns
-------
scale : `float`
    Scale factor applied to the sky frame.

Definition at line 551 of file skyCorrection.py.

551 def _subtractSkyFrame(self, calExps, skyFrames, calBkgs):
552 """Determine the full focal plane sky frame scale factor relative to
553 an input list of calibrated exposures and subtract.
554
555 This method measures the sky frame scale on all inputs, resulting in
556 values equal to the background method solveScales(). The sky frame is
557 then subtracted as in subtractSkyFrame() using the appropriate scale.
558
559 Input calExps and calBkgs are updated in-place, returning sky frame
560 subtracted calExps and sky frame updated calBkgs, respectively.
561
562 Parameters
563 ----------
564 calExps : `list` [`lsst.afw.image.ExposureF`]
565 Calibrated exposures to be background subtracted.
566 skyFrames : `list` [`lsst.afw.image.ExposureF`]
567 Sky frame calibration data for the input detectors.
568 calBkgs : `list` [`lsst.afw.math.BackgroundList`]
569 Background lists associated with the input calibrated exposures.
570
571 Returns
572 -------
573 scale : `float`
574 Scale factor applied to the sky frame.
575 """
576 skyFrameBgModels = []
577 scales = []
578 for calExp, skyFrame in zip(calExps, skyFrames):
579 skyFrameBgModel = self.sky.exposureToBackground(skyFrame)
580 skyFrameBgModels.append(skyFrameBgModel)
581 # return a tuple of gridded image and sky frame clipped means
582 samples = self.sky.measureScale(calExp.getMaskedImage(), skyFrameBgModel)
583 scales.append(samples)
584 scale = self.sky.solveScales(scales)
585 for calExp, skyFrameBgModel, calBkg in zip(calExps, skyFrameBgModels, calBkgs):
586 # subtract the scaled sky frame model from each calExp in-place,
587 # also updating the calBkg list in-place
588 self.sky.subtractSkyFrame(calExp.getMaskedImage(), skyFrameBgModel, scale, calBkg)
589 self.log.info("Sky frame subtracted with a scale factor of %.5f", scale)
590 return scale
591

◆ _subtractVisitBackground()

lsst.pipe.tasks.skyCorrection.SkyCorrectionTask._subtractVisitBackground ( self,
calExps,
calBkgs,
camera,
config )
protected
Perform a full focal-plane background subtraction for a visit.

Generate a full focal plane background model, binning all masked
detectors into bins of [bgModelN.xSize, bgModelN.ySize]. After,
subtract the resultant background model (translated back into CCD
coordinates) from the original detector exposure.

Return a list of background subtracted images and a list of full focal
plane background parameters.

Parameters
----------
calExps : `list` [`lsst.afw.image.ExposureF`]
    Calibrated exposures to be background subtracted.
calBkgs : `list` [`lsst.afw.math.BackgroundList`]
    Background lists associated with the input calibrated exposures.
camera : `lsst.afw.cameraGeom.Camera`
    Camera description.
config : `lsst.pipe.tasks.background.FocalPlaneBackgroundConfig`
    Configuration to use for background subtraction.

Returns
-------
calExps : `list` [`lsst.afw.image.maskedImage.MaskedImageF`]
    Background subtracted exposures for creating a focal plane image.
calBkgs : `list` [`lsst.afw.math.BackgroundList`]
    Updated background lists with a visit-level model appended.

Definition at line 441 of file skyCorrection.py.

441 def _subtractVisitBackground(self, calExps, calBkgs, camera, config):
442 """Perform a full focal-plane background subtraction for a visit.
443
444 Generate a full focal plane background model, binning all masked
445 detectors into bins of [bgModelN.xSize, bgModelN.ySize]. After,
446 subtract the resultant background model (translated back into CCD
447 coordinates) from the original detector exposure.
448
449 Return a list of background subtracted images and a list of full focal
450 plane background parameters.
451
452 Parameters
453 ----------
454 calExps : `list` [`lsst.afw.image.ExposureF`]
455 Calibrated exposures to be background subtracted.
456 calBkgs : `list` [`lsst.afw.math.BackgroundList`]
457 Background lists associated with the input calibrated exposures.
458 camera : `lsst.afw.cameraGeom.Camera`
459 Camera description.
460 config : `lsst.pipe.tasks.background.FocalPlaneBackgroundConfig`
461 Configuration to use for background subtraction.
462
463 Returns
464 -------
465 calExps : `list` [`lsst.afw.image.maskedImage.MaskedImageF`]
466 Background subtracted exposures for creating a focal plane image.
467 calBkgs : `list` [`lsst.afw.math.BackgroundList`]
468 Updated background lists with a visit-level model appended.
469 """
470 # Set up empty full focal plane background model object
471 bgModelBase = FocalPlaneBackground.fromCamera(config, camera)
472
473 # Loop over each detector, bin into [xSize, ySize] bins, and update
474 # summed flux (_values) and number of contributing pixels (_numbers)
475 # in focal plane coordinates. Append outputs to bgModels.
476 bgModels = []
477 for calExp in calExps:
478 bgModel = bgModelBase.clone()
479 bgModel.addCcd(calExp)
480 bgModels.append(bgModel)
481
482 # Merge detector models to make a single full focal plane bg model
483 for bgModel, calExp in zip(bgModels, calExps):
484 msg = (
485 "Detector %d: Merging %d unmasked pixels (%.1f%s of detector area) into focal plane "
486 "background model"
487 )
488 self.log.debug(
489 msg,
490 calExp.getDetector().getId(),
491 bgModel._numbers.getArray().sum(),
492 100 * bgModel._numbers.getArray().sum() / calExp.getBBox().getArea(),
493 "%",
494 )
495 bgModelBase.merge(bgModel)
496
497 # Map full focal plane bg solution to detector; subtract from exposure
498 calBkgElements = []
499 for calExp in calExps:
500 _, calBkgElement = self._subtractDetectorBackground(calExp, bgModelBase)
501 calBkgElements.append(calBkgElement)
502
503 msg = (
504 "Focal plane background model constructed using %.2f x %.2f mm (%d x %d pixel) superpixels; "
505 "FP BG median = %.1f counts, FP BG IQR = %.1f counts"
506 )
507 with warnings.catch_warnings():
508 warnings.filterwarnings("ignore", r"invalid value encountered")
509 stats = np.nanpercentile(bgModelBase.getStatsImage().array, [50, 75, 25])
510 self.log.info(
511 msg,
512 config.xSize,
513 config.ySize,
514 int(config.xSize / config.pixelSize),
515 int(config.ySize / config.pixelSize),
516 stats[0],
517 np.subtract(*stats[1:]),
518 )
519
520 for calBkg, calBkgElement in zip(calBkgs, calBkgElements):
521 calBkg.append(calBkgElement[0])
522 return calExps, calBkgs
523

◆ _undoInitialBackground()

lsst.pipe.tasks.skyCorrection.SkyCorrectionTask._undoInitialBackground ( self,
calExps,
calBkgs,
initialBackgroundIndex )
protected
Undo the initial background subtraction (bgModel1) after sky frame
subtraction.

Parameters
----------
calExps : `list` [`lsst.afw.image.ExposureF`]
    Calibrated exposures to be background subtracted.
calBkgs : `list` [`lsst.afw.math.BackgroundList`]
    Background lists associated with the input calibrated exposures.
initialBackgroundIndex : `int`
    Index of the initial background (bgModel1) in the background list.

Notes
-----
Inputs are modified in-place.

Definition at line 410 of file skyCorrection.py.

410 def _undoInitialBackground(self, calExps, calBkgs, initialBackgroundIndex):
411 """Undo the initial background subtraction (bgModel1) after sky frame
412 subtraction.
413
414 Parameters
415 ----------
416 calExps : `list` [`lsst.afw.image.ExposureF`]
417 Calibrated exposures to be background subtracted.
418 calBkgs : `list` [`lsst.afw.math.BackgroundList`]
419 Background lists associated with the input calibrated exposures.
420 initialBackgroundIndex : `int`
421 Index of the initial background (bgModel1) in the background list.
422
423 Notes
424 -----
425 Inputs are modified in-place.
426 """
427 for calExp, calBkg in zip(calExps, calBkgs):
428 image = calExp.getMaskedImage()
429
430 # Remove bgModel1 from the background list; restore in the image
431 initialBackground = calBkg[initialBackgroundIndex][0].getImageF()
432 image += initialBackground
433 calBkg._backgrounds.pop(initialBackgroundIndex)
434
435 self.log.info(
436 "Detector %d: The initial background model prior to sky frame subtraction (bgModel1) has "
437 "been removed from the background list",
438 calExp.getDetector().getId(),
439 )
440

◆ run()

lsst.pipe.tasks.skyCorrection.SkyCorrectionTask.run ( self,
calExps,
calBkgs,
skyFrames,
camera )
Perform sky correction on a visit.

The original visit-level background is first restored to the calibrated
exposure and the existing background model is inverted in-place. If
doMaskObjects is True, the mask map associated with this exposure will
be iteratively updated (over nIter loops) by re-estimating the
background each iteration and redetecting footprints.

An initial full focal plane sky subtraction (bgModel1) will take place
prior to scaling and subtracting the sky frame.

If doSky is True, the sky frame will be scaled to the flux in the input
visit.

If doBgModel2 is True, a final full focal plane sky subtraction will
take place after the sky frame has been subtracted.

The first N elements of the returned skyCorr will consist of inverted
elements of the calexpBackground model (i.e., subtractive). All
subsequent elements appended to skyCorr thereafter will be additive
such that, when skyCorr is subtracted from a calexp, the net result
will be to undo the initial per-detector background solution and then
apply the skyCorr model thereafter. Adding skyCorr to a
calexpBackground will effectively negate the calexpBackground,
returning only the additive background components of the skyCorr
background model.

Parameters
----------
calExps : `list` [`lsst.afw.image.ExposureF`]
    Detector calibrated exposure images for the visit.
calBkgs : `list` [`lsst.afw.math.BackgroundList`]
    Detector background lists matching the calibrated exposures.
skyFrames : `list` [`lsst.afw.image.ExposureF`]
    Sky frame calibration data for the input detectors.
camera : `lsst.afw.cameraGeom.Camera`
    Camera matching the input data to process.

Returns
-------
results : `Struct` containing:
    skyFrameScale : `float`
        Scale factor applied to the sky frame.
    skyCorr : `list` [`lsst.afw.math.BackgroundList`]
        Detector-level sky correction background lists.
    calExpMosaic : `lsst.afw.image.ExposureF`
        Visit-level mosaic of the sky corrected data, binned.
        Analogous to `calexp - skyCorr`.
    calBkgMosaic : `lsst.afw.image.ExposureF`
        Visit-level mosaic of the sky correction background, binned.
        Analogous to `calexpBackground + skyCorr`.

Definition at line 261 of file skyCorrection.py.

261 def run(self, calExps, calBkgs, skyFrames, camera):
262 """Perform sky correction on a visit.
263
264 The original visit-level background is first restored to the calibrated
265 exposure and the existing background model is inverted in-place. If
266 doMaskObjects is True, the mask map associated with this exposure will
267 be iteratively updated (over nIter loops) by re-estimating the
268 background each iteration and redetecting footprints.
269
270 An initial full focal plane sky subtraction (bgModel1) will take place
271 prior to scaling and subtracting the sky frame.
272
273 If doSky is True, the sky frame will be scaled to the flux in the input
274 visit.
275
276 If doBgModel2 is True, a final full focal plane sky subtraction will
277 take place after the sky frame has been subtracted.
278
279 The first N elements of the returned skyCorr will consist of inverted
280 elements of the calexpBackground model (i.e., subtractive). All
281 subsequent elements appended to skyCorr thereafter will be additive
282 such that, when skyCorr is subtracted from a calexp, the net result
283 will be to undo the initial per-detector background solution and then
284 apply the skyCorr model thereafter. Adding skyCorr to a
285 calexpBackground will effectively negate the calexpBackground,
286 returning only the additive background components of the skyCorr
287 background model.
288
289 Parameters
290 ----------
291 calExps : `list` [`lsst.afw.image.ExposureF`]
292 Detector calibrated exposure images for the visit.
293 calBkgs : `list` [`lsst.afw.math.BackgroundList`]
294 Detector background lists matching the calibrated exposures.
295 skyFrames : `list` [`lsst.afw.image.ExposureF`]
296 Sky frame calibration data for the input detectors.
297 camera : `lsst.afw.cameraGeom.Camera`
298 Camera matching the input data to process.
299
300 Returns
301 -------
302 results : `Struct` containing:
303 skyFrameScale : `float`
304 Scale factor applied to the sky frame.
305 skyCorr : `list` [`lsst.afw.math.BackgroundList`]
306 Detector-level sky correction background lists.
307 calExpMosaic : `lsst.afw.image.ExposureF`
308 Visit-level mosaic of the sky corrected data, binned.
309 Analogous to `calexp - skyCorr`.
310 calBkgMosaic : `lsst.afw.image.ExposureF`
311 Visit-level mosaic of the sky correction background, binned.
312 Analogous to `calexpBackground + skyCorr`.
313 """
314 # Restore original backgrounds in-place; optionally refine mask maps
315 numOrigBkgElements = [len(calBkg) for calBkg in calBkgs]
316 _ = self._restoreOriginalBackgroundRefineMask(calExps, calBkgs)
317
318 # Bin exposures, generate full-fp bg, map to CCDs and subtract in-place
319 _ = self._subtractVisitBackground(calExps, calBkgs, camera, self.config.bgModel1)
320 initialBackgroundIndex = len(calBkgs[0]._backgrounds) - 1
321
322 # Subtract a scaled sky frame from all input exposures
323 skyFrameScale = None
324 if self.config.doSky:
325 skyFrameScale = self._subtractSkyFrame(calExps, skyFrames, calBkgs)
326
327 # Adds full-fp bg back onto exposures, removes it from list
328 if self.config.undoBgModel1:
329 _ = self._undoInitialBackground(calExps, calBkgs, initialBackgroundIndex)
330
331 # Bin exposures, generate full-fp bg, map to CCDs and subtract in-place
332 if self.config.doBgModel2:
333 _ = self._subtractVisitBackground(calExps, calBkgs, camera, self.config.bgModel2)
334
335 # Make camera-level images of bg subtracted calexps and subtracted bgs
336 calExpIds = [exp.getDetector().getId() for exp in calExps]
337 skyCorrExtras = []
338 for calBkg, num in zip(calBkgs, numOrigBkgElements):
339 skyCorrExtra = calBkg.clone()
340 skyCorrExtra._backgrounds = skyCorrExtra._backgrounds[num:]
341 skyCorrExtras.append(skyCorrExtra)
342 calExpMosaic = self._binAndMosaic(calExps, camera, self.config.binning, ids=calExpIds, refExps=None)
343 calBkgMosaic = self._binAndMosaic(
344 skyCorrExtras, camera, self.config.binning, ids=calExpIds, refExps=calExps
345 )
346
347 return Struct(
348 skyFrameScale=skyFrameScale, skyCorr=calBkgs, calExpMosaic=calExpMosaic, calBkgMosaic=calBkgMosaic
349 )
350

◆ runQuantum()

lsst.pipe.tasks.skyCorrection.SkyCorrectionTask.runQuantum ( self,
butlerQC,
inputRefs,
outputRefs )

Definition at line 235 of file skyCorrection.py.

235 def runQuantum(self, butlerQC, inputRefs, outputRefs):
236 # Sort the calExps, calBkgs and skyFrames inputRefs and the
237 # skyCorr outputRef by detector ID to ensure reproducibility.
238 detectorOrder = [ref.dataId["detector"] for ref in inputRefs.calExps]
239 detectorOrder.sort()
240 inputRefs.calExps = _reorderAndPadList(
241 inputRefs.calExps, [ref.dataId["detector"] for ref in inputRefs.calExps], detectorOrder
242 )
243 inputRefs.calBkgs = _reorderAndPadList(
244 inputRefs.calBkgs, [ref.dataId["detector"] for ref in inputRefs.calBkgs], detectorOrder
245 )
246 # Only attempt to fetch sky frames if they are going to be applied.
247 if self.config.doSky:
248 inputRefs.skyFrames = _reorderAndPadList(
249 inputRefs.skyFrames, [ref.dataId["detector"] for ref in inputRefs.skyFrames], detectorOrder
250 )
251 else:
252 inputRefs.skyFrames = []
253 outputRefs.skyCorr = _reorderAndPadList(
254 outputRefs.skyCorr, [ref.dataId["detector"] for ref in outputRefs.skyCorr], detectorOrder
255 )
256 inputs = butlerQC.get(inputRefs)
257 inputs.pop("rawLinker", None)
258 outputs = self.run(**inputs)
259 butlerQC.put(outputs, outputRefs)
260

Member Data Documentation

◆ _DefaultName

str lsst.pipe.tasks.skyCorrection.SkyCorrectionTask._DefaultName = "skyCorr"
staticprotected

Definition at line 228 of file skyCorrection.py.

◆ ConfigClass

lsst.pipe.tasks.skyCorrection.SkyCorrectionTask.ConfigClass = SkyCorrectionConfig
static

Definition at line 227 of file skyCorrection.py.


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