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-45318: Add NO_DATA to detectAndMeasure's excludeMaskPlanes #345

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion python/lsst/ip/diffim/detectAndMeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,12 @@ def setDefaults(self):
self.detection.thresholdValue = 5.0
self.detection.reEstimateBackground = False
self.detection.thresholdType = "pixel_stdev"
self.detection.excludeMaskPlanes = ["EDGE", "SAT", "BAD", "INTRP"]
self.detection.excludeMaskPlanes = ["EDGE",
"SAT",
"BAD",
"INTRP",
"NO_DATA",
]

self.measurement.plugins.names |= ["ext_trailedSources_Naive",
"base_LocalPhotoCalib",
Expand Down
10 changes: 9 additions & 1 deletion python/lsst/ip/diffim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ class DipoleTestImage:
"""

def __init__(self, w=101, h=101, xcenPos=[27.], ycenPos=[25.], xcenNeg=[23.], ycenNeg=[25.],
psfSigma=2., flux=[30000.], fluxNeg=None, noise=10., gradientParams=None):
psfSigma=2., flux=[30000.], fluxNeg=None, noise=10., gradientParams=None, edgeWidth=8):
self.w = w
self.h = h
self.xcenPos = xcenPos
Expand All @@ -735,6 +735,7 @@ def __init__(self, w=101, h=101, xcenPos=[27.], ycenPos=[25.], xcenNeg=[23.], yc
self.fluxNeg = self.flux
self.noise = noise
self.gradientParams = gradientParams
self.edgeWidth = edgeWidth
self._makeDipoleImage()

def _makeDipoleImage(self):
Expand Down Expand Up @@ -768,6 +769,13 @@ def _makeStarImage(self, xc=[15.3], yc=[18.6], flux=[2500], schema=None, randomS
schema = TestDataset.makeMinimalSchema()
exposure, catalog = dataset.realize(noise=self.noise, schema=schema, randomSeed=randomSeed)

# set EDGE by masking the whole exposure and un-masking an inner bbox
edgeMask = exposure.mask.getPlaneBitMask('EDGE')
exposure.mask.array |= edgeMask
inner_bbox = exposure.getBBox()
inner_bbox.grow(-self.edgeWidth)
exposure[inner_bbox].mask.array &= ~edgeMask

if self.gradientParams is not None:
y, x = np.mgrid[:self.w, :self.h]
gp = self.gradientParams
Expand Down
15 changes: 11 additions & 4 deletions tests/test_dipoleFitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ class DipoleTestImage:
Pixel coordinates between lobes of dipoles.
"""

def __init__(self, xc=None, yc=None, flux=None, offsets=None, gradientParams=None):
def __init__(self, xc=None, yc=None, flux=None, offsets=None, gradientParams=None, edgeWidth=None):
self.xc = xc if xc is not None else [65.3, 24.2]
self.yc = yc if yc is not None else [38.6, 78.5]
self.offsets = offsets if offsets is not None else np.array([-2., 2.])
self.flux = flux if flux is not None else [2500., 2345.]
self.gradientParams = gradientParams if gradientParams is not None else [10., 3., 5.]
self.edgeWidth = edgeWidth if edgeWidth is not None else 8

# The default tolerance for comparisons of fitted parameters with input values.
# Given the noise in the input images (default noise value of 2.), this is a
Expand All @@ -72,7 +73,8 @@ def generateTestImage(self):
ycenNeg=self.yc - self.offsets,
flux=self.flux, fluxNeg=self.flux,
noise=2., # Note the input noise - this affects the relative tolerances used.
gradientParams=self.gradientParams)
gradientParams=self.gradientParams,
edgeWidth=self.edgeWidth)


class DipoleFitTest(lsst.utils.tests.TestCase):
Expand Down Expand Up @@ -277,10 +279,15 @@ def testDipoleEdge(self):
not detected.
"""

dipoleTestImage = DipoleTestImage(xc=[5.3, 4.8], yc=[4.6, 96.5])
# with no edge we should detect both dipole sources
dipoleTestImage = DipoleTestImage(xc=[5.3, 4.8], yc=[4.6, 86.5], flux=[200, 210], edgeWidth=0)
sources = self._runDetection(dipoleTestImage)
self.assertEqual(len(sources), 2)

self.assertTrue(len(sources) == 0)
# with a wide edge we should not detect any sources
dipoleTestImage = DipoleTestImage(xc=[5.3, 4.8], yc=[4.6, 86.5], flux=[200, 210], edgeWidth=20)
sources = self._runDetection(dipoleTestImage)
self.assertEqual(len(sources), 0)

def testDipoleFootprintTooLarge(self):
"""Test that the footprint area cut flags sources."""
Expand Down
Loading