Hide keyboard shortcuts

Hot-keys 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

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 HSC gen2 to gen3 conversion. 

23""" 

24 

25import glob 

26import os 

27import subprocess 

28import tempfile 

29import unittest 

30 

31import lsst.utils.tests 

32from lsst.obs.base.gen2to3 import convertTests 

33import lsst.obs.subaru 

34import lsst.obs.hsc 

35 

36 

37testDataPackage = "testdata_subaru" 

38try: 

39 testDataDirectory = lsst.utils.getPackageDir(testDataPackage) 

40except LookupError: 

41 testDataDirectory = None 

42 

43 

44def createGen2Repo(inputPath): 

45 """ 

46 Construct a gen2 repository for `HscMapper` containing a given set 

47 of input data and return its path. 

48 

49 Parameters 

50 ---------- 

51 inputPath : `str` 

52 Location of data files to ingest. 

53 

54 Returns 

55 ------- 

56 path : `str` 

57 Path to newly created gen2 repo, with ingested files. 

58 """ 

59 repoPath = tempfile.mkdtemp() 

60 with open(os.path.join(repoPath, "_mapper"), "w") as _mapper: 

61 print("lsst.obs.hsc.HscMapper", file=_mapper) 

62 ingest_cmd = "hscIngestImages.py" 

63 files = glob.glob(os.path.join(inputPath, "*.fits.gz")) 

64 cmd = [ingest_cmd, repoPath, *files] 

65 print(f"Running command: {' '.join(cmd)}") 

66 subprocess.run(cmd, check=True) 

67 return repoPath 

68 

69 

70@unittest.skipIf(testDataDirectory is None, f"{testDataPackage} not setup") 

71class ConvertGen2To3TestCase(convertTests.ConvertGen2To3TestCase, 

72 lsst.utils.tests.TestCase): 

73 

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

75 

76 def setUp(self): 

77 rawpath = os.path.join(testDataDirectory, 'hsc/raw') 

78 self.gen2calib = os.path.join(testDataDirectory, 'hsc/calib') 

79 self.gen2root = createGen2Repo(rawpath) 

80 self.config = os.path.join(os.path.abspath(os.path.dirname(__file__)), 

81 "config", "convert2to3Config.py") 

82 

83 self.biases = [{"detector": 50, "instrument": "HSC"}] 

84 self.flats = [{"detector": 50, "instrument": "HSC", "physical_filter": "HSC-I"}] 

85 self.darks = [{"detector": 50, "instrument": "HSC"}] 

86 super().setUp() 

87 

88 

89def setup_module(module): 

90 lsst.utils.tests.init() 

91 

92 

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

94 lsst.utils.tests.init() 

95 unittest.main()