Coverage for python/lsst/obs/test/testMapper.py: 32%

72 statements  

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

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__all__ = ["TestMapper", "MapperForTestCalexpMetadataObjects"] 

23 

24import os 

25import warnings 

26 

27import lsst.utils 

28import lsst.afw.image.utils as afwImageUtils 

29import lsst.daf.persistence as dafPersist 

30from lsst.obs.base import CameraMapper 

31from .testCamera import TestCamera 

32from .makeTestRawVisitInfo import MakeTestRawVisitInfo 

33 

34 

35class TestMapper(CameraMapper): 

36 """Camera mapper for the Test camera. 

37 """ 

38 packageName = 'obs_test' 

39 

40 MakeRawVisitInfoClass = MakeTestRawVisitInfo 

41 

42 def __init__(self, inputPolicy=None, **kwargs): 

43 policyFilePath = dafPersist.Policy.defaultPolicyFile(self.packageName, "testMapper.yaml", "policy") 

44 policy = dafPersist.Policy(policyFilePath) 

45 

46 self.doFootprints = False 

47 if inputPolicy is not None: 

48 for kw in inputPolicy.paramNames(True): 

49 if kw == "doFootprints": 

50 self.doFootprints = True 

51 else: 

52 kwargs[kw] = inputPolicy.get(kw) 

53 

54 CameraMapper.__init__(self, policy, policyFilePath, **kwargs) 

55 self.filterIdMap = { 

56 'u': 0, 'g': 1, 'r': 2, 'i': 3, 'z': 4, 'y': 5, 'i2': 5} 

57 

58 with warnings.catch_warnings(): 

59 # surpress Filter warnings; we already know this is deprecated 

60 warnings.simplefilter('ignore', category=FutureWarning) 

61 

62 # The LSST Filters from L. Jones 04/07/10 

63 afwImageUtils.defineFilter('u', 364.59) 

64 afwImageUtils.defineFilter('g', 476.31) 

65 afwImageUtils.defineFilter('r', 619.42) 

66 afwImageUtils.defineFilter('i', 752.06) 

67 afwImageUtils.defineFilter('z', 866.85) 

68 afwImageUtils.defineFilter('y', 971.68, alias=['y4']) # official y filter 

69 

70 def _extractDetectorName(self, dataId): 

71 return "0" 

72 

73 def _defectLookup(self, dataId): 

74 """Find the defects for a given CCD. 

75 

76 Parameters 

77 ---------- 

78 dataId : `dict` 

79 Dataset identifier 

80 

81 Returns 

82 ------- 

83 result : `str` 

84 Path to the defects file. 

85 

86 Raises 

87 ------ 

88 RuntimeError 

89 If ``obs_test`` is not setup. 

90 """ 

91 obsTestDir = lsst.utils.getPackageDir('obs_test') 

92 

93 return os.path.join(obsTestDir, "data", "input", "defects", "defects.fits") 

94 

95 def _computeCcdExposureId(self, dataId): 

96 """Compute the 64-bit (long) identifier for a CCD exposure. 

97 

98 Parameters 

99 ---------- 

100 dataId : `dict` 

101 Data identifier with visit 

102 """ 

103 visit = dataId['visit'] 

104 return int(visit) 

105 

106 def bypass_ccdExposureId(self, datasetType, pythonType, location, dataId): 

107 return self._computeCcdExposureId(dataId) 

108 

109 def bypass_ccdExposureId_bits(self, datasetType, pythonType, location, dataId): 

110 return 41 

111 

112 def validate(self, dataId): 

113 visit = dataId.get("visit") 

114 if visit is not None and not isinstance(visit, int): 

115 dataId["visit"] = int(visit) 

116 return dataId 

117 

118 def _setCcdExposureId(self, propertyList, dataId): 

119 propertyList.set("Computed_ccdExposureId", self._computeCcdExposureId(dataId)) 

120 return propertyList 

121 

122 def _makeCamera(self, policy, repositoryDir): 

123 """Make a camera describing the camera geometry. 

124 

125 Returns 

126 ------- 

127 testCamera : `TestCamera` 

128 Test camera. 

129 """ 

130 return TestCamera() 

131 

132 

133class MapperForTestCalexpMetadataObjects(lsst.obs.base.CameraMapper): 

134 """Minimal mapper for testing calexp composite access, e.g. calexp_wcs. 

135 

136 Used by test_metadataObjectAccess.py. 

137 """ 

138 packageName = "obs_test" 

139 

140 def __init__(self, root, parentRegistry=None, repositoryCfg=None): 

141 policyFilePath = dafPersist.Policy.defaultPolicyFile( 

142 self.packageName, "testCalexpMetadataObjects.yaml", "policy") 

143 policy = dafPersist.Policy(policyFilePath) 

144 super(MapperForTestCalexpMetadataObjects, self).__init__( 

145 policy, repositoryDir=root, root=root, parentRegistry=None, repositoryCfg=None) 

146 self.filterIdMap = { 

147 'u': 0, 'g': 1, 'r': 2, 'i': 3, 'z': 4, 'y': 5, 'i2': 5} 

148 

149 with warnings.catch_warnings(): 

150 # surpress Filter warnings; we already know this is deprecated 

151 warnings.simplefilter('ignore', category=FutureWarning) 

152 

153 # The LSST Filters from L. Jones 04/07/10 

154 afwImageUtils.defineFilter('u', 364.59) 

155 afwImageUtils.defineFilter('g', 476.31) 

156 afwImageUtils.defineFilter('r', 619.42) 

157 afwImageUtils.defineFilter('i', 752.06) 

158 afwImageUtils.defineFilter('z', 866.85) 

159 afwImageUtils.defineFilter('y', 971.68, alias=['y4']) # official y filter 

160 

161 def _makeCamera(self, policy, repositoryDir): 

162 """Normally this makes a camera. For composite testing, we don't need a camera. 

163 """ 

164 return TestCamera() 

165 

166 def _extractDetectorName(self, dataId): 

167 """Normally this extracts the detector (CCD) name from the dataset 

168 identifier. The name in question is the detector name used by 

169 lsst.afw.cameraGeom. 

170 

171 We don't need anything meaninful here, so just override so as not to 

172 throw (in the base class impl) 

173 """ 

174 return "0"