Coverage for tests/test_makeDiscreteSkyMap.py : 94%

Hot-keys 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# Copyright 2012 LSST Corporation.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
22import os.path
23import shutil
24import unittest
26from lsst.utils import getPackageDir
27import lsst.utils.tests
28from lsst.geom import Extent2I, Box2D
29from lsst.daf.persistence import Butler
30from lsst.pipe.tasks.makeDiscreteSkyMap import MakeDiscreteSkyMapTask, DiscreteSkyMap
33class MakeDiscreteSkyMapTestCase(unittest.TestCase):
34 """Test MakeDiscreteSkyMapTask"""
36 def setUp(self):
37 self.inPath = os.path.join(getPackageDir("obs_test"), "data", "input")
38 self.outPath = os.path.join(os.path.dirname(__file__), "testMakeDiscreteSkyMapOutput")
39 self.config = MakeDiscreteSkyMapTask.ConfigClass()
40 self.config.doWrite = False # repo has no place to put the data
42 def tearDown(self):
43 del self.config
44 if True:
45 shutil.rmtree(self.outPath)
47 def testBasics(self):
48 """Test construction of a discrete sky map
49 """
50 butler = Butler(inputs=self.inPath, outputs={'root': self.outPath, 'mode': 'rw'})
51 coordList = [] # list of sky coords of all corners of all calexp
52 for dataId in (
53 dict(visit=1, filter="g"),
54 dict(visit=2, filter="g"),
55 dict(visit=3, filter="r"),
56 ):
57 rawImage = butler.get("raw", dataId)
58 # fake calexp by simply copying raw data; the task just cares about its bounding box
59 # (which is slightly larger for raw, but that doesn't matter for this test)
60 calexp = rawImage
61 butler.put(calexp, "calexp", dataId)
62 calexpWcs = calexp.getWcs()
63 calexpBoxD = Box2D(calexp.getBBox())
64 coordList += [calexpWcs.pixelToSky(corner) for corner in calexpBoxD.getCorners()]
66 # use the calexp to make a sky map
67 retVal = MakeDiscreteSkyMapTask.parseAndRun(
68 args=[self.inPath, "--output", self.outPath, "--id", "filter=g^r"],
69 config=self.config,
70 doReturnResults=True,
71 )
72 self.assertEqual(len(retVal.resultList), 1)
73 skyMap = retVal.resultList[0].result.skyMap
74 self.assertEqual(type(skyMap), DiscreteSkyMap)
75 self.assertEqual(len(skyMap), 1)
76 tractInfo = skyMap[0]
77 self.assertEqual(tractInfo.getId(), 0)
78 self.assertEqual(tractInfo.getNumPatches(), Extent2I(3, 3))
79 tractWcs = tractInfo.getWcs()
80 tractBoxD = Box2D(tractInfo.getBBox())
81 for skyPoint in coordList:
82 self.assertTrue(tractBoxD.contains(tractWcs.skyToPixel(skyPoint)))
85class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
86 pass
89def setup_module(module):
90 lsst.utils.tests.init()
93if __name__ == "__main__": 93 ↛ 94line 93 didn't jump to line 94, because the condition on line 93 was never true
94 lsst.utils.tests.init()
95 unittest.main()