Skip to content

Commit

Permalink
Update unit test to new Footprint API
Browse files Browse the repository at this point in the history
  • Loading branch information
natelust committed Apr 25, 2017
1 parent 243fcd0 commit cfd38fe
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
6 changes: 4 additions & 2 deletions tests/centroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def do_testAstrometry(self, alg, bkgd, control):
im.set(x, y, (1010,))

source = table.addNew()
foot = afwDetection.Footprint(exp.getBBox(afwImage.LOCAL))
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)
Expand Down Expand Up @@ -145,7 +146,8 @@ def mySetup(self):
measCat = afwTable.SourceCatalog(schema)

source = measCat.addNew()
fp = afwDetection.Footprint(self.exp.getBBox(afwImage.LOCAL))
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
Expand Down
4 changes: 3 additions & 1 deletion tests/testInputCount.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ def testInputCounts(self, showPlot=False):

# Add simulated sources to the measurement catalog.
for src in sources:
foot = afwDetection.Footprint(afwGeom.Point2I(src.pos), 1.0)
spans = afwGeom.SpanSet.fromShape(1)
spans = spans.shiftedBy(int(src.pos.getX()), int(src.pos.getY()))
foot = afwDetection.Footprint(spans)
peak = foot.getPeaks().addNew()
peak.setFx(src.pos[0])
peak.setFy(src.pos[1])
Expand Down
12 changes: 9 additions & 3 deletions tests/testMeasureSources.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ def testPixelFlags(self):
(20, 80, ['edge']),
(30, 30, ['clipped']),
]:
foot = afwDetection.Footprint(afwGeom.Point2I(afwGeom.Point2D(x + x0, y + y0)), 5)
spans = afwGeom.SpanSet.fromShape(5).shiftedBy(x + x0,
y + y0)
foot = afwDetection.Footprint(spans)
source = cat.makeRecord()
source.setFootprint(foot)
source.set("centroid_x", x+x0)
Expand All @@ -276,7 +278,9 @@ def testPixelFlags(self):
source.set("centroid_x", float("NAN"))
source.set("centroid_y", 40)
source.set("centroid_flag", True)
source.setFootprint(afwDetection.Footprint(afwGeom.Point2I(afwGeom.Point2D(x + x0, y + y0)), 5))
tmpSpanSet = afwGeom.SpanSet.fromShape(5).shiftedBy(x + x0,
y + y0)
source.setFootprint(afwDetection.Footprint(tmpSpanSet))
with self.assertRaises(lsst.pex.exceptions.RuntimeError):
plugin.measure(source, exp)
# Test that if there is no center and centroider that the object should look at the footprint
Expand All @@ -286,7 +290,9 @@ def testPixelFlags(self):
with self.assertRaises(lsst.pex.exceptions.RuntimeError):
plugin.measure(source, exp)
# The second test will raise an error because no peaks are present
source.setFootprint(afwDetection.Footprint(afwGeom.Point2I(afwGeom.Point2D(x + x0, y + y0)), 5))
tmpSpanSet2 = afwGeom.SpanSet.fromShape(5).shiftedBy(x + x0,
y + y0)
source.setFootprint(afwDetection.Footprint(tmpSpanSet2))
with self.assertRaises(lsst.pex.exceptions.RuntimeError):
plugin.measure(source, exp)
# The final test should pass because it detects a peak, we are reusing the location of the
Expand Down
3 changes: 2 additions & 1 deletion tests/testNoiseReplacer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#
# LSST Data Management System
# Copyright 2008-2017 LSST Corporation.
Expand Down Expand Up @@ -49,7 +50,7 @@ def measure(self, measRecord, exposure):
footprint = measRecord.getFootprint()
fullArray = exposure.getMaskedImage().getImage().getArray()
insideArray = np.zeros(footprint.getArea(), dtype=fullArray.dtype)
lsst.afw.detection.flattenArray(footprint, fullArray, insideArray, exposure.getXY0())
footprint.spans.flatten(insideArray, fullArray, exposure.getXY0())
insideFlux = float(insideArray.sum())
outsideFlux = float(fullArray.sum()) - insideFlux
measRecord.set(self.insideKey, insideFlux)
Expand Down
4 changes: 3 additions & 1 deletion tests/testSdssCentroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from lsst.meas.base.tests import (AlgorithmTestCase, CentroidTransformTestCase,
SingleFramePluginTransformSetupHelper)
import lsst.afw.geom as afwGeom
import lsst.utils.tests

# n.b. Some tests here depend on the noise realization in the test data
Expand Down Expand Up @@ -124,7 +125,8 @@ def testEdge(self):
# we also need to install a smaller footprint, or NoiseReplacer complains before we even get to
# measuring the centriod
record = catalog[0]
newFootprint = lsst.afw.detection.Footprint(bbox)
spanSet = afwGeom.SpanSet(bbox)
newFootprint = lsst.afw.detection.Footprint(spanSet)
peak = record.getFootprint().getPeaks()[0]
newFootprint.addPeak(peak.getFx(), peak.getFy(), peak.getPeakValue())
record.setFootprint(newFootprint)
Expand Down
4 changes: 3 additions & 1 deletion tests/testVariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ def setUp(self):
task = measBase.SingleFrameMeasurementTask(schema, config=config)
catalog = afwTable.SourceCatalog(schema)

foot = afwDetection.Footprint(afwGeom.Point2I(center), width)
spans = afwGeom.SpanSet.fromShape(int(width))
spans = spans.shiftedBy(int(center.getX()), int(center.getY()))
foot = afwDetection.Footprint(spans)
peak = foot.getPeaks().addNew()
peak.setIx(int(center.getX()))
peak.setIy(int(center.getY()))
Expand Down
19 changes: 11 additions & 8 deletions tests/test_undeblended.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,19 @@ def testUndeblendedMeasurement(self):
parent = cat.addNew()
parent.set("centroid_x", x0 + xCenter)
parent.set("centroid_y", y0 + yCenter)
parent.setFootprint(afwDetection.Footprint(afwGeom.Point2I(x0 + xCenter, y0 + yCenter), radius))
spanSetParent = afwGeom.SpanSet.fromShape(int(radius))
spanSetParent = spanSetParent.shiftedBy(x0 + xCenter, y0 + yCenter)
parent.setFootprint(afwDetection.Footprint(spanSetParent))

# First child is bright, dominating the blend
child1 = cat.addNew()
child1.set("centroid_x", parent.get("centroid_x"))
child1.set("centroid_y", parent.get("centroid_y"))
child1.setParent(parent.getId())
image.set(xCenter, yCenter, (flux1, 0, 0))
foot1 = afwDetection.Footprint(afwGeom.Point2I(x0 + xCenter, y0 + yCenter), 0.1)
spanSetChild1 = afwGeom.SpanSet.fromShape(1)
spanSetChild1 = spanSetChild1.shiftedBy(x0 + xCenter, y0 + yCenter)
foot1 = afwDetection.Footprint(spanSetChild1)
child1.setFootprint(afwDetection.HeavyFootprintF(foot1, image))

# Second child is fainter, but we want to be able to measure it!
Expand All @@ -107,14 +111,13 @@ def testUndeblendedMeasurement(self):
child2.set("centroid_y", parent.get("centroid_y") + yOffset)
child2.setParent(parent.getId())
image.set(xCenter + xOffset, yCenter + yOffset, (flux2, 0, 0))
foot2 = afwDetection.Footprint(afwGeom.Point2I(x0 + xCenter + xOffset, y0 + yCenter + yOffset), 0.1)
spanSetChild2 = afwGeom.SpanSet.fromShape(1)
tmpPoint = (x0 + xCenter + xOffset, y0 + yCenter + yOffset)
spanSetChild2 = spanSetChild2.shiftedBy(*tmpPoint)
foot2 = afwDetection.Footprint(spanSetChild2)
child2.setFootprint(afwDetection.HeavyFootprintF(foot2, image))

spans = []
for ss in foot1.getSpans():
spans.append(ss)
for ss in foot2.getSpans():
spans.append(ss)
spans = foot1.spans.union(foot2.spans)
bbox = afwGeom.Box2I()
bbox.include(foot1.getBBox())
bbox.include(foot2.getBBox())
Expand Down

0 comments on commit cfd38fe

Please sign in to comment.