Coverage for tests/test_ingest.py: 60%

48 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-13 11:47 +0000

1# This file is part of obs_subaru. 

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 Gen3 HSC raw data ingest. 

23""" 

24 

25import unittest 

26import os 

27import lsst.utils.tests 

28 

29import lsst.afw.image 

30from lsst.daf.butler import Butler, DataCoordinate 

31from lsst.obs.base.ingest_tests import IngestTestBase 

32from lsst.obs.subaru.strayLight.yStrayLight import SubaruStrayLightData 

33 

34testDataPackage = "testdata_subaru" 

35try: 

36 testDataDirectory = lsst.utils.getPackageDir(testDataPackage) 

37except LookupError: 

38 testDataDirectory = None 

39 

40 

41@unittest.skipIf(testDataDirectory is None, "testdata_subaru must be set up") 

42class HscIngestTestCase(IngestTestBase, lsst.utils.tests.TestCase): 

43 

44 curatedCalibrationDatasetTypes = ("defects", "camera", "bfKernel", "transmission_optics", 

45 "transmission_sensor", "transmission_filter", "transmission_atmosphere") 

46 ingestDir = os.path.dirname(__file__) 

47 instrumentClassName = "lsst.obs.subaru.HyperSuprimeCam" 

48 filterLabel = lsst.afw.image.FilterLabel(physical="HSC-I", band="i") 

49 

50 @property 

51 def file(self): 

52 return os.path.join(testDataDirectory, "hsc", "raw", "HSCA90402512.fits.gz") 

53 

54 dataIds = [dict(instrument="HSC", exposure=904024, detector=50)] 

55 

56 @property 

57 def visits(self): 

58 butler = Butler(self.root, collections=[self.outputRun]) 

59 return { 

60 DataCoordinate.standardize( 

61 instrument="HSC", 

62 visit=904024, 

63 universe=butler.dimensions 

64 ): [ 

65 DataCoordinate.standardize( 

66 instrument="HSC", 

67 exposure=904024, 

68 universe=butler.dimensions 

69 ) 

70 ] 

71 } 

72 

73 def testStrayLightIngest(self): 

74 """Ingested stray light files.""" 

75 

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

77 

78 straylightDir = os.path.join(testDataDirectory, "hsc", "straylight") 

79 

80 instrument = self.instrumentClass() 

81 

82 # This will warn about lots of missing files 

83 with self.assertLogs("lsst.obs.subaru", level="WARNING") as cm: 

84 instrument.ingestStrayLightData(butler, straylightDir, transfer="auto") 

85 

86 collection = instrument.makeCalibrationCollectionName() 

87 datasets = list(butler.registry.queryDatasetAssociations("yBackground", collections=collection)) 

88 # Should have at least one dataset and dataset+warnings = 112 

89 self.assertGreaterEqual(len(datasets), 1) 

90 self.assertEqual(len(datasets) + len(cm.output), len(instrument.getCamera())) 

91 

92 # Ensure that we can read the first stray light file 

93 strayLight = butler.get(datasets[0].ref) 

94 self.assertIsInstance(strayLight, SubaruStrayLightData) 

95 

96 def checkRepo(self, files=None): 

97 # We ignore `files` because there's only one raw file in 

98 # testdata_subaru, and we know it's a science frame. 

99 # If we ever add more, this test will need to change. 

100 butler = Butler(self.root, collections=[self.outputRun]) 

101 expanded = butler.registry.expandDataId(self.dataIds[0]) 

102 self.assertEqual(expanded.records["exposure"].observation_type, "science") 

103 

104 

105def setup_module(module): 

106 lsst.utils.tests.init() 

107 

108 

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

110 lsst.utils.tests.init() 

111 unittest.main()