diff --git a/python/lsst/ip/diffim/utils.py b/python/lsst/ip/diffim/utils.py index 6f58f970..ee9d22d3 100644 --- a/python/lsst/ip/diffim/utils.py +++ b/python/lsst/ip/diffim/utils.py @@ -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 @@ -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): @@ -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 diff --git a/tests/test_dipoleFitter.py b/tests/test_dipoleFitter.py index f11caed7..4bf9366a 100644 --- a/tests/test_dipoleFitter.py +++ b/tests/test_dipoleFitter.py @@ -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 @@ -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): @@ -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."""