Coverage for tests/test_joinMatchListWithCatalog.py: 30%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#
2# LSST Data Management System
3#
4# Copyright 2008-2015 AURA/LSST.
5#
6# This product includes software developed by the
7# LSST Project (http://www.lsst.org/).
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the LSST License Statement and
20# the GNU General Public License along with this program. If not,
21# see <https://www.lsstcorp.org/LegalNotices/>.
22#
24import os
25import unittest
26import logging
28import lsst.geom
29from lsst.afw.image import ExposureF
30from lsst.afw.table import packMatches, SourceCatalog
31import lsst.utils.tests
32from lsst.daf.persistence import Butler
33from lsst.meas.algorithms import LoadIndexedReferenceObjectsTask
34from lsst.meas.astrom import AstrometryTask
37class JoinMatchListWithCatalogTestCase(unittest.TestCase):
39 def setUp(self):
40 # Load sample input from disk
41 testDir = os.path.dirname(__file__)
43 self.srcSet = SourceCatalog.readFits(os.path.join(testDir, "v695833-e0-c000.xy.fits"))
45 self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(2048, 4612)) # approximate
46 # create an exposure with the right metadata; the closest thing we have is
47 # apparently v695833-e0-c000-a00.sci.fits, which is much too small
48 smallExposure = ExposureF(os.path.join(testDir, "v695833-e0-c000-a00.sci.fits"))
49 self.exposure = ExposureF(self.bbox)
50 self.exposure.setWcs(smallExposure.getWcs())
51 self.exposure.setFilterLabel(smallExposure.getFilterLabel())
52 # copy the pixels we can, in case the user wants a debug display
53 mi = self.exposure.getMaskedImage()
54 mi.assign(smallExposure.getMaskedImage(), smallExposure.getBBox())
56 logLevel = logging.INFO
57 refCatDir = os.path.join(testDir, "data", "sdssrefcat")
58 butler = Butler(refCatDir)
59 refObjLoader = LoadIndexedReferenceObjectsTask(butler=butler)
60 astrometryConfig = AstrometryTask.ConfigClass()
61 self.astrom = AstrometryTask(config=astrometryConfig, refObjLoader=refObjLoader)
62 self.astrom.log.setLevel(logLevel)
63 # Since our sourceSelector is a registry object we have to wait for it to be created
64 # before setting default values.
65 self.astrom.sourceSelector.config.minSnr = 0
67 def tearDown(self):
68 del self.srcSet
69 del self.bbox
70 del self.exposure
71 del self.astrom
73 def getAstrometrySolution(self):
74 return self.astrom.solve(exposure=self.exposure, sourceCat=self.srcSet)
76 def testJoin(self):
77 res = self.getAstrometrySolution()
79 matches = res.matches
80 matchmeta = res.matchMeta
82 normalized = packMatches(matches)
83 normalized.table.setMetadata(matchmeta)
85 matches2 = self.astrom.refObjLoader.joinMatchListWithCatalog(normalized, self.srcSet)
87 self.assertEqual(len(matches2), len(matches))
88 for i in range(len(matches)):
89 self.assertEqual(matches2[i].second.table, matches[i].second.table)
90 self.assertEqual(matches2[i].second.getId(), matches[i].second.getId())
91 self.assertEqual(matches2[i].second, matches[i].second) # no deep copying, so we can compare ptrs
92 self.assertEqual(matches2[i].first.getId(), matches[i].first.getId())
93 self.assertEqual(matches2[i].first.getRa().asDegrees(), matches[i].first.getRa().asDegrees())
94 self.assertEqual(matches2[i].first.getDec().asDegrees(), matches[i].first.getDec().asDegrees())
95 self.assertEqual(matches2[i].first.get("i_flux"), matches[i].first.get("i_flux"))
97 def testJoinAllFluxes(self):
98 """Test that we can read all the fluxes from a reference catalog"""
99 res = self.getAstrometrySolution()
101 matches = res.matches
102 matchmeta = res.matchMeta
104 normalized = packMatches(matches)
105 normalized.table.setMetadata(matchmeta)
107 matches2 = self.astrom.refObjLoader.joinMatchListWithCatalog(normalized, self.srcSet)
108 self.assertGreater(len(matches2), 0)
109 ref = matches2[0][0]
111 refSchema = ref.getSchema()
112 for b in ("u", "g", "r", "i", "z"):
113 self.assertIn("%s_flux" % (b,), refSchema)
114 self.assertIn("%s_fluxErr" % (b,), refSchema)
117class MemoryTester(lsst.utils.tests.MemoryTestCase):
118 pass
121def setup_module(module):
122 lsst.utils.tests.init()
125if __name__ == "__main__": 125 ↛ 126line 125 didn't jump to line 126, because the condition on line 125 was never true
126 lsst.utils.tests.init()
127 unittest.main()