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

tickets/DM-7248 #44

Merged
merged 8 commits into from
Aug 21, 2016
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ python/lsst/meas/algorithms/version.py
tests/.tests
tests/data/psf*.*
tests/photometry
tests/psfAttributes
tests/sizeMagnitudeStarSelector
tests/testPsfAttributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like tests/photometry can be removed.

tests/testSizeMagnitudeStarSelector
tests/testPsfCaching
tests/testImagePsf
tests/testWarpedPsf
Expand Down
28 changes: 14 additions & 14 deletions tests/testAstrometrySourceSelector.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2015 AURA/LSST.
# Copyright 2008-2016 LSST Corporation.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# 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
# it under the terms of the GNU General Public License as
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -17,17 +18,17 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <https://www.lsstcorp.org/LegalNotices/>.
# see <http://www.lsstcorp.org/LegalNotices/>.
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you are not using he current copyright template: https://github.com/lsst/templates/blob/master/CopyrightHeader.py

from __future__ import division, absolute_import, print_function

import unittest
import numpy as np

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


badFlags = ["base_PixelFlags_flag_edge",
Expand All @@ -43,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 All @@ -58,8 +58,9 @@ def add_good_source(src, num=0):


class TestAstrometrySourceSelector(lsst.utils.tests.TestCase):

def setUp(self):
schema = TestDataset.makeMinimalSchema()
schema = lsst.meas.base.tests.TestDataset.makeMinimalSchema()
schema.addField("slot_ApFlux_flux", type=float)
schema.addField("slot_ApFlux_fluxSigma", type=float)
for flag in badFlags:
Expand Down Expand Up @@ -87,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 @@ -138,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
45 changes: 20 additions & 25 deletions tests/binnedWcs.py → tests/testBinnedWcs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2014 LSST Corporation.
# Copyright 2008-2016 LSST Corporation.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# 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
# it under the terms of the GNU General Public License as
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -20,22 +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 math
import unittest
import itertools

import lsst.utils.tests as utilsTests

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):

class BinnedWcsTest(utilsTests.TestCase):
def setUp(self):
self.scale = (1.0*afwGeom.arcseconds).asDegrees() # degrees/pixel
self.scale = (1.0*afwGeom.arcseconds).asDegrees() # degrees/pixel
self.wcs = afwImage.makeWcs(afwCoord.Coord(0.0*afwGeom.degrees, 0.0*afwGeom.degrees),
afwGeom.Point2D(0.0, 0.0), self.scale, 0.0, 0.0, self.scale)

Expand Down Expand Up @@ -70,30 +70,25 @@ def assertWcs(self, origWcs, binnedWcs, xBin, yBin, x0, y0, size=1000):
self.assertPointEqual(pixelToSky(binned), sky)

def testCases(self):
for xBin, yBin, x0, y0 in [(1, 1, 0, 0), # Pass-through
(1, 1, 12345, 6789), # Offset only
(100, 100, 0, 0), # Binning only
for xBin, yBin, x0, y0 in [(1, 1, 0, 0), # Pass-through
(1, 1, 12345, 6789), # Offset only
(100, 100, 0, 0), # Binning only
(8, 3, 0, 0), # Different binnings
(100, 100, 12345, 6789), # Binning and offset
(4, 7, 9876, 54321), # Different binnings and offset
(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)

def suite():
"""Returns a suite containing all the test cases in this module."""

utilsTests.init()
class TestMemory(lsst.utils.tests.MemoryTestCase):
pass

suites = []
suites += unittest.makeSuite(BinnedWcsTest)
suites += unittest.makeSuite(utilsTests.MemoryTestCase)
return unittest.TestSuite(suites)

def run(shouldExit=False):
"""Run the tests"""
utilsTests.run(suite(), shouldExit)
def setup_module(module):
lsst.utils.tests.init()

if __name__ == "__main__":
run(True)
lsst.utils.tests.init()
unittest.main()
54 changes: 21 additions & 33 deletions tests/CoaddApCorrMap.py → tests/testCoaddApCorrMap.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2014 LSST Corporation.
# Copyright 2008-2016 LSST Corporation.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# 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
# it under the terms of the GNU General Public License as
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -20,26 +20,19 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#

"""
Tests for CoaddApCorr code

Run with:
python CoaddApCorr.py
"""

from __future__ import absolute_import, division, print_function
import os
import numpy
import numpy as np
import unittest

import lsst.utils.tests as utilsTests
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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there also be a .tests appended here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was because of the lsst.utils.getPackageDir... call later on, but if we use file instead then this could be lsst.utils.tests

try:
type(verbose)
Expand All @@ -48,12 +41,12 @@
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
scale = 5.0e-5 # deg/pix; for CD matrix
coord = afwCoord.Coord(0.0*afwGeom.degrees, 0.0*afwGeom.degrees)
center = afwGeom.Point2D(afwGeom.Extent2D(coaddBox.getDimensions())*0.5)
coaddWcs = afwImage.makeWcs(coord, afwGeom.Point2D(0, 0), scale, 0.0, 0.0, scale)
Expand All @@ -69,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 @@ -112,7 +105,7 @@ def test(self):
# Only the second record will be valid for this point
self.assertApCorrMapValid(apCorrMap, pointListValid)

filename = "tests/coaddApCorrMap.fits"
filename = os.path.join(lsst.utils.getPackageDir("meas_algorithms"), "tests", "coaddApCorrMap.fits")
exposure = afwImage.ExposureF(1, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use file as per @timj's instructions.

exposure.getInfo().setApCorrMap(apCorrMap)
exposure.writeFits(filename)
Expand All @@ -125,34 +118,29 @@ def assertApCorrMap(self, apCorrMap, pointList):
for i, point in enumerate(pointList):
weights = [i+1, i+2]
values = [i+1, i+2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and throughout there are many cases where spaces need to be added around the + and - operators, or removed around the * and / operators.

expected = sum((w*v for w,v in zip(weights, values)), 0.0) / sum(weights)
expected = sum((w*v for w, v in zip(weights, values)), 0.0) / sum(weights)
actual = apCorrMap["only"].evaluate(point)
self.assertEqual(actual, expected)

def assertApCorrMapValid(self, apCorrMap, pointList):
for i, point in enumerate(pointList):
weights = [i+2]
values = [i+2]
expected = sum((w*v for w,v in zip(weights, values)), 0.0) / sum(weights)
expected = sum((w*v for w, v in zip(weights, values)), 0.0) / sum(weights)
actual = apCorrMap["only"].evaluate(point)
self.assertEqual(actual, expected)



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

def suite():
"""Returns a suite containing all the test cases in this module."""
utilsTests.init()

suites = []
suites += unittest.makeSuite(CoaddApCorrMapTest)
suites += unittest.makeSuite(utilsTests.MemoryTestCase)
return unittest.TestSuite(suites)
class TestMemory(lsst.utils.tests.MemoryTestCase):
pass


def run(exit = False):
"""Run the utilsTests"""
utilsTests.run(suite(), exit)
def setup_module(module):
lsst.utils.tests.init()

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