Coverage for tests/test_ingest.py: 58%

70 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-02-05 18:52 -0800

1# This file is part of obs_lsst. 

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"""Unit tests for LSST raw data ingest. 

23""" 

24 

25import unittest 

26import os 

27import lsst.utils.tests 

28 

29from lsst.afw.math import flipImage 

30from lsst.afw.cameraGeom import AmplifierGeometryComparison 

31from lsst.daf.butler import Butler 

32from lsst.obs.base.ingest_tests import IngestTestBase 

33import lsst.afw.cameraGeom.testUtils # for injected test asserts 

34import lsst.obs.lsst 

35 

36TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

37DATAROOT = os.path.join(TESTDIR, os.path.pardir, "data", "input") 

38 

39 

40class LatissIngestTestCase(IngestTestBase, lsst.utils.tests.TestCase): 

41 

42 curatedCalibrationDatasetTypes = ("camera", "defects") 

43 instrumentClassName = "lsst.obs.lsst.Latiss" 

44 ingestDir = TESTDIR 

45 file = os.path.join(DATAROOT, "latiss", "raw", "2018-09-20", "3018092000065-det000.fits") 

46 dataIds = [dict(instrument="LATISS", exposure=3018092000065, detector=0)] 

47 filterLabel = lsst.afw.image.FilterLabel(band="unknown", physical="unknown~unknown") 

48 

49 def checkRepo(self, files=None): 

50 # Test amp parameter implementation for the LSST raw formatter. This 

51 # is the same for all instruments, so repeating it in other test cases 

52 # is wasteful. 

53 butler = Butler(self.root, run=self.outputRun) 

54 ref = butler.registry.findDataset("raw", self.dataIds[0]) 

55 full_assembled = butler.getDirect(ref) 

56 unassembled_detector = self.instrumentClass().getCamera()[ref.dataId["detector"]] 

57 assembled_detector = full_assembled.getDetector() 

58 for unassembled_amp, assembled_amp in zip(unassembled_detector, assembled_detector): 

59 # Check that we're testing what we think we're testing: these 

60 # amps should differ in assembly state (offsets, flips), and they 

61 # _may_ differ in fundamental geometry if we had to patch the 

62 # overscan region sizes. 

63 comparison = unassembled_amp.compareGeometry(assembled_amp) 

64 self.assertTrue(comparison & AmplifierGeometryComparison.ASSEMBLY_DIFFERS) 

65 assembled_subimage = butler.getDirect(ref, parameters={"amp": assembled_amp}) 

66 unassembled_subimage = butler.getDirect(ref, parameters={"amp": unassembled_amp.getName()}) 

67 self.assertEqual(len(assembled_subimage.getDetector()), 1) 

68 self.assertEqual(len(unassembled_subimage.getDetector()), 1) 

69 self.assertEqual(len(assembled_subimage.getDetector()), 1) 

70 self.assertEqual(len(unassembled_subimage.getDetector()), 1) 

71 self.assertImagesEqual(assembled_subimage.image, full_assembled.image[assembled_amp.getRawBBox()]) 

72 self.assertImagesEqual( 

73 unassembled_subimage.image, 

74 flipImage( 

75 full_assembled.image[assembled_amp.getRawBBox()], 

76 flipLR=unassembled_amp.getRawFlipX(), 

77 flipTB=unassembled_amp.getRawFlipY(), 

78 ), 

79 ) 

80 self.assertAmplifiersEqual(assembled_subimage.getDetector()[0], assembled_amp) 

81 if comparison & comparison.REGIONS_DIFFER: 

82 # We needed to patch overscans, but unassembled_amp (which 

83 # comes straight from the camera) won't have those patches, so 

84 # we can't compare it to the amp attached to 

85 # unassembled_subimage (which does have those patches). 

86 comparison2 = unassembled_subimage.getDetector()[0].compareGeometry(unassembled_amp) 

87 

88 self.assertTrue(comparison2 & AmplifierGeometryComparison.REGIONS_DIFFER) 

89 # ...and that unassembled_subimage's amp has the same regions 

90 # (after accounting for assembly/orientation) as assembled_amp. 

91 comparison3 = unassembled_subimage.getDetector()[0].compareGeometry(assembled_amp) 

92 self.assertTrue(comparison3 & AmplifierGeometryComparison.ASSEMBLY_DIFFERS) 

93 self.assertFalse(comparison3 & AmplifierGeometryComparison.REGIONS_DIFFER) 

94 else: 

95 self.assertAmplifiersEqual(unassembled_subimage.getDetector()[0], unassembled_amp) 

96 

97 

98class Ts3IngestTestCase(IngestTestBase, lsst.utils.tests.TestCase): 

99 

100 curatedCalibrationDatasetTypes = ("camera",) 

101 instrumentClassName = "lsst.obs.lsst.LsstTS3" 

102 ingestDir = TESTDIR 

103 file = os.path.join(DATAROOT, "ts3", "raw", "2018-11-15", "201811151255111-R433-S00-det433.fits") 

104 dataIds = [dict(instrument="LSST-TS3", exposure=201811151255111, detector=433)] 

105 filterLabel = lsst.afw.image.FilterLabel(physical="550CutOn") 

106 

107 

108class ComCamIngestTestCase(IngestTestBase, lsst.utils.tests.TestCase): 

109 

110 curatedCalibrationDatasetTypes = ("camera",) 

111 instrumentClassName = "lsst.obs.lsst.LsstComCam" 

112 ingestDir = TESTDIR 

113 file = os.path.join(DATAROOT, "comCam", "raw", "2019-05-30", 

114 "3019053000001", "3019053000001-R22-S00-det000.fits") 

115 dataIds = [dict(instrument="LSSTComCam", exposure=3019053000001, detector=0)] 

116 filterLabel = lsst.afw.image.FilterLabel(physical="unknown", band="unknown") 

117 

118 

119class LSSTCamIngestTestCase(IngestTestBase, lsst.utils.tests.TestCase): 

120 

121 curatedCalibrationDatasetTypes = ("camera",) 

122 instrumentClassName = "lsst.obs.lsst.LsstCam" 

123 ingestDir = TESTDIR 

124 file = os.path.join(DATAROOT, "lsstCam", "raw", "2019-03-19", 

125 "3019031900001", "3019031900001-R10-S02-det029.fits") 

126 dataIds = [dict(instrument="LSSTCam", exposure=3019031900001, detector=29)] 

127 filterLabel = lsst.afw.image.FilterLabel(physical="unknown", band="unknown") 

128 

129 

130def setup_module(module): 

131 lsst.utils.tests.init() 

132 

133 

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

135 lsst.utils.tests.init() 

136 unittest.main()