Skip to content

Commit

Permalink
Update dipole edge test case
Browse files Browse the repository at this point in the history
  • Loading branch information
mrawls committed Oct 30, 2024
1 parent 342a1b6 commit d78d8f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
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

0 comments on commit d78d8f3

Please sign in to comment.