def run(self, dataRef): image = dataRef.get("starfield_image", immediate=True) nx = image.getWidth()/3-1 ny = image.getWidth()/3-1 # extract only the lower-left image bbox = lsst.afw.geom.Box2I(lsst.afw.geom.Point2I(0,0), lsst.afw.geom.Extent2I(nx, ny)) image = image[bbox].convertD() # shift by half a pixel in both directions, so it's centered on a pixel image = lsst.afw.math.offsetImage(image, -0.5, -0.5) assert image.getWidth() == nx assert image.getHeight() == ny kernel = lsst.afw.math.FixedKernel(image) return lsst.meas.algorithms.KernelPsf(kernel)
def testObjective(self): """Test that model evaluation agrees with derivative evaluation in the objective object. """ image = self.psf.computeKernelImage() msf = self.Algorithm.initializeResult(self.ctrl) self.Algorithm.fitMoments(msf, self.ctrl, image) moments = msf.evaluate().computeMoments() r0 = moments.getCore().getDeterminantRadius() objective = self.Algorithm.makeObjective(moments, self.ctrl, image) image, model = self.makeImages(msf) parameters = numpy.zeros(4, dtype=float) parameters[0] = msf.getComponents()[0].getCoefficients()[0] parameters[1] = msf.getComponents()[1].getCoefficients()[0] parameters[2] = msf.getComponents()[0].getEllipse().getCore( ).getDeterminantRadius() / r0 parameters[3] = msf.getComponents()[1].getEllipse().getCore( ).getDeterminantRadius() / r0 residuals = numpy.zeros(image.getArray().size, dtype=float) objective.computeResiduals(parameters, residuals) return msf self.assertFloatsAlmostEqual( residuals.reshape(image.getHeight(), image.getWidth()), image.getArray() - model.getArray()) step = 1E-6 derivatives = numpy.zeros((parameters.size, residuals.size), dtype=float).transpose() objective.differentiateResiduals(parameters, derivatives) for i in range(parameters.size): original = parameters[i] r1 = numpy.zeros(residuals.size, dtype=float) r2 = numpy.zeros(residuals.size, dtype=float) parameters[i] = original + step objective.computeResiduals(parameters, r1) parameters[i] = original - step objective.computeResiduals(parameters, r2) parameters[i] = original d = (r1 - r2) / (2.0 * step) self.assertFloatsAlmostEqual(d.reshape(image.getHeight(), image.getWidth()), derivatives[:, i].reshape( image.getHeight(), image.getWidth()), atol=1E-11)
def testObjective(self): """Test that model evaluation agrees with derivative evaluation in the objective object. """ image = self.psf.computeKernelImage() msf = self.Algorithm.initializeResult(self.ctrl) self.Algorithm.fitMoments(msf, self.ctrl, image) moments = msf.evaluate().computeMoments() r0 = moments.getCore().getDeterminantRadius() objective = self.Algorithm.makeObjective(moments, self.ctrl, image) image, model = self.makeImages(msf) parameters = numpy.zeros(4, dtype=float) parameters[0] = msf.getComponents()[0].getCoefficients()[0] parameters[1] = msf.getComponents()[1].getCoefficients()[0] parameters[2] = msf.getComponents()[0].getEllipse().getCore().getDeterminantRadius() / r0 parameters[3] = msf.getComponents()[1].getEllipse().getCore().getDeterminantRadius() / r0 residuals = numpy.zeros(image.getArray().size, dtype=float) objective.computeResiduals(parameters, residuals) self.assertFloatsAlmostEqual( residuals.reshape(image.getHeight(), image.getWidth()), image.getArray() - model.getArray() ) step = 1E-6 derivatives = numpy.zeros((parameters.size, residuals.size), dtype=float).transpose() objective.differentiateResiduals(parameters, derivatives) for i in range(parameters.size): original = parameters[i] r1 = numpy.zeros(residuals.size, dtype=float) r2 = numpy.zeros(residuals.size, dtype=float) parameters[i] = original + step objective.computeResiduals(parameters, r1) parameters[i] = original - step objective.computeResiduals(parameters, r2) parameters[i] = original d = (r1 - r2)/(2.0*step) self.assertFloatsAlmostEqual( d.reshape(image.getHeight(), image.getWidth()), derivatives[:, i].reshape(image.getHeight(), image.getWidth()), atol=1E-11 )
def run(self, dataRef, dataType): image = dataRef.get(dataType + "starfield_image", immediate=True) nx = self.config.size - 1 ny = self.config.size - 1 # extract only the lower-left image bbox = lsst.afw.geom.Box2I(lsst.afw.geom.Point2I(0, 0), lsst.afw.geom.Extent2I(nx, ny)) image = image[bbox].convertD() # shift by half a pixel in both directions, so it's centered on a pixel image = lsst.afw.math.offsetImage(image, -0.5, -0.5) assert image.getWidth() == nx assert image.getHeight() == ny kernel = lsst.afw.math.FixedKernel(image) return lsst.meas.algorithms.KernelPsf(kernel)
def testHdu(self): mapper = MinMapper2() butler = dafPersist.ButlerFactory(mapper=mapper).create() # HDU INT_MIN returns primary array (skipping empty PDU) # HDU 0 returns (header-only) PDU # HDU 1 returns first image plane # HDU 2 returns mask plane # HDU 3 returns variance plane for i in (1, 2, 3): loc = mapper.map("other", dict(ccd=35, hdu=i)) expectedLocations = ["bar-35.fits[%d]" % (i,)] self.assertEqual(loc.getStorage().root, ROOT) self.assertEqual(loc.getLocations(), expectedLocations) image = butler.get("other", ccd=35, hdu=i, immediate=True) self.assertIsInstance(image, lsst.afw.image.ImageF) self.assertEqual(image.getHeight(), 2024) self.assertEqual(image.getWidth(), 2248) self.assertEqual(image[200, 25, lsst.afw.image.LOCAL], (0.0, 20.0, 0.0)[i-1]) self.assertAlmostEqual(image[200, 26, lsst.afw.image.LOCAL], (1.20544, 0.0, 5.82185)[i-1], places=5)