Skip to content

Commit

Permalink
Handle edges better WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mrawls committed Oct 29, 2024
1 parent 88d9658 commit b599627
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 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
11 changes: 8 additions & 3 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 Down Expand Up @@ -277,10 +278,14 @@ def testDipoleEdge(self):
not detected.
"""

# Move the dipole extremely close to the edge for this test to pass
dipoleTestImage = DipoleTestImage(xc=[0.2, 0.1], yc=[0.1, 96.5])
# with no edge we should detect 1-2 dipole sources
dipoleTestImage = DipoleTestImage(xc=[5.3, 4.8], yc=[4.6, 96.5], flux=[200, 210], edgeWidth=0)
sources = self._runDetection(dipoleTestImage)
self.assertTrue(len(sources) == 1)

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

def testDipoleFootprintTooLarge(self):
Expand Down

0 comments on commit b599627

Please sign in to comment.