Coverage for tests/test_centroid.py : 26%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This file is part of meas_base. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (https://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>.
"""A test case for centroiding. """
pass
pass
"""Test that tearDown does""" pass
"""Test that we can instantiate and play with a centroiding algorithm. """
schema = afwTable.SourceTable.makeMinimalSchema() schema.getAliasMap().set("slot_Centroid", "test") centroider = alg(control, "test", schema) table = afwTable.SourceCatalog(schema)
x0, y0 = 12345, 54321 for imageFactory in (afwImage.MaskedImageF,):
im = imageFactory(lsst.geom.ExtentI(100, 100)) im.setXY0(lsst.geom.Point2I(x0, y0))
# This fixed DoubleGaussianPsf replaces a computer generated one. # The values are not anything in particular, just a reasonable size. psf = afwDetection.GaussianPsf(15, 15, 3.0) exp = afwImage.makeExposure(im) exp.setPsf(psf)
im.set(bkgd) x, y = 30, 20 im.image[x, y, afwImage.LOCAL] = 1010
source = table.addNew() spans = afwGeom.SpanSet(exp.getBBox(afwImage.LOCAL)) foot = afwDetection.Footprint(spans) foot.addPeak(x + x0, y + y0, 1010) source.setFootprint(foot) centroider.measure(source, exp)
self.assertFloatsAlmostEqual(x + x0, source.getX(), rtol=.00001) self.assertFloatsAlmostEqual(y + y0, source.getY(), rtol=.00001) self.assertFalse(source.get("test_flag"))
im.set(bkgd) im.image[10, 20, afwImage.LOCAL] = 1010 im.image[10, 21, afwImage.LOCAL] = 1010 im.image[11, 20, afwImage.LOCAL] = 1010 im.image[11, 21, afwImage.LOCAL] = 1010
x, y = 10.5 + x0, 20.5 + y0 source = table.addNew() source.set('test_x', x) source.set('test_y', y) centroider.measure(source, exp) self.assertFloatsAlmostEqual(x, source.getX(), rtol=.00001) self.assertFloatsAlmostEqual(y, source.getY(), rtol=.00001) self.assertFalse(source.get("test_flag"))
"""Test that we can instantiate and play with naive centroids. """ bkgd = 10.0 afwTable.SourceTable.makeMinimalSchema() control = measBase.NaiveCentroidControl() control.background = bkgd control.doFootprintCheck = False self.do_testAstrometry(measBase.NaiveCentroidAlgorithm, bkgd, control)
"""Test that we can instantiate and play with SDSS centroids""" control = measBase.SdssCentroidControl() control.doFootprintCheck = False self.do_testAstrometry(measBase.SdssCentroidAlgorithm, 10.0, control)
"""A test case for the SingleFrameMeasurementTask. """
msConfig = measBase.SingleFrameMeasurementConfig() msConfig.algorithms.names = ["base_SdssCentroid"] msConfig.slots.centroid = "base_SdssCentroid" msConfig.slots.shape = None msConfig.slots.psfShape = None msConfig.slots.apFlux = None msConfig.slots.modelFlux = None msConfig.slots.psfFlux = None msConfig.slots.gaussianFlux = None msConfig.slots.calibFlux = None schema = afwTable.SourceTable.makeMinimalSchema() task = measBase.SingleFrameMeasurementTask(schema, config=msConfig) measCat = afwTable.SourceCatalog(schema)
source = measCat.addNew() spans = afwGeom.SpanSet(self.exp.getBBox(afwImage.LOCAL)) fp = afwDetection.Footprint(spans) fp.addPeak(50, 50, 1000.0) source.setFootprint(fp) # Then run the default SFM task. Results not checked task.run(measCat, self.exp) return source
"""Make the image we'll measure. """
self.exp = afwImage.ExposureF(100, 100) psf = afwDetection.GaussianPsf(15, 15, 3.0) self.exp.setPsf(psf) self.I0, self.xcen, self.ycen = 1000.0, 50.5, 50.0 im = self.exp.getMaskedImage().getImage()
for i in (-1, 0, 1): for j in (-1, 0, 1): im[int(self.xcen) + i, int(self.ycen) + j, afwImage.LOCAL] = \ self.I0*(1 - 0.5*math.hypot(i - 0.5, j))
del self.exp
"""Measure the centroid. """ s = self.mySetup()
# this does not match exactly, and it used to self.assertFloatsAlmostEqual(s.getCentroid(), lsst.geom.PointD(self.xcen, self.ycen), rtol=.01)
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |