Skip to content

Commit

Permalink
Add from __future__ import absolute_import, division, print_function …
Browse files Browse the repository at this point in the history
…and modernize to python 2
  • Loading branch information
isullivan authored and AstroVPK committed Aug 18, 2016
1 parent 56d3146 commit f9d6802
Show file tree
Hide file tree
Showing 24 changed files with 309 additions and 368 deletions.
18 changes: 8 additions & 10 deletions tests/testAstrometrySourceSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import unittest
import numpy as np

import lsst.utils
from lsst.meas.base.tests import TestDataset as Dataset
import lsst.afw.table as afwTable
from lsst.meas.algorithms import sourceSelector
from lsst.meas.base.tests import TestDataset as Dataset
import lsst.utils.tests


badFlags = ["base_PixelFlags_flag_edge",
Expand All @@ -44,9 +44,8 @@


def add_good_source(src, num=0):
"""Insert a likely-good source into the catalog."""
"""
Insert a likely-good source into the catalog.
num is added to various values to distinguish them in catalogs with multiple objects.
"""
src.addNew()
Expand Down Expand Up @@ -89,7 +88,7 @@ def testSelectSources_bad(self):
self.src[i].set(flag, True)
result = self.sourceSelector.selectSources(self.src)
for i, x in enumerate(self.src['id']):
self.assertNotIn(x, result.sourceCat['id'], "should not have found %s"%badFlags[i])
self.assertNotIn(x, result.sourceCat['id'], "should not have found %s" % badFlags[i])

def testSelectSources_bad_centroid(self):
add_good_source(self.src, 1)
Expand Down Expand Up @@ -140,13 +139,12 @@ def testSelectSources_non_contiguous(self):
self.assertTrue(result.sourceCat.find(x['id']))


# for MemoryTestCase
def setup_module(module):
lsst.utils.tests.init()
class TestMemory(lsst.utils.tests.MemoryTestCase):
pass


class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
pass
def setup_module(module):
lsst.utils.tests.init()

if __name__ == "__main__":
lsst.utils.tests.init()
Expand Down
7 changes: 4 additions & 3 deletions tests/testBinnedWcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import math
import unittest
import itertools

import lsst.utils.tests
import lsst.afw.geom as afwGeom
import lsst.afw.image as afwImage
import lsst.afw.coord as afwCoord
from lsst.meas.algorithms import BinnedWcs
import lsst.utils.tests


class BinnedWcsTest(lsst.utils.tests.TestCase):
Expand Down Expand Up @@ -76,12 +77,12 @@ def testCases(self):
(100, 100, 12345, 6789), # Binning and offset
(4, 7, 9876, 54321), # Different binnings and offset
]:
print "Testing:", xBin, yBin, x0, y0
print("Testing:", xBin, yBin, x0, y0)
binnedWcs = BinnedWcs(self.wcs, xBin, yBin, afwGeom.Point2I(x0, y0))
self.assertWcs(self.wcs, binnedWcs, xBin, yBin, x0, y0)


class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
class TestMemory(lsst.utils.tests.MemoryTestCase):
pass


Expand Down
17 changes: 9 additions & 8 deletions tests/testCoaddApCorrMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import os
import numpy
import numpy as np
import unittest

import lsst.utils
import lsst.afw.geom as afwGeom
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
import lsst.afw.image as afwImage
import lsst.afw.coord as afwCoord
import lsst.meas.algorithms as measAlg
from lsst.afw.geom.polygon import Polygon
import lsst.meas.algorithms as measAlg
import lsst.utils

try:
type(verbose)
Expand All @@ -40,10 +41,10 @@
display = False


class CoaddApCorrMapTest(unittest.TestCase):
class CoaddApCorrMapTest(lsst.utils.tests.TestCase):

def test(self):
"""Check that we can create and use a coadd ApCorrMap"""
def testCoaddApCorrMap(self):
"""Check that we can create and use a coadd ApCorrMap."""
coaddBox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(100, 100))
scale = 5.0e-5 # deg/pix; for CD matrix
coord = afwCoord.Coord(0.0*afwGeom.degrees, 0.0*afwGeom.degrees)
Expand All @@ -61,7 +62,7 @@ def test(self):
pointListValid = []

for i in range(num):
value = numpy.array([[1]], dtype=float) # Constant with value = i+1
value = np.array([[1]], dtype=float) # Constant with value = i+1
apCorrMap = afwImage.ApCorrMap()
bf = afwMath.ChebyshevBoundedField(inputBox, value*(i + 1))
apCorrMap.set("only", bf)
Expand Down Expand Up @@ -133,7 +134,7 @@ def assertApCorrMapValid(self, apCorrMap, pointList):
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
class TestMemory(lsst.utils.tests.MemoryTestCase):
pass


Expand Down
31 changes: 16 additions & 15 deletions tests/testCoaddBoundedField.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import os

import numpy
import numpy as np
import unittest

import lsst.utils.tests
import lsst.pex.exceptions
import lsst.afw.math
import lsst.afw.geom
import lsst.afw.image
import lsst.afw.coord
import lsst.meas.algorithms
from lsst.afw.geom.polygon import Polygon
import lsst.meas.algorithms
import lsst.pex.exceptions
import lsst.utils.tests

numpy.random.seed(50)
np.random.seed(50)


class CoaddBoundedFieldTestCase(lsst.utils.tests.TestCase):
Expand All @@ -46,9 +47,9 @@ def makeRandomWcs(self, crval, maxOffset=10.0):
warped images (which implicitly include the Jacobian) against the behavior of CoaddBoundedField
(which intentionally does not).
"""
crpix = lsst.afw.geom.Point2D(*numpy.random.uniform(low=-maxOffset, high=maxOffset, size=2))
crpix = lsst.afw.geom.Point2D(*np.random.uniform(low=-maxOffset, high=maxOffset, size=2))
rotate = lsst.afw.geom.LinearTransform.makeRotation(
numpy.pi*numpy.random.rand()*lsst.afw.geom.radians
np.pi*np.random.rand()*lsst.afw.geom.radians
)
scale = lsst.afw.geom.LinearTransform.makeScaling(
(0.01*lsst.afw.geom.arcseconds).asDegrees()
Expand All @@ -58,10 +59,10 @@ def makeRandomWcs(self, crval, maxOffset=10.0):

def makeRandomField(self, bbox):
"""Create a random ChebyshevBoundedField"""
coefficients = numpy.random.randn(3, 3)
coefficients = np.random.randn(3, 3)
# We add a positive DC offset to make sure our fields more likely to combine constructively;
# this makes the test more stringent, because we get less accidental small numbers.
coefficients[0, 0] = numpy.random.uniform(low=4, high=6)
coefficients[0, 0] = np.random.uniform(low=4, high=6)
return lsst.afw.math.ChebyshevBoundedField(bbox, coefficients)

def setUp(self):
Expand All @@ -77,7 +78,7 @@ def setUp(self):
self.makeRandomField(elementBBox),
self.makeRandomWcs(crval),
Polygon(lsst.afw.geom.Box2D(validBox)),
numpy.random.uniform(low=0.5, high=1.5)
np.random.uniform(low=0.5, high=1.5)
)
)
self.validBoxes.append(validBox)
Expand All @@ -103,7 +104,7 @@ def testEvaluate(self):
warp.getArray()[warp.getArray() != 0.0] = element.weight
weightMap += warp
coaddImage /= weightMap
coaddImage.getArray()[numpy.isnan(coaddImage.getArray())] = 0.0
coaddImage.getArray()[np.isnan(coaddImage.getArray())] = 0.0
fieldImage = lsst.afw.image.ImageF(self.bbox)
field.fillImage(fieldImage)

Expand All @@ -114,11 +115,11 @@ def testEvaluate(self):
# they do, just modify the seed (at the top of this file) or change number-of-pixels threshold
# until the test passes.

diff = numpy.abs(fieldImage.getArray() - coaddImage.getArray())
relTo = numpy.abs(fieldImage.getArray())
diff = np.abs(fieldImage.getArray() - coaddImage.getArray())
relTo = np.abs(fieldImage.getArray())
rtol = 1E-2
atol = 1E-7
bad = numpy.logical_and(diff > rtol*relTo, diff > atol)
bad = np.logical_and(diff > rtol*relTo, diff > atol)

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)
Expand Down Expand Up @@ -147,7 +148,7 @@ def tearDown(self):
del self.elements


class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
class TestMemory(lsst.utils.tests.MemoryTestCase):
pass


Expand Down
37 changes: 19 additions & 18 deletions tests/testCoaddPsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import unittest

import lsst.utils.tests
import lsst.pex.exceptions as pexExceptions
import lsst.pex.logging as logging
import lsst.afw.geom as afwGeom
import lsst.afw.math as afwMath
import lsst.afw.table as afwTable
import lsst.afw.image as afwImage
import lsst.afw.coord as afwCoord
import lsst.meas.algorithms as measAlg
import lsst.pex.exceptions as pexExceptions
import lsst.pex.logging as logging
from lsst.afw.geom.polygon import Polygon
import lsst.utils.tests


try:
Expand Down Expand Up @@ -123,8 +124,8 @@ class CoaddPsfTest(lsst.utils.tests.TestCase):
# mapped to "weight"

def testCreate(self):
"""Check that we can create a CoaddPsf with 9 elements"""
print "CreatePsfTest"
"""Check that we can create a CoaddPsf with 9 elements."""
print("CreatePsfTest")
# this is the coadd Wcs we want
cd11 = 5.55555555e-05
cd12 = 0.0
Expand Down Expand Up @@ -180,8 +181,8 @@ def testCreate(self):
self.assertAlmostEqual(i*i, myy, delta=0.01)

def testFractionalPixel(self):
"""Check that we can create a CoaddPsf with 10 elements"""
print "FractionalPixelTest"
"""Check that we can create a CoaddPsf with 10 elements."""
print("FractionalPixelTest")
# this is the coadd Wcs we want
cd11 = 5.55555555e-05
cd12 = 0.0
Expand Down Expand Up @@ -224,9 +225,9 @@ def testFractionalPixel(self):
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

def testRotatePsf(self):
"""Check that we can create a CoaddPsf with 10 elements"""
"""Check that we can create a CoaddPsf with 10 elements."""
# this is the coadd Wcs we want
print "RotatePsfTest"
print("RotatePsfTest")
cd11 = 5.55555555e-05
cd12 = 0.0
cd21 = 0.0
Expand Down Expand Up @@ -263,8 +264,8 @@ def testRotatePsf(self):
self.assertAlmostEqual(myy, cmxx, delta=0.01)

def testDefaultSize(self):
"""Test of both default size and specified size"""
print "DefaultSizeTest"
"""Test of both default size and specified size."""
print("DefaultSizeTest")
sigma0 = 5
# set the peak of the outer guassian to 0 so this is really a single gaussian.

Expand Down Expand Up @@ -304,8 +305,8 @@ def testDefaultSize(self):
self.assertAlmostEqual(m2, m2coadd, delta=.01)

def testSimpleGaussian(self):
"""Check that we can measure a single Gaussian's attributes"""
print "SimpleGaussianTest"
"""Check that we can measure a single Gaussian's attributes."""
print("SimpleGaussianTest")
sigma0 = 5
# set the peak of the outer guassian to 0 so this is really a single gaussian.

Expand Down Expand Up @@ -370,8 +371,8 @@ def testSimpleGaussian(self):
# and be sure that the resulting moments are correct

def testWeight(self):
"""Check that we can measure a single Gaussian's attributes"""
print "WeightTest"
"""Check that we can measure a single Gaussian's attributes."""
print("WeightTest")
sigma0 = 5
# set the peak of the outer guassian to 0 so this is really a single gaussian.

Expand Down Expand Up @@ -463,7 +464,7 @@ def testTicket2872(self):
coaddPsf.computeKernelImage()

def testValidPolygonPsf(self):
"""Demonstrate that we can use the validPolygon on Exposures in the CoaddPsf"""
"""Demonstrate that we can use the validPolygon on Exposures in the CoaddPsf."""
cd11, cd12, cd21, cd22 = 5.55555555e-05, 0.0, 0.0, 5.55555555e-05
crval1, crval2 = 0.0, 0.0
crpix = afwGeom.PointD(1000, 1000)
Expand Down Expand Up @@ -499,7 +500,7 @@ def testValidPolygonPsf(self):
self.assertAlmostEqual(m2, m2coadd, delta=0.01)

def testGoodPix(self):
"""Demonstrate that we can goodPix information in the CoaddPsf"""
"""Demonstrate that we can goodPix information in the CoaddPsf."""
cd11, cd12, cd21, cd22 = 5.55555555e-05, 0.0, 0.0, 5.55555555e-05
crval1, crval2 = 0.0, 0.0
bboxSize = afwGeom.Extent2I(2000, 2000)
Expand Down Expand Up @@ -546,7 +547,7 @@ def testGoodPix(self):
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
class TestMemory(lsst.utils.tests.MemoryTestCase):
pass


Expand Down

0 comments on commit f9d6802

Please sign in to comment.