Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-41700: Deprecate Naive Centroid #372

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
113 changes: 0 additions & 113 deletions tests/test_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,119 +63,6 @@ def toString(*args):
return "%d: %d..%d" % (y, x0, x1)


class MeasureTestCase(lsst.utils.tests.TestCase):
"""A test case for Measure"""
class Object:

def __init__(self, val, spans):
self.val = val
self.spans = spans

def insert(self, im, dx=0, dy=0):
"""Insert self into an image"""
for sp in self.spans:
y, x0, x1 = sp
for x in range(x0, x1 + 1):
im[x + dx, y + dy, afwImage.LOCAL] = self.val

def __eq__(self, other):
for osp, sp in zip(other.getSpans(), self.spans):
if osp.toString() != toString(sp):
return False

return True

def setUp(self):
ms = afwImage.MaskedImageF(lsst.geom.ExtentI(31, 27))
ms.getVariance().set(1)
bbox = lsst.geom.BoxI(lsst.geom.PointI(1, 1), lsst.geom.ExtentI(24, 20))
self.mi = afwImage.MaskedImageF(ms, bbox, afwImage.LOCAL)
self.exposure = afwImage.makeExposure(self.mi)
im = self.mi.getImage()
#
# Objects that we should detect. These are coordinates in the subimage
#
self.objects = []
self.objects += [self.Object(10, [(1, 4, 4), (2, 3, 5), (3, 4, 4)])]
self.objects += [self.Object(20, [(5, 7, 8), (5, 10, 10), (6, 8, 9)])]
self.objects += [self.Object(20, [(8, 3, 3)])]

im.set(0) # clear image
for obj in self.objects:
obj.insert(im, 5, 5)
#
# Add a few more pixels to make peaks that we can centroid around
#
for x, y in [(9, 7), (13, 11)]:
im[x, y, afwImage.LOCAL] += 1

def tearDown(self):
del self.mi
del self.exposure

def testFootprintsMeasure(self):
"""Check that we can measure the objects in a detectionSet"""

xcentroid = [10.0, 14.0, 9.0]
ycentroid = [8.0, 11.5061728, 14.0]
flux = [51.0, 101.0, 20.0]
# sqrt of num pixels in aperture; note the second source is offset
# from the pixel grid.
fluxErr = [math.sqrt(29), math.sqrt(26), math.sqrt(29)]

footprints = afwDetection.FootprintSet(self.mi, afwDetection.Threshold(10), "DETECTED")

if display:
disp = afwDisplay.Display(frame=0)
disp.mtv(self.mi, title=self._testMethodName + ": image")
afwDisplay.Display(frame=1).mtv(self.mi.getVariance(), title=self._testMethodName + ": variance")

measureSourcesConfig = measBase.SingleFrameMeasurementConfig()
measureSourcesConfig.algorithms["base_CircularApertureFlux"].radii = [3.0]
# Numerical tests below assumes that we are not using sinc fluxes.
measureSourcesConfig.algorithms["base_CircularApertureFlux"].maxSincRadius = 0.0
measureSourcesConfig.algorithms.names = ["base_NaiveCentroid", "base_SdssShape", "base_PsfFlux",
"base_CircularApertureFlux"]
measureSourcesConfig.slots.centroid = "base_NaiveCentroid"
measureSourcesConfig.slots.psfFlux = "base_PsfFlux"
measureSourcesConfig.slots.apFlux = "base_CircularApertureFlux_3_0"
measureSourcesConfig.slots.modelFlux = None
measureSourcesConfig.slots.gaussianFlux = None
measureSourcesConfig.slots.calibFlux = None

schema = afwTable.SourceTable.makeMinimalSchema()
task = measBase.SingleFrameMeasurementTask(schema, config=measureSourcesConfig)
measCat = afwTable.SourceCatalog(schema)
footprints.makeSources(measCat)
# now run the SFM task with the test plugin
sigma = 1e-10
psf = algorithms.DoubleGaussianPsf(11, 11, sigma) # i.e. a single pixel
self.exposure.setPsf(psf)
task.run(measCat, self.exposure)

self.assertEqual(len(measCat), len(flux))
for i, source in enumerate(measCat):

xc, yc = source.getX(), source.getY()
if display:
disp.dot("+", xc, yc)

self.assertAlmostEqual(source.getX(), xcentroid[i], 6)
self.assertAlmostEqual(source.getY(), ycentroid[i], 6)
self.assertEqual(source.getApInstFlux(), flux[i])
self.assertAlmostEqual(source.getApInstFluxErr(), fluxErr[i], 6)

# We're using a delta-function PSF, so the psfFlux should be the
# pixel under the centroid, iff the object's centred in the pixel
if xc == int(xc) and yc == int(yc):
self.assertAlmostEqual(source.getPsfInstFlux(),
self.exposure.getMaskedImage().getImage()[int(xc + 0.5),
int(yc + 0.5)])
self.assertAlmostEqual(source.getPsfInstFluxErr(),
self.exposure.getMaskedImage().getVariance()[int(xc + 0.5),
int(yc + 0.5)])


class FindAndMeasureTestCase(lsst.utils.tests.TestCase):
"""A test case detecting and measuring objects."""

Expand Down