Skip to content
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-42121: Restore missing fakes when using preconvolution #289

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 13 additions & 8 deletions python/lsst/ip/diffim/subtractImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,16 @@ class AlardLuptonSubtractBaseConfig(lsst.pex.config.Config):
default=("sky_source", "slot_Centroid_flag",
"slot_ApFlux_flag", "slot_PsfFlux_flag", ),
)
badMaskPlanes = lsst.pex.config.ListField(
excludeMaskPlanes = lsst.pex.config.ListField(
dtype=str,
default=("NO_DATA", "BAD", "SAT", "EDGE", "FAKE"),
doc="Mask planes to exclude when selecting sources for PSF matching."
)
badMaskPlanes = lsst.pex.config.ListField(
dtype=str,
default=("NO_DATA", "BAD", "SAT", "EDGE"),
doc="Mask planes to interpolate over."
)
preserveTemplateMask = lsst.pex.config.ListField(
dtype=str,
default=("NO_DATA", "BAD", "SAT", "FAKE", "INJECTED", "INJECTED_CORE"),
Expand Down Expand Up @@ -749,7 +754,7 @@ def _sourceSelector(self, sources, mask):
self.log.warning("Could not apply source flag: %s", e)
sToNFlag = (sources.getPsfInstFlux()/sources.getPsfInstFluxErr()) > self.config.detectionThreshold
flags *= sToNFlag
flags *= self._checkMask(mask, sources, self.config.badMaskPlanes)
flags *= self._checkMask(mask, sources, self.config.excludeMaskPlanes)
selectSources = sources[flags]
self.log.info("%i/%i=%.1f%% of sources selected for PSF matching from the input catalog",
len(selectSources), len(sources), 100*len(selectSources)/len(sources))
Expand All @@ -763,7 +768,7 @@ def _sourceSelector(self, sources, mask):
return selectSources.copy(deep=True)

@staticmethod
def _checkMask(mask, sources, badMaskPlanes):
def _checkMask(mask, sources, excludeMaskPlanes):
"""Exclude sources that are located on masked pixels.

Parameters
Expand All @@ -773,7 +778,7 @@ def _checkMask(mask, sources, badMaskPlanes):
based on the location of their centroid on the ccd.
sources : `lsst.afw.table.SourceCatalog`
The source catalog to evaluate.
badMaskPlanes : `list` of `str`
excludeMaskPlanes : `list` of `str`
List of the names of the mask planes to exclude.

Returns
Expand All @@ -783,17 +788,17 @@ def _checkMask(mask, sources, badMaskPlanes):
kept (True) or rejected (False) based on the value of the
mask plane at its location.
"""
setBadMaskPlanes = [
maskPlane for maskPlane in badMaskPlanes if maskPlane in mask.getMaskPlaneDict()
setExcludeMaskPlanes = [
maskPlane for maskPlane in excludeMaskPlanes if maskPlane in mask.getMaskPlaneDict()
]

badPixelMask = mask.getPlaneBitMask(setBadMaskPlanes)
excludePixelMask = mask.getPlaneBitMask(setExcludeMaskPlanes)

xv = np.rint(sources.getX() - mask.getX0())
yv = np.rint(sources.getY() - mask.getY0())

mv = mask.array[yv.astype(int), xv.astype(int)]
flags = np.bitwise_and(mv, badPixelMask) == 0
flags = np.bitwise_and(mv, excludePixelMask) == 0
return flags

def _prepareInputs(self, template, science, visitSummary=None):
Expand Down