Coverage for tests/test_metadataObjectAccess.py: 32%

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

56 statements  

1# This file is part of obs_test. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

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 GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21# 

22 

23import math 

24import os 

25import unittest 

26 

27import lsst.afw.image 

28from lsst.afw.geom import SkyWcs 

29import lsst.daf.persistence as dafPersist 

30import lsst.utils.tests 

31from lsst.utils import getPackageDir 

32 

33obsTestDir = getPackageDir('obs_test') 

34 

35 

36class TestCalexpMetadataObjects(lsst.utils.tests.TestCase): 

37 """Test getting metadata objects from a calexp.""" 

38 def setUp(self): 

39 self.input = os.path.join(obsTestDir, 

40 'data', 

41 'calexpMetadataObjectsTest') 

42 

43 def nanSafeAssertEqual(self, val1, val2): 

44 try: 

45 self.assertEqual(val1, val2) 

46 except AssertionError as err: 

47 if math.isnan(val1) and math.isnan(val2): 

48 pass 

49 else: 

50 raise err 

51 

52 def testNanSafeAssertEqual(self): 

53 val1 = float('nan') 

54 val2 = float(123.45) 

55 with self.assertRaises(AssertionError): 

56 self.nanSafeAssertEqual(val1, val2) 

57 val1 = float(123.44) 

58 val2 = float(123.45) 

59 with self.assertRaises(AssertionError): 

60 self.nanSafeAssertEqual(val1, val2) 

61 # should not raise: 

62 val1 = float('nan') 

63 val2 = float('nan') 

64 self.nanSafeAssertEqual(val1, val2) 

65 val1 = float(123.45) 

66 val2 = float(123.45) 

67 self.nanSafeAssertEqual(val1, val2) 

68 

69 def test(self): 

70 """Get the wcs, photoCalib, and visitInfo from a calexp dataset.""" 

71 butler = dafPersist.Butler(inputs=self.input) 

72 wcs = butler.get('calexp_wcs', immediate=True) 

73 photoCalib = butler.get('calexp_photoCalib', immediate=True) 

74 visitInfo = butler.get('calexp_visitInfo', immediate=True) 

75 filt = butler.get('calexp_filter', immediate=True) 

76 calexp = butler.get('calexp', immediate=True) 

77 self.assertIsInstance(calexp, lsst.afw.image.ExposureF) 

78 

79 self.assertIsInstance(wcs, SkyWcs) 

80 self.assertWcsAlmostEqualOverBBox(wcs, calexp.getWcs(), calexp.getBBox()) 

81 

82 self.assertIsInstance(photoCalib, lsst.afw.image.PhotoCalib) 

83 self.assertEqual(photoCalib, calexp.getPhotoCalib()) 

84 

85 self.assertIsInstance(visitInfo, lsst.afw.image.VisitInfo) 

86 self.assertIsInstance(filt, lsst.afw.image.Filter) 

87 

88 self.assertEqual(visitInfo, calexp.info.getVisitInfo()) 

89 

90 

91class MemoryTester(lsst.utils.tests.MemoryTestCase): 

92 pass 

93 

94 

95def setup_module(module): 

96 lsst.utils.tests.init() 

97 

98 

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

100 lsst.utils.tests.init() 

101 unittest.main()