Coverage for tests/test_dm-329.py: 52%

42 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-15 02:57 -0700

1# This file is part of obs_base. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://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 <https://www.gnu.org/licenses/>. 

21 

22import os 

23import unittest 

24 

25import lsst.afw.image 

26import lsst.daf.persistence as dafPersist 

27import lsst.obs.base 

28import lsst.utils.tests 

29 

30ROOT = os.path.abspath(os.path.dirname(__file__)) 

31 

32 

33class MinMapper2(lsst.obs.base.CameraMapper): 

34 packageName = "larry" 

35 

36 def __init__(self): 

37 policy = dafPersist.Policy(os.path.join(ROOT, "MinMapper2.yaml")) 

38 lsst.obs.base.CameraMapper.__init__( 

39 self, policy=policy, repositoryDir=ROOT, root=ROOT, registry=os.path.join(ROOT, "cfhtls.sqlite3") 

40 ) 

41 return 

42 

43 def _transformId(self, dataId): 

44 return dataId 

45 

46 def _extractDetectorName(self, dataId): 

47 return "Detector" 

48 

49 @classmethod 

50 def getPackageDir(cls): 

51 return "/path/to/nowhere" 

52 

53 

54class DM329TestCase(unittest.TestCase): 

55 def testHdu(self): 

56 mapper = MinMapper2() 

57 butler = dafPersist.ButlerFactory(mapper=mapper).create() 

58 # HDU INT_MIN returns primary array (skipping empty PDU) 

59 # HDU 0 returns (header-only) PDU 

60 # HDU 1 returns first image plane 

61 # HDU 2 returns mask plane 

62 # HDU 3 returns variance plane 

63 for i in (1, 2, 3): 

64 loc = mapper.map("other", dict(ccd=35, hdu=i)) 

65 expectedLocations = ["bar-35.fits[%d]" % (i,)] 

66 self.assertEqual(loc.getStorage().root, ROOT) 

67 self.assertEqual(loc.getLocations(), expectedLocations) 

68 image = butler.get("other", ccd=35, hdu=i, immediate=True) 

69 self.assertIsInstance(image, lsst.afw.image.ImageF) 

70 self.assertEqual(image.getHeight(), 2024) 

71 self.assertEqual(image.getWidth(), 2248) 

72 self.assertEqual(image[200, 25, lsst.afw.image.LOCAL], (0.0, 20.0, 0.0)[i - 1]) 

73 self.assertAlmostEqual( 

74 image[200, 26, lsst.afw.image.LOCAL], (1.20544, 0.0, 5.82185)[i - 1], places=5 

75 ) 

76 

77 

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

79 pass 

80 

81 

82def setup_module(module): 

83 lsst.utils.tests.init() 

84 

85 

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

87 lsst.utils.tests.init() 

88 unittest.main()