-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-17426 #1
base: master
Are you sure you want to change the base?
DM-17426 #1
Changes from 2 commits
7ce5656
b2ebc0a
832078c
773e3a2
a078e08
876d95d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,10 @@ | |
import lsst.afw.image as afwImage | ||
import lsst.afw.geom as afwGeom | ||
import lsst.afw.cameraGeom as afwCameraGeom | ||
import lsst.meas.algorithms as measAlg | ||
import lsst.afw.table as afwTable | ||
|
||
from lsst.pex.config import Config, Field, ListField, ChoiceField, ConfigField, RangeField | ||
from lsst.pex.config import Config, Field, ListField, ChoiceField, ConfigField, RangeField, ConfigurableField | ||
from lsst.pipe.base import Task | ||
|
||
|
||
|
@@ -284,7 +286,9 @@ def measureScale(self, image, skyBackground): | |
statistic = afwMath.stringToStatisticsProperty(self.config.stats.statistic) | ||
imageSamples = [] | ||
skySamples = [] | ||
for xStart, yStart, xStop, yStop in zip(xLimits[:-1], yLimits[:-1], xLimits[1:], yLimits[1:]): | ||
for xIndex, yIndex in itertools.product(range(self.config.xNumSamples), range(self.config.yNumSamples)): | ||
xStart, xStop = xLimits[xIndex : xIndex + 2] | ||
yStart, yStop = yLimits[yIndex : yIndex + 2] | ||
box = afwGeom.Box2I(afwGeom.Point2I(xStart, yStart), afwGeom.Point2I(xStop, yStop)) | ||
subImage = image.Factory(image, box) | ||
subSky = sky.Factory(sky, box) | ||
|
@@ -721,3 +725,63 @@ def getStatsImage(self): | |
return values | ||
|
||
|
||
class MaskObjectsConfig(Config): | ||
"""Configuration for MaskObjectsTask""" | ||
nIter = Field(doc="Iteration for masking", dtype=int, default=3) | ||
subtractBackground = ConfigurableField(target=measAlg.SubtractBackgroundTask, doc='Background configuration') | ||
detection = ConfigurableField(target=measAlg.SourceDetectionTask, doc="Detection configuration") | ||
detectSigma = Field(dtype=float, default=5., doc='Detection PSF gaussian sigmas') | ||
doInterpolate = Field(dtype=bool, default=True, doc='Interpolate masked region?') | ||
interpolate = ConfigurableField(target=measAlg.SubtractBackgroundTask, doc='Interpolate configuration') | ||
|
||
def setDefaults(self): | ||
self.detection.reEstimateBackground = False | ||
self.detection.doTempLocalBackground = False | ||
self.detection.doTempWideBackground = False | ||
self.detection.thresholdValue = 2.5 | ||
# self.detection.thresholdPolarity = "both" | ||
self.subtractBackground.binSize = 1024 | ||
self.subtractBackground.useApprox = False | ||
self.interpolate.binSize = 256 | ||
self.interpolate.useApprox = False | ||
|
||
def validate(self): | ||
assert not self.detection.reEstimateBackground | ||
assert not self.detection.doTempLocalBackground | ||
assert not self.detection.doTempWideBackground | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you change these into |
||
|
||
|
||
class MaskObjectsTask(Task): | ||
"""MaskObjectsTask | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need a better short summary than the name of the task. Maybe "Iterative masking of objects on an image"? |
||
|
||
This task makes more exhaustive object mask by iteratively doing detection and background-subtraction. | ||
michitaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The purpose of this task is to get true background removing faint tails of large objects. | ||
This is useful to make clean SKY from relatively small number of visits. | ||
|
||
We deliberately use the specified 'detectSigma' instead of the PSF, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put
|
||
in order to better pick up the faint wings of objects. | ||
""" | ||
ConfigClass = MaskObjectsConfig | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(MaskObjectsTask, self).__init__(*args, **kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Python 3, so just need |
||
# Disposable schema suppresses warning from SourceDetectionTask.__init__ | ||
self.makeSubtask("detection", schema=afwTable.Schema()) | ||
self.makeSubtask('interpolate') | ||
self.makeSubtask('subtractBackground') | ||
|
||
def run(self, exp): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a numpydoc docstring: https://developer.lsst.io/python/numpydoc.html |
||
for i in range(self.config.nIter): | ||
self.log.info("Masking %d/%d", i + 1, self.config.nIter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be |
||
bg = self.subtractBackground.run(exp).background | ||
fp = self.detection.detectFootprints(exp, sigma=self.config.detectSigma, clearMask=True) | ||
exp.maskedImage += bg.getImage() | ||
|
||
if self.config.doInterpolate: | ||
self.log.info("Interpolating") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
smooth = self.interpolate.run(exp).background | ||
exp.maskedImage += smooth.getImage() | ||
mask = exp.maskedImage.mask | ||
detected = mask.array & mask.getPlaneBitMask(['DETECTED']) > 0 | ||
exp.maskedImage.image.array[detected] = smooth.getImage().getArray()[detected] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code.