Skip to content

Commit

Permalink
Use MaskObjectsTask in skyCorrection
Browse files Browse the repository at this point in the history
  • Loading branch information
michitaro committed Apr 1, 2019
1 parent 832078c commit 773e3a2
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions python/lsst/pipe/drivers/skyCorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from lsst.pex.config import Config, Field, ConfigurableField, ConfigField
from lsst.ctrl.pool.pool import Pool
from lsst.ctrl.pool.parallel import BatchPoolTask
from lsst.pipe.drivers.background import SkyMeasurementTask, FocalPlaneBackground, FocalPlaneBackgroundConfig
from lsst.pipe.drivers.background import SkyMeasurementTask, FocalPlaneBackground, FocalPlaneBackgroundConfig, MaskObjectsTask
import lsst.pipe.drivers.visualizeVisit as visualizeVisit

DEBUG = False # Debugging outputs?
Expand Down Expand Up @@ -42,20 +42,18 @@ class SkyCorrectionConfig(Config):
"""Configuration for SkyCorrectionTask"""
bgModel = ConfigField(dtype=FocalPlaneBackgroundConfig, doc="Background model")
sky = ConfigurableField(target=SkyMeasurementTask, doc="Sky measurement")
detection = ConfigurableField(target=measAlg.SourceDetectionTask, doc="Detection configuration")
doDetection = Field(dtype=bool, default=True, doc="Detect sources (to find good sky)?")
detectSigma = Field(dtype=float, default=5.0, doc="Detection PSF gaussian sigma")
maskObjects = ConfigurableField(target=MaskObjectsTask, doc="Mask Objects")
doMaskObjects = Field(dtype=bool, default=True, doc="Mask objects to find good sky?")
doBgModel = Field(dtype=bool, default=True, doc="Do background model subtraction?")
doSky = Field(dtype=bool, default=True, doc="Do sky frame subtraction?")
binning = Field(dtype=int, default=8, doc="Binning factor for constructing focal-plane images")

def setDefaults(self):
Config.setDefaults(self)
self.detection.reEstimateBackground = False
self.detection.thresholdPolarity = "both"
self.detection.doTempLocalBackground = False
self.detection.thresholdType = "pixel_stdev"
self.detection.thresholdValue = 3.0
self.maskObjects.doInterpolate = False

def validate(self):
assert not self.maskObjects.doInterpolate

class SkyCorrectionTask(BatchPoolTask):
"""Correct sky over entire focal plane"""
Expand All @@ -64,9 +62,8 @@ class SkyCorrectionTask(BatchPoolTask):

def __init__(self, *args, **kwargs):
BatchPoolTask.__init__(self, *args, **kwargs)
self.makeSubtask("maskObjects")
self.makeSubtask("sky")
# Disposable schema suppresses warning from SourceDetectionTask.__init__
self.makeSubtask("detection", schema=afwTable.Schema())

@classmethod
def _makeArgumentParser(cls, *args, **kwargs):
Expand Down Expand Up @@ -187,15 +184,6 @@ def loadImage(self, cache, dataId):
bgOld = cache.butler.get("calexpBackground", dataId, immediate=True)
image = cache.exposure.getMaskedImage()

if self.config.doDetection:
# We deliberately use the specified 'detectSigma' instead of the PSF, in order to better pick up
# the faint wings of objects.
results = self.detection.detectFootprints(cache.exposure, doSmooth=True,
sigma=self.config.detectSigma, clearMask=True)
if hasattr(results, "background") and results.background:
# Restore any background that was removed during detection
maskedImage += results.background.getImage()

# We're removing the old background, so change the sense of all its components
for bgData in bgOld:
statsImage = bgData[0].getStatsImage()
Expand All @@ -206,6 +194,9 @@ def loadImage(self, cache, dataId):
for bgData in bgOld:
cache.bgList.append(bgData)

if self.config.doMaskObjects:
self.maskObjects.run(cache.exposure)

return self.collect(cache)

def measureSkyFrame(self, cache, dataId):
Expand Down

0 comments on commit 773e3a2

Please sign in to comment.