-
Notifications
You must be signed in to change notification settings - Fork 12
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
tickets/DM-7248 #44
Changes from 5 commits
396a137
1e3cf43
966f6e9
56d3146
ea4d154
d8cd513
08a519f
b735ab1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
# | ||
|
@@ -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/>. | ||
# | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
@@ -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() | ||
|
@@ -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: | ||
|
@@ -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) | ||
|
@@ -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() | ||
|
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. | ||
# | ||
|
@@ -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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there also be a .tests appended here? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() |
There was a problem hiding this comment.
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.