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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

# This file is part of obs_lsst. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (http://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <http://www.gnu.org/licenses/>. 

 

import os.path 

import unittest 

 

from lsst.pipe.tasks.ingest import IngestConfig 

import lsst.daf.base 

import lsst.log 

 

import lsst.obs.lsst.translators # noqa: F401 -- register the translators 

from lsst.obs.lsst.auxTel import AuxTelParseTask 

from lsst.obs.lsst.ts8 import Ts8ParseTask 

from lsst.obs.lsst.phosim import PhosimParseTask 

from lsst.obs.lsst.imsim import ImsimParseTask 

from lsst.obs.lsst.ucd import UcdParseTask 

 

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

ROOTDIR = os.path.normpath(os.path.join(TESTDIR, os.path.pardir)) 

DATADIR = os.path.join(ROOTDIR, "data", "input") 

CONFIGDIR = os.path.join(ROOTDIR, "config") 

 

 

class LsstCamParseTaskTestCase(unittest.TestCase): 

 

def _constructParseTask(self, configdir, name, parseTaskClass): 

"""Construct a parser task suitable for testing translation methods. 

 

Parameters 

---------- 

configdir : `str` 

Root of the config directory. This directory must include a 

directory of name ``name``. 

name : `str` 

Name of instrument within data directory and config directory. 

parseTaskClass : `lsst.pipe.tasks.ParseTask` 

Class, not instance, to use to extract information from header. 

 

Returns 

------- 

parseTask : `lsst.pipe.tasks.ParseTask` 

Instance of a ``parseTaskClass`` class. 

""" 

ingestConfig = IngestConfig() 

ingestConfig.load(os.path.join(configdir, "ingest.py")) 

ingestConfig.load(os.path.join(configdir, name, "ingest.py")) 

parser = parseTaskClass(ingestConfig.parse, name=name) 

return parser 

 

def assertParseCompare(self, datadir, configdir, name, parseTask, testData): 

"""Compare parsed output from headers with expected output. 

 

Parameters 

---------- 

datadir : `str` 

Name of the data directory to use. This directory must include 

a directory of name ``name``. 

configdir : `str` 

Root of the config directory. This directory must include a 

directory of name ``name``. 

name : `str` 

Name of instrument within data directory and config directory. 

parseTask : `lsst.pipe.tasks.ParseTask` 

Class, not instance, to use to extract information from header. 

testData : `tuple` of `tuple` (`str`, `dict`) pairs. 

Each pair in the tuple defines the file name to read from the 

constructed data directory and a `dict` defining the expected 

results from metadata extraction. 

 

Raises 

------ 

AssertionError 

If the results differ from the expected values. 

 

""" 

parser = self._constructParseTask(configdir, name, parseTask) 

for fileFragment, expected in testData: 

file = os.path.join(DATADIR, name, fileFragment) 

with self.subTest(f"Testing {file}"): 

phuInfo, infoList = parser.getInfo(file) 

print(f"Name: {file}") 

for k, v in phuInfo.items(): 

print(f"{k}: {v!r}") 

self.assertEqual(phuInfo, expected) 

 

def test_parsetask_auxtel_translator(self): 

"""Run the gen 2 metadata extraction code for AuxTel""" 

test_data = (("raw/2018-09-20/05700065-det000.fits", 

dict( 

expTime=27.0, 

object='UNKNOWN', 

imageType='UNKNOWN', 

detectorName='S00', 

dateObs='2018-09-21T06:12:18.210', 

date='2018-09-21T06:12:18.210', 

dayObs='2018-09-20', 

detector=0, 

filter='NONE', 

seqNum=65, 

visit=20180920000065, 

wavelength=-666, 

)), 

) 

self.assertParseCompare(DATADIR, CONFIGDIR, "auxTel", AuxTelParseTask, test_data) 

 

# Need to test some code paths for translations where we don't have 

# example headers. 

parseTask = self._constructParseTask(CONFIGDIR, "auxTel", AuxTelParseTask) 

 

md = lsst.daf.base.PropertyList() 

md["IMGNAME"] = "AT-O-20180816-00008" 

seqNum = parseTask.translate_seqNum(md) 

self.assertEqual(seqNum, 8) 

 

del md["IMGNAME"] 

md["FILENAME"] = "ats_exp_27_AT_C_20180920_000065.fits" 

seqNum = parseTask.translate_seqNum(md) 

self.assertEqual(seqNum, 65) 

 

# This will issue a warning 

md["FILENAME"] = "ats_exp_27_AT_C.fits" 

with self.assertLogs(level="WARNING"): 

with lsst.log.UsePythonLogging(): 

seqNum = parseTask.translate_seqNum(md) 

self.assertEqual(seqNum, 0) 

 

# Test the wavelength code path for non integer wavelength 

md["MONOWL"] = 600.4 

with self.assertLogs(level="WARNING"): 

with lsst.log.UsePythonLogging(): 

wl = parseTask.translate_wavelength(md) 

self.assertEqual(wl, int(md.getScalar("MONOWL"))) 

 

def test_parsetask_ts8_translator(self): 

"""Run the gen 2 metadata extraction code for TS8""" 

test_data = (("raw/6006D/201807241028453-RTM-010-S11-det067.fits", 

dict( 

expTime=21.913, 

object='UNKNOWN', 

imageType='FLAT', 

testType='LAMBDA', 

lsstSerial='E2V-CCD250-179', 

date='2018-07-24T10:28:45.342', 

dateObs='2018-07-24T10:28:45.342', 

run='6006D', 

wavelength=700, 

detectorName='S11', 

raftName="RTM-010", 

detector=67, 

dayObs='2018-07-24', 

filter='z', 

visit=201807241028453, 

testSeqNum=17, 

)), 

) 

self.assertParseCompare(DATADIR, CONFIGDIR, "ts8", Ts8ParseTask, test_data) 

 

# Need to test some code paths for translations where we don't have 

# example headers. 

parseTask = self._constructParseTask(CONFIGDIR, "ts8", Ts8ParseTask) 

 

md = lsst.daf.base.PropertyList() 

wl = parseTask.translate_testSeqNum(md) 

self.assertEqual(wl, 0) 

md["SEQNUM"] = 5 

wl = parseTask.translate_testSeqNum(md) 

self.assertEqual(wl, 5) 

 

def test_parsetask_imsim_translator(self): 

"""Run the gen 2 metadata extraction code for Imsim""" 

test_data = (("raw/204595/R11/00204595-R11-S20-det042-000.fits", 

dict( 

expTime=30.0, 

object='UNKNOWN', 

imageType='SKYEXP', 

testType='IMSIM', 

filter='i', 

lsstSerial='LCA-11021_RTM-000', 

date='2022-10-05T06:53:26.357', 

dateObs='2022-10-05T06:53:26.357', 

run='204595', 

visit=204595, 

wavelength=-666, 

raftName='R11', 

detectorName='S20', 

detector=42, 

snap=0, 

)), 

) 

self.assertParseCompare(DATADIR, CONFIGDIR, "imsim", ImsimParseTask, test_data) 

 

def test_parsetask_phosim_translator(self): 

"""Run the gen 2 metadata extraction code for Phosim""" 

test_data = (("raw/204595/R11/00204595-R11-S20-det042-000.fits", 

dict( 

expTime=30.0, 

object='UNKNOWN', 

imageType='SKYEXP', 

testType='PHOSIM', 

lsstSerial='R11_S20', 

date='2022-10-05T06:53:11.357', 

dateObs='2022-10-05T06:53:11.357', 

run='204595', 

wavelength=-666, 

raftName='R11', 

detectorName='S20', 

detector=42, 

snap=0, 

filter='i', 

visit=204595, 

)), 

) 

self.assertParseCompare(DATADIR, CONFIGDIR, "phosim", PhosimParseTask, test_data) 

 

def test_parsetask_ucd_translator(self): 

"""Run the gen 2 metadata extraction code for UCDCam""" 

self.maxDiff = None 

test_data = (("raw/2018-12-05/20181205233148-S00-det000.fits", 

dict( 

expTime=0.5, 

object='UNKNOWN', 

imageType='FLAT', 

testType='flat', 

lsstSerial='E2V-CCD250-112-04', 

date='2018-12-05T23:31:48.288', 

dateObs='2018-12-05T23:31:48.288', 

run='2018-12-05', 

wavelength=-666, 

raftName='R00', 

detectorName='S00', 

detector=0, 

dayObs='2018-12-05', 

filter='r', 

visit=20181205233148, 

testSeqNum=100, 

)), 

("raw/2018-05-30/20180530150355-S00-det002.fits", 

dict( 

expTime=0.5, 

object='UNKNOWN', 

imageType='FLAT', 

testType='flat', 

lsstSerial='ITL-3800C-002', 

date='2018-05-30T15:03:55.872', 

dateObs='2018-05-30T15:03:55.872', 

run='2018-05-30', 

wavelength=-666, 

raftName='R02', 

detectorName='S00', 

detector=2, 

dayObs='2018-05-30', 

filter='r', 

visit=20180530150355, 

testSeqNum=100, 

)), 

) 

self.assertParseCompare(DATADIR, CONFIGDIR, "ucd", UcdParseTask, test_data) 

 

# Need to test some code paths for translations where we don't have 

# example headers. 

parseTask = self._constructParseTask(CONFIGDIR, "ucd", UcdParseTask) 

 

md = lsst.daf.base.PropertyList() 

wl = parseTask.translate_testSeqNum(md) 

self.assertEqual(wl, 0) 

md["SEQNUM"] = 5 

wl = parseTask.translate_testSeqNum(md) 

self.assertEqual(wl, 5) 

 

 

289 ↛ 290line 289 didn't jump to line 290, because the condition on line 289 was never trueif __name__ == "__main__": 

unittest.main()