Skip to content

Commit

Permalink
Merge pull request #103 from lsst/tickets/DM-36928
Browse files Browse the repository at this point in the history
DM-36928: Avoid deprecated Psf methods
  • Loading branch information
jmeyers314 committed Nov 22, 2022
2 parents 9f262a3 + 50249a6 commit 7748303
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
6 changes: 4 additions & 2 deletions tests/test_cModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ def testNoNoise(self):
self.exposure.getMaskedImage().getVariance().getArray()[:, :] = var
psfImage = self.exposure.getPsf().computeKernelImage(self.xyPosition).getArray()
expectedFluxErr = var**0.5 * (psfImage**2).sum()**(-0.5)
pos = self.exposure.getPsf().getAveragePosition()
result = algorithm.apply(
self.exposure, makeMultiShapeletCircularGaussian(self.psfSigma),
self.xyPosition, self.exposure.getPsf().computeShape()
self.xyPosition, self.exposure.getPsf().computeShape(pos)
)
self.assertFalse(result.initial.flags[result.FAILED])
self.assertFloatsAlmostEqual(result.initial.instFlux, self.trueFlux, rtol=0.01)
Expand Down Expand Up @@ -137,9 +138,10 @@ def testVsPsfFlux(self):
noiseSigma*numpy.random.randn(exposure.getHeight(), exposure.getWidth())
ctrl = lsst.meas.modelfit.CModelControl()
algorithm = lsst.meas.modelfit.CModelAlgorithm(ctrl)
pos = self.exposure.getPsf().getAveragePosition()
cmodel = algorithm.apply(
exposure, makeMultiShapeletCircularGaussian(self.psfSigma),
self.xyPosition, self.exposure.getPsf().computeShape()
self.xyPosition, self.exposure.getPsf().computeShape(pos)
)
psfFlux, psfFluxErr = computePsfFlux(self.xyPosition, exposure)
self.assertFloatsAlmostEqual(psfFlux, cmodel.instFlux, rtol=0.1/fluxFactor**0.5)
Expand Down
16 changes: 9 additions & 7 deletions tests/test_doubleShapeletPsfApprox.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def checkBounds(self, msf):
These requirements must be true after a call to any fit method or measure().
"""
pos = self.psf.getAveragePosition()
self.assertEqual(len(msf.getComponents()), 2)
self.assertEqual(
lsst.shapelet.computeSize(self.ctrl.innerOrder),
Expand All @@ -97,11 +98,11 @@ def checkBounds(self, msf):
len(msf.getComponents()[1].getCoefficients())
)
self.assertGreater(
self.ctrl.maxRadiusBoxFraction * (self.psf.computeKernelImage().getBBox().getArea())**0.5,
self.ctrl.maxRadiusBoxFraction * (self.psf.computeKernelImage(pos).getBBox().getArea())**0.5,
lsst.afw.geom.ellipses.Axes(msf.getComponents()[0].getEllipse().getCore()).getA()
)
self.assertGreater(
self.ctrl.maxRadiusBoxFraction * (self.psf.computeKernelImage().getBBox().getArea())**0.5,
self.ctrl.maxRadiusBoxFraction * (self.psf.computeKernelImage(pos).getBBox().getArea())**0.5,
lsst.afw.geom.ellipses.Axes(msf.getComponents()[1].getEllipse().getCore()).getA()
)
self.assertLess(
Expand Down Expand Up @@ -139,7 +140,8 @@ def checkRatios(self, msf):
def makeImages(self, msf):
"""Return an Image of the data and an Image of the model for comparison.
"""
dataImage = self.exposure.getPsf().computeKernelImage()
pos = self.exposure.getPsf().getAveragePosition()
dataImage = self.exposure.getPsf().computeKernelImage(pos)
modelImage = dataImage.Factory(dataImage.getBBox())
msf.evaluate().addToImage(modelImage)
return dataImage, modelImage
Expand Down Expand Up @@ -218,7 +220,7 @@ def testFitMoments(self):
correctly.
"""
MOMENTS_RTOL = 1E-13
image = self.psf.computeKernelImage()
image = self.psf.computeKernelImage(self.psf.getAveragePosition())
array = image.getArray()
bbox = image.getBBox()
x, y = numpy.meshgrid(
Expand All @@ -245,7 +247,7 @@ def testFitMoments(self):
def testObjective(self):
"""Test that model evaluation agrees with derivative evaluation in the objective object.
"""
image = self.psf.computeKernelImage()
image = self.psf.computeKernelImage(self.psf.getAveragePosition())
msf = self.Algorithm.initializeResult(self.ctrl)
self.Algorithm.fitMoments(msf, self.ctrl, image)
moments = msf.evaluate().computeMoments()
Expand Down Expand Up @@ -286,7 +288,7 @@ def testFitProfile(self):
"""Test that fitProfile() does not modify the ellipticity, that it improves the fit, and
that small perturbations to the zeroth-order amplitudes and radii do not improve the fit.
"""
image = self.psf.computeKernelImage()
image = self.psf.computeKernelImage(self.psf.getAveragePosition())
msf = self.Algorithm.initializeResult(self.ctrl)
self.Algorithm.fitMoments(msf, self.ctrl, image)
prev = lsst.shapelet.MultiShapeletFunction(msf)
Expand Down Expand Up @@ -328,7 +330,7 @@ def testFitShapelets(self):
that it improves the fit, and that small perturbations to the higher-order coefficients
do not improve the fit.
"""
image = self.psf.computeKernelImage()
image = self.psf.computeKernelImage(self.psf.getAveragePosition())
msf = self.Algorithm.initializeResult(self.ctrl)
self.Algorithm.fitMoments(msf, self.ctrl, image)
self.Algorithm.fitProfile(msf, self.ctrl, image)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_generalShapeletPsfApproxPlugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def tearDown(self):
def checkResult(self, msf):
# Because we're fitting multiple shapelets to a single Gaussian (a single 0th-order shapelet)
# we should be able to fit with zero residuals, aside from (single-precision) round-off error.
dataImage = self.exposure.getPsf().computeImage()
pos = self.exposure.getPsf().getAveragePosition()
dataImage = self.exposure.getPsf().computeImage(pos)
modelImage = dataImage.Factory(dataImage.getBBox())
modelImage.getArray()[:, :] *= -1
msf.evaluate().addToImage(modelImage)
Expand Down

0 comments on commit 7748303

Please sign in to comment.