Coverage for tests/test_makeDiscreteSkyMap.py: 37%

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

47 statements  

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 

25 

26from lsst.utils import getPackageDir 

27import lsst.utils.tests 

28from lsst.geom import Box2D 

29from lsst.skymap import Index2D 

30from lsst.daf.persistence import Butler 

31from lsst.pipe.tasks.makeDiscreteSkyMap import MakeDiscreteSkyMapTask, DiscreteSkyMap 

32 

33 

34class MakeDiscreteSkyMapTestCase(unittest.TestCase): 

35 """Test MakeDiscreteSkyMapTask""" 

36 

37 def setUp(self): 

38 self.inPath = os.path.join(getPackageDir("obs_test"), "data", "input") 

39 self.outPath = os.path.join(os.path.dirname(__file__), "testMakeDiscreteSkyMapOutput") 

40 self.config = MakeDiscreteSkyMapTask.ConfigClass() 

41 self.config.doWrite = False # repo has no place to put the data 

42 

43 def tearDown(self): 

44 del self.config 

45 if True: 

46 shutil.rmtree(self.outPath) 

47 

48 def testBasics(self): 

49 """Test construction of a discrete sky map 

50 """ 

51 butler = Butler(inputs=self.inPath, outputs={'root': self.outPath, 'mode': 'rw'}) 

52 coordList = [] # list of sky coords of all corners of all calexp 

53 for dataId in ( 

54 dict(visit=1, filter="g"), 

55 dict(visit=2, filter="g"), 

56 dict(visit=3, filter="r"), 

57 ): 

58 rawImage = butler.get("raw", dataId) 

59 # fake calexp by simply copying raw data; the task just cares about its bounding box 

60 # (which is slightly larger for raw, but that doesn't matter for this test) 

61 calexp = rawImage 

62 butler.put(calexp, "calexp", dataId) 

63 calexpWcs = calexp.getWcs() 

64 calexpBoxD = Box2D(calexp.getBBox()) 

65 coordList += [calexpWcs.pixelToSky(corner) for corner in calexpBoxD.getCorners()] 

66 

67 # use the calexp to make a sky map 

68 retVal = MakeDiscreteSkyMapTask.parseAndRun( 

69 args=[self.inPath, "--output", self.outPath, "--id", "filter=g^r"], 

70 config=self.config, 

71 doReturnResults=True, 

72 ) 

73 self.assertEqual(len(retVal.resultList), 1) 

74 skyMap = retVal.resultList[0].result.skyMap 

75 self.assertEqual(type(skyMap), DiscreteSkyMap) 

76 self.assertEqual(len(skyMap), 1) 

77 tractInfo = skyMap[0] 

78 self.assertEqual(tractInfo.getId(), 0) 

79 self.assertEqual(tractInfo.getNumPatches(), Index2D(x=3, y=3)) 

80 tractWcs = tractInfo.getWcs() 

81 tractBoxD = Box2D(tractInfo.getBBox()) 

82 for skyPoint in coordList: 

83 self.assertTrue(tractBoxD.contains(tractWcs.skyToPixel(skyPoint))) 

84 

85 

86class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

87 pass 

88 

89 

90def setup_module(module): 

91 lsst.utils.tests.init() 

92 

93 

94if __name__ == "__main__": 94 ↛ 95line 94 didn't jump to line 95, because the condition on line 94 was never true

95 lsst.utils.tests.init() 

96 unittest.main()