Skip to content

Commit

Permalink
Clean up test code
Browse files Browse the repository at this point in the history
Clean up the unittest code and remove some extra whitespace. Get path
to data via __file__. Remove extra file in .gitignor. Move random seed
initializer into setup.
  • Loading branch information
AstroVPK committed Aug 21, 2016
1 parent 08a519f commit eb5e9c1
Show file tree
Hide file tree
Showing 25 changed files with 140 additions and 126 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ python/lsst/meas/algorithms/algorithmsLib_wrap.cc
python/lsst/meas/algorithms/version.py
tests/.tests
tests/data/psf*.*
tests/photometry
tests/testPsfAttributes
tests/testSizeMagnitudeStarSelector
tests/testPsfCaching
Expand Down
17 changes: 9 additions & 8 deletions tests/testAstrometrySourceSelector.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 LSST Corporation.
#
# Copyright 2008-2016 AURA/LSST.
#
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -18,7 +19,7 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import division, absolute_import, print_function

Expand Down Expand Up @@ -49,11 +50,11 @@ def add_good_source(src, num=0):
num is added to various values to distinguish them in catalogs with multiple objects.
"""
src.addNew()
src['coord_ra'][-1] = 1.+num
src['coord_dec'][-1] = 2.+num
src['slot_Centroid_x'][-1] = 10.+num
src['slot_Centroid_y'][-1] = 20.+num
src['slot_ApFlux_flux'][-1] = 100.+num
src['coord_ra'][-1] = 1. + num
src['coord_dec'][-1] = 2. + num
src['slot_Centroid_x'][-1] = 10. + num
src['slot_Centroid_y'][-1] = 20. + num
src['slot_ApFlux_flux'][-1] = 100. + num
src['slot_ApFlux_fluxSigma'][-1] = 1.


Expand Down
7 changes: 4 additions & 3 deletions tests/testBinnedWcs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 LSST Corporation.
#
# Copyright 2008-2016 AURA/LSST.
#
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -18,7 +19,7 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import math
Expand Down
23 changes: 12 additions & 11 deletions tests/testCoaddApCorrMap.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 LSST Corporation.
#
# Copyright 2008-2016 AURA/LSST.
#
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -18,7 +19,7 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import os
Expand All @@ -32,7 +33,7 @@
import lsst.afw.coord as afwCoord
from lsst.afw.geom.polygon import Polygon
import lsst.meas.algorithms as measAlg
import lsst.utils
import lsst.utils.tests

try:
type(verbose)
Expand Down Expand Up @@ -105,7 +106,7 @@ def testCoaddApCorrMap(self):
# Only the second record will be valid for this point
self.assertApCorrMapValid(apCorrMap, pointListValid)

filename = os.path.join(lsst.utils.getPackageDir("meas_algorithms"), "tests", "coaddApCorrMap.fits")
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), "coaddApCorrMap.fits")
exposure = afwImage.ExposureF(1, 1)
exposure.getInfo().setApCorrMap(apCorrMap)
exposure.writeFits(filename)
Expand All @@ -116,17 +117,17 @@ def testCoaddApCorrMap(self):

def assertApCorrMap(self, apCorrMap, pointList):
for i, point in enumerate(pointList):
weights = [i+1, i+2]
values = [i+1, i+2]
expected = sum((w*v for w, v in zip(weights, values)), 0.0) / sum(weights)
weights = [i + 1, i + 2]
values = [i + 1, i + 2]
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)
weights = [i + 2]
values = [i + 2]
expected = sum((w*v for w, v in zip(weights, values)), 0.0)/sum(weights)
actual = apCorrMap["only"].evaluate(point)
self.assertEqual(actual, expected)

Expand Down
3 changes: 1 addition & 2 deletions tests/testCoaddBoundedField.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import lsst.pex.exceptions
import lsst.utils.tests

np.random.seed(50)


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

Expand Down Expand Up @@ -71,6 +69,7 @@ def setUp(self):
validBox = lsst.afw.geom.Box2I(lsst.afw.geom.Point2I(-25, -25), lsst.afw.geom.Point2I(25, 25))
self.elements = lsst.meas.algorithms.CoaddBoundedField.ElementVector()
self.validBoxes = []
np.random.seed(50)

for i in range(10):
self.elements.append(
Expand Down
7 changes: 4 additions & 3 deletions tests/testCoaddPsf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 LSST Corporation.
#
# Copyright 2008-2016 AURA/LSST.
#
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -18,7 +19,7 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import unittest
Expand Down
7 changes: 4 additions & 3 deletions tests/testCr.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 LSST Corporation.
#
# Copyright 2008-2016 AURA/LSST.
#
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -18,7 +19,7 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import math
Expand Down
7 changes: 4 additions & 3 deletions tests/testDetection.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 LSST Corporation.
#
# Copyright 2008-2016 AURA/LSST.
#
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -18,7 +19,7 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import unittest
Expand Down
7 changes: 4 additions & 3 deletions tests/testDoubleGaussianPsf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 LSST Corporation.
#
# Copyright 2008-2016 AURA/LSST.
#
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -18,7 +19,7 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import math
Expand Down
23 changes: 23 additions & 0 deletions tests/testExecutables.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
#!/usr/bin/env python
#
# LSST Data Management System
#
# Copyright 2008-2016 AURA/LSST.
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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/>.
#
import unittest
import lsst.utils.tests

Expand Down
7 changes: 4 additions & 3 deletions tests/testGaussianPsfFactory.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 LSST Corporation.
#
# Copyright 2008-2016 AURA/LSST.
#
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -18,7 +19,7 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import unittest
Expand Down
11 changes: 6 additions & 5 deletions tests/testHtmIndex.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 LSST Corporation.
#
# Copyright 2008-2016 AURA/LSST.
#
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -18,7 +19,7 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function

Expand All @@ -36,8 +37,8 @@
import lsst.afw.geom as afwGeom
import lsst.afw.coord as afwCoord
import lsst.daf.persistence as dafPersist
from lsst.meas.algorithms import IngestIndexedReferenceTask, LoadIndexedReferenceObjectsTask, \
LoadIndexedReferenceObjectsConfig, getRefFluxField
from lsst.meas.algorithms import (IngestIndexedReferenceTask, LoadIndexedReferenceObjectsTask,
LoadIndexedReferenceObjectsConfig, getRefFluxField)
import lsst.utils

obs_test_dir = lsst.utils.getPackageDir('obs_test')
Expand Down
7 changes: 4 additions & 3 deletions tests/testInstallGaussianPsf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008-2016 LSST Corporation.
#
# Copyright 2008-2016 AURA/LSST.
#
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
Expand All @@ -18,7 +19,7 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from __future__ import absolute_import, division, print_function
import unittest
Expand Down

0 comments on commit eb5e9c1

Please sign in to comment.