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-10096 Add unit test asserts for SpherePoint, SpherePointList and PointList #73

Merged
merged 4 commits into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions tests/testBinnedWcs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python
#
# LSST Data Management System
#
# Copyright 2008-2016 AURA/LSST.
# Copyright 2008-2017 AURA/LSST.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
Expand Down Expand Up @@ -48,7 +47,7 @@ def assertPointEqual(self, p, q, places=6):
self.assertAlmostEqual(p.getY(), q.getY(), places=places)

def assertWcs(self, origWcs, binnedWcs, xBin, yBin, x0, y0, size=1000):
self.assertAnglesNearlyEqual(binnedWcs.pixelScale(), origWcs.pixelScale()*math.sqrt(xBin*yBin))
self.assertAnglesAlmostEqual(binnedWcs.pixelScale(), origWcs.pixelScale()*math.sqrt(xBin*yBin))
for xOrig, yOrig in itertools.product((x0, x0 + size), (y0, y0 + size)):
orig = afwGeom.Point2D(xOrig, yOrig)
binned = afwGeom.Point2D(float(xOrig - x0)/xBin, float(yOrig - y0)/yBin)
Expand Down Expand Up @@ -90,6 +89,7 @@ class TestMemory(lsst.utils.tests.MemoryTestCase):
def setup_module(module):
lsst.utils.tests.init()


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main()
12 changes: 7 additions & 5 deletions tests/testCoaddBoundedField.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 LSST Corporation.
# Copyright 2008-2017 LSST Corporation.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
Expand Down Expand Up @@ -122,8 +122,8 @@ def testEvaluate(self):

if False: # enable this to see a plot of the comparison (but it will always fail, since
# it doesn't take into account the artifacts in coaddImage)
self.assertClose(fieldImage.getArray(), coaddImage.getArray(), plotOnFailure=True,
rtol=rtol, atol=atol, relTo=relTo)
self.assertFloatsAlmostEqual(fieldImage.getArray(), coaddImage.getArray(), plotOnFailure=True,
rtol=rtol, atol=atol, relTo=relTo)

self.assertLess(bad.sum(), 0.10*self.bbox.getArea())

Expand All @@ -137,8 +137,9 @@ def testPersistence(self):
image2 = lsst.afw.image.ImageD(self.bbox)
field1.fillImage(image1)
field2.fillImage(image2)
# use assertClose for array support, not fuzziness; this test should be exact
self.assertClose(image1.getArray(), image2.getArray(), rtol=0.0, atol=0.0, plotOnFailure=True)
# use assertFloatsAlmostEqual for array support, not fuzziness; this test should be exact
self.assertFloatsAlmostEqual(image1.getArray(), image2.getArray(), rtol=0.0, atol=0.0,
plotOnFailure=True)
os.remove(filename)

def tearDown(self):
Expand All @@ -154,6 +155,7 @@ class TestMemory(lsst.utils.tests.MemoryTestCase):
def setup_module(module):
lsst.utils.tests.init()


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main()
17 changes: 4 additions & 13 deletions tests/testCoaddPsf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python
#
# LSST Data Management System
#
# Copyright 2008-2016 AURA/LSST.
# Copyright 2008-2017 AURA/LSST.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
Expand Down Expand Up @@ -36,9 +35,6 @@
import lsst.utils.tests


#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


def getPsfMoments(psf, point):
# import os, pdb; print "PID =", os.getpid(); pdb.set_trace()
image = psf.computeImage(point)
Expand Down Expand Up @@ -137,7 +133,6 @@ def tearDown(self):
del self.weightKey
del self.mycatalog

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# This is a test which checks to see that all of the ExposureCatalog rows are correctly
# ingested by the CoaddPsf constructor, and that they can be read back in the right order
# and with the right values
Expand Down Expand Up @@ -220,8 +215,6 @@ def testFractionalPixel(self):
self.assertAlmostEqual(x0+xbar, cx0+cxbar, delta=0.01)
self.assertAlmostEqual(y0+ybar, cy0+cybar, delta=0.01)

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

def testRotatePsf(self):
"""Check that we can create a CoaddPsf with 10 elements."""
print("RotatePsfTest")
Expand Down Expand Up @@ -306,7 +299,7 @@ def testSimpleGaussian(self):
bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(2000, 2000))
record.setBBox(bbox)
self.mycatalog.append(record)
#img = psf.computeImage(afwGeom.Point2D(1000,1000), afwGeom.Extent2I(100,100), False, False)
# img = psf.computeImage(afwGeom.Point2D(1000,1000), afwGeom.Extent2I(100,100), False, False)
# img.writeFits("img%d.fits"%i)

mypsf = measAlg.CoaddPsf(self.mycatalog, self.wcsref) # , 'weight')
Expand All @@ -320,7 +313,6 @@ def testSimpleGaussian(self):
self.assertAlmostEqual(m1, m1coadd, delta=0.01)


#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# This test checks to be sure that the weights are being applied correctly in doComputeImage
# Since the 2nd moments are linear in the function value, we can simply weight the moments
# and be sure that the resulting moments are correct
Expand Down Expand Up @@ -460,7 +452,7 @@ def testGoodPix(self):

mypsf = measAlg.CoaddPsf(mycatalog, self.wcsref, 'weight')
predPos = afwGeom.Point2D(xwsum/wsum, ywsum/wsum)
self.assertPairsNearlyEqual(predPos, mypsf.getAveragePosition())
self.assertPairsAlmostEqual(predPos, mypsf.getAveragePosition())

def testBBox(self):
"""Check that we can measure a single Gaussian's attributes."""
Expand All @@ -485,8 +477,6 @@ def testBBox(self):

self.assertEqual(mypsf.computeKernelImage().getBBox(), mypsf.computeBBox())

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


class TestMemory(lsst.utils.tests.MemoryTestCase):
pass
Expand All @@ -495,6 +485,7 @@ class TestMemory(lsst.utils.tests.MemoryTestCase):
def setup_module(module):
lsst.utils.tests.init()


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main()
9 changes: 5 additions & 4 deletions tests/testSdssShapePsf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 AURA/LSST.
# Copyright 2008-2017 AURA/LSST.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
Expand Down Expand Up @@ -104,9 +104,9 @@ def _runMeasurementTask(self, psf=None):
return exposure, catalog

def _checkPsfShape(self, result, psfResult, psfTruth):
self.assertClose(psfResult.getIxx(), psfTruth.getIxx(), rtol=1E-4)
self.assertClose(psfResult.getIyy(), psfTruth.getIyy(), rtol=1E-4)
self.assertClose(psfResult.getIxy(), psfTruth.getIxy(), rtol=1E-4)
self.assertFloatsAlmostEqual(psfResult.getIxx(), psfTruth.getIxx(), rtol=1E-4)
self.assertFloatsAlmostEqual(psfResult.getIyy(), psfTruth.getIyy(), rtol=1E-4)
self.assertFloatsAlmostEqual(psfResult.getIxy(), psfTruth.getIxy(), rtol=1E-4)
self.assertFalse(result.getFlag(measBase.SdssShapeAlgorithm.PSF_SHAPE_BAD.number))

def testMeasureGoodPsf(self):
Expand Down Expand Up @@ -146,6 +146,7 @@ class TestMemory(lsst.utils.tests.MemoryTestCase):
def setup_module(module):
lsst.utils.tests.init()


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main()