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

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

# This file is part of daf_butler. 

# 

# 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/>. 

 

from datetime import datetime, timedelta 

import os 

import unittest 

 

import lsst.utils.tests 

 

from lsst.daf.butler import (ButlerConfig, DatasetType, Registry, DataId, 

DatasetOriginInfoDef, StorageClass) 

from lsst.daf.butler.registries.sqlPreFlight import SqlPreFlight 

from lsst.sphgeom import Angle, Box, LonLat, NormalizedAngle 

 

 

class SqlPreFlightTestCase(lsst.utils.tests.TestCase): 

"""Test for SqlPreFlight. 

""" 

 

def setUp(self): 

self.testDir = os.path.dirname(__file__) 

self.configFile = os.path.join(self.testDir, "config/basic/butler.yaml") 

# easiest way to make SqlPreFlight instance is to ask SqlRegistry to do it 

self.butlerConfig = ButlerConfig(self.configFile) 

self.registry = Registry.fromConfig(self.butlerConfig) 

 

def testDatasetOriginInfoDef(self): 

"""Test for DatasetOriginInfoDef class""" 

 

originInfo = DatasetOriginInfoDef(defaultInputs=["a", "b"], defaultOutput="out") 

self.assertEqual(originInfo.getInputCollections("ds"), ["a", "b"]) 

self.assertEqual(originInfo.getInputCollections("ds2"), ["a", "b"]) 

self.assertEqual(originInfo.getOutputCollection("ds"), "out") 

self.assertEqual(originInfo.getOutputCollection("ds2"), "out") 

 

originInfo = DatasetOriginInfoDef(defaultInputs=["a", "b"], defaultOutput="out", 

inputOverrides=dict(ds2=["c"]), 

outputOverrides=dict(ds2="out2")) 

self.assertEqual(originInfo.getInputCollections("ds"), ["a", "b"]) 

self.assertEqual(originInfo.getInputCollections("ds2"), ["c"]) 

self.assertEqual(originInfo.getOutputCollection("ds"), "out") 

self.assertEqual(originInfo.getOutputCollection("ds2"), "out2") 

 

def testPreFlightInstrumentUnits(self): 

"""Test involving only Instrument units, no joins to SkyMap""" 

registry = self.registry 

 

# need a bunch of units and datasets for test 

registry.addDimensionEntry("Instrument", dict(instrument="DummyCam", visit_max=25, exposure_max=300, 

detector_max=6)) 

registry.addDimensionEntry("PhysicalFilter", dict(instrument="DummyCam", 

physical_filter="dummy_r", 

abstract_filter="r")) 

registry.addDimensionEntry("PhysicalFilter", dict(instrument="DummyCam", 

physical_filter="dummy_i", 

abstract_filter="i")) 

for detector in (1, 2, 3, 4, 5): 

registry.addDimensionEntry("Detector", dict(instrument="DummyCam", detector=detector)) 

registry.addDimensionEntry("Visit", dict(instrument="DummyCam", visit=10, physical_filter="dummy_i")) 

registry.addDimensionEntry("Visit", dict(instrument="DummyCam", visit=11, physical_filter="dummy_r")) 

registry.addDimensionEntry("Visit", dict(instrument="DummyCam", visit=20, physical_filter="dummy_r")) 

registry.addDimensionEntry("Exposure", dict(instrument="DummyCam", exposure=100, visit=10, 

physical_filter="dummy_i")) 

registry.addDimensionEntry("Exposure", dict(instrument="DummyCam", exposure=101, visit=10, 

physical_filter="dummy_i")) 

registry.addDimensionEntry("Exposure", dict(instrument="DummyCam", exposure=110, visit=11, 

physical_filter="dummy_r")) 

registry.addDimensionEntry("Exposure", dict(instrument="DummyCam", exposure=111, visit=11, 

physical_filter="dummy_r")) 

registry.addDimensionEntry("Exposure", dict(instrument="DummyCam", exposure=200, visit=20, 

physical_filter="dummy_r")) 

registry.addDimensionEntry("Exposure", dict(instrument="DummyCam", exposure=201, visit=20, 

physical_filter="dummy_r")) 

 

# dataset types 

collection1 = "test" 

collection2 = "test2" 

run = registry.makeRun(collection=collection1) 

run2 = registry.makeRun(collection=collection2) 

storageClass = StorageClass("testDataset") 

registry.storageClasses.registerStorageClass(storageClass) 

rawType = DatasetType(name="RAW", dimensions=("Instrument", "Exposure", "Detector"), 

storageClass=storageClass) 

registry.registerDatasetType(rawType) 

calexpType = DatasetType(name="CALEXP", dimensions=("Instrument", "Visit", "Detector"), 

storageClass=storageClass) 

registry.registerDatasetType(calexpType) 

 

# add pre-existing datasets 

for exposure in (100, 101, 110, 111): 

for detector in (1, 2, 3): 

# note that only 3 of 5 detectors have datasets 

dataId = dict(instrument="DummyCam", exposure=exposure, detector=detector) 

ref = registry.addDataset(rawType, dataId=dataId, run=run) 

# Exposures 100 and 101 appear in both collections, 100 has different 

# dataset_id in different collections, for 101 only single dataset_id exists 

if exposure == 100: 

registry.addDataset(rawType, dataId=dataId, run=run2) 

if exposure == 101: 

registry.associate(run2.collection, [ref]) 

# Add pre-existing datasets to second collection. 

for exposure in (200, 201): 

for detector in (3, 4, 5): 

# note that only 3 of 5 detectors have datasets 

dataId = dict(instrument="DummyCam", exposure=exposure, detector=detector) 

registry.addDataset(rawType, dataId=dataId, run=run2) 

 

# with empty expression 

originInfo = DatasetOriginInfoDef(defaultInputs=[collection1], defaultOutput=collection1) 

for deferOutputIdQueries in (True, False): 

with self.subTest(deferOutputIdQueries=deferOutputIdQueries): 

preFlight = SqlPreFlight(self.registry, neededDatasetTypes=[rawType], 

futureDatasetTypes=[calexpType], originInfo=originInfo, 

deferOutputIdQueries=deferOutputIdQueries) 

rows = preFlight.selectDimensions() 

rows = list(rows) 

self.assertEqual(len(rows), 4*3) # 4 exposures times 3 detectors 

for row in rows: 

self.assertCountEqual(row.dataId.keys(), ("instrument", "detector", "exposure", "visit")) 

self.assertCountEqual(row.datasetRefs.keys(), (rawType, calexpType)) 

packer1 = registry.makeDataIdPacker("VisitDetector", row.dataId) 

packer2 = registry.makeDataIdPacker("ExposureDetector", row.dataId) 

self.assertEqual(packer1.unpack(packer1.pack(row.dataId)), 

DataId(row.dataId, dimensions=packer1.dimensions.required)) 

self.assertEqual(packer2.unpack(packer2.pack(row.dataId)), 

DataId(row.dataId, dimensions=packer2.dimensions.required)) 

self.assertNotEqual(packer1.pack(row.dataId), packer2.pack(row.dataId)) 

self.assertCountEqual(set(row.dataId["exposure"] for row in rows), 

(100, 101, 110, 111)) 

self.assertCountEqual(set(row.dataId["visit"] for row in rows), (10, 11)) 

self.assertCountEqual(set(row.dataId["detector"] for row in rows), (1, 2, 3)) 

 

# second collection 

originInfo = DatasetOriginInfoDef(defaultInputs=[collection2], defaultOutput=collection1) 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, neededDatasetTypes=[rawType], 

futureDatasetTypes=[calexpType]) 

rows = preFlight.selectDimensions() 

rows = list(rows) 

self.assertEqual(len(rows), 4*3) # 4 exposures times 3 detectors 

for row in rows: 

self.assertCountEqual(row.dataId.keys(), ("instrument", "detector", "exposure", "visit")) 

self.assertCountEqual(row.datasetRefs.keys(), (rawType, calexpType)) 

self.assertCountEqual(set(row.dataId["exposure"] for row in rows), 

(100, 101, 200, 201)) 

self.assertCountEqual(set(row.dataId["visit"] for row in rows), (10, 20)) 

self.assertCountEqual(set(row.dataId["detector"] for row in rows), (1, 2, 3, 4, 5)) 

 

# with two input datasets 

originInfo = DatasetOriginInfoDef(defaultInputs=[collection1, collection2], defaultOutput=collection2) 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[rawType], 

futureDatasetTypes=[calexpType]) 

rows = preFlight.selectDimensions() 

rows = list(rows) 

self.assertEqual(len(rows), 6*3) # 6 exposures times 3 detectors 

for row in rows: 

self.assertCountEqual(row.dataId.keys(), ("instrument", "detector", "exposure", "visit")) 

self.assertCountEqual(row.datasetRefs.keys(), (rawType, calexpType)) 

self.assertCountEqual(set(row.dataId["exposure"] for row in rows), 

(100, 101, 110, 111, 200, 201)) 

self.assertCountEqual(set(row.dataId["visit"] for row in rows), (10, 11, 20)) 

self.assertCountEqual(set(row.dataId["detector"] for row in rows), (1, 2, 3, 4, 5)) 

 

# limit to single visit 

originInfo = DatasetOriginInfoDef(defaultInputs=[collection1], defaultOutput=None) 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[rawType], 

futureDatasetTypes=[calexpType]) 

rows = preFlight.selectDimensions(expression="Visit.visit = 10") 

rows = list(rows) 

self.assertEqual(len(rows), 2*3) # 2 exposures times 3 detectors 

self.assertCountEqual(set(row.dataId["exposure"] for row in rows), (100, 101)) 

self.assertCountEqual(set(row.dataId["visit"] for row in rows), (10,)) 

self.assertCountEqual(set(row.dataId["detector"] for row in rows), (1, 2, 3)) 

 

# more limiting expression, using link names instead of Table.column 

originInfo = DatasetOriginInfoDef(defaultInputs=[collection1], defaultOutput="") 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[rawType], 

futureDatasetTypes=[calexpType]) 

rows = preFlight.selectDimensions(expression="visit = 10 and detector > 1") 

rows = list(rows) 

self.assertEqual(len(rows), 2*2) # 2 exposures times 2 detectors 

self.assertCountEqual(set(row.dataId["exposure"] for row in rows), (100, 101)) 

self.assertCountEqual(set(row.dataId["visit"] for row in rows), (10,)) 

self.assertCountEqual(set(row.dataId["detector"] for row in rows), (2, 3)) 

 

# expression excludes everything 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[rawType], 

futureDatasetTypes=[calexpType]) 

rows = preFlight.selectDimensions(expression="Visit.visit > 1000") 

rows = list(rows) 

self.assertEqual(len(rows), 0) 

 

# Selecting by PhysicalFilter, this is not in the units, but it is 

# a part of the full expression so it should work too. 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[rawType], 

futureDatasetTypes=[calexpType]) 

rows = preFlight.selectDimensions(expression="physical_filter = 'dummy_r'") 

rows = list(rows) 

self.assertEqual(len(rows), 2*3) # 2 exposures times 3 detectors 

self.assertCountEqual(set(row.dataId["exposure"] for row in rows), (110, 111)) 

self.assertCountEqual(set(row.dataId["visit"] for row in rows), (11,)) 

self.assertCountEqual(set(row.dataId["detector"] for row in rows), (1, 2, 3)) 

 

def testPreFlightExposureRange(self): 

"""Test involving only ExposureRange unit""" 

registry = self.registry 

 

# need a bunch of units and datasets for test 

registry.addDimensionEntry("Instrument", dict(instrument="DummyCam")) 

registry.addDimensionEntry("PhysicalFilter", dict(instrument="DummyCam", 

physical_filter="dummy_r", 

abstract_filter="r")) 

for detector in (1, 2, 3, 4, 5): 

registry.addDimensionEntry("Detector", dict(instrument="DummyCam", detector=detector)) 

 

# make few visits/exposures 

now = datetime.now() 

timestamps = [] # list of start/end time of each exposure 

for visit in (10, 11, 20): 

registry.addDimensionEntry("Visit", 

dict(instrument="DummyCam", visit=visit, physical_filter="dummy_r")) 

visit_start = now + timedelta(seconds=visit*45) 

for exposure in (0, 1): 

start = visit_start + timedelta(seconds=15*exposure) 

end = start + timedelta(seconds=15) 

registry.addDimensionEntry("Exposure", dict(instrument="DummyCam", 

exposure=visit*10+exposure, 

visit=visit, 

physical_filter="dummy_r", 

datetime_begin=start, 

datetime_end=end)) 

timestamps += [(start, end)] 

self.assertEqual(len(timestamps), 6) 

 

# dataset types 

collection = "test" 

run = registry.makeRun(collection=collection) 

storageClass = StorageClass("testExposureRange") 

registry.storageClasses.registerStorageClass(storageClass) 

rawType = DatasetType(name="RAW", dimensions=("Instrument", "Detector", "Exposure"), 

storageClass=storageClass) 

registry.registerDatasetType(rawType) 

biasType = DatasetType(name="bias", dimensions=("Instrument", "Detector", "ExposureRange"), 

storageClass=storageClass) 

registry.registerDatasetType(biasType) 

flatType = DatasetType(name="flat", 

dimensions=("Instrument", "Detector", "PhysicalFilter", "ExposureRange"), 

storageClass=storageClass) 

registry.registerDatasetType(flatType) 

calexpType = DatasetType(name="CALEXP", dimensions=("Instrument", "Visit", "Detector"), 

storageClass=storageClass) 

registry.registerDatasetType(calexpType) 

 

# add pre-existing raw datasets 

for visit in (10, 11, 20): 

for exposure in (0, 1): 

for detector in (1, 2, 3, 4, 5): 

dataId = dict(instrument="DummyCam", exposure=visit*10+exposure, detector=detector) 

registry.addDataset(rawType, dataId=dataId, run=run) 

 

# add few bias datasets 

for detector in (1, 2, 3, 4, 5): 

# from before first exposure to the end of second exposure 

dataId = dict(instrument="DummyCam", detector=detector, 

valid_first=now-timedelta(seconds=3600), 

valid_last=timestamps[1][1]) 

registry.addDataset(biasType, dataId=dataId, run=run) 

# from start of third exposure to the end of last exposure 

dataId = dict(instrument="DummyCam", detector=detector, 

valid_first=timestamps[2][0], 

valid_last=timestamps[-1][1]) 

registry.addDataset(biasType, dataId=dataId, run=run) 

 

# add few flat datasets, only for subset of detectors and exposures 

for detector in (1, 2, 3): 

# third and fourth exposures 

dataId = dict(instrument="DummyCam", detector=detector, 

physical_filter="dummy_r", 

valid_first=timestamps[2][0], 

valid_last=timestamps[3][1]) 

registry.addDataset(flatType, dataId=dataId, run=run) 

# fifth exposure only 

dataId = dict(instrument="DummyCam", detector=detector, 

physical_filter="dummy_r", 

valid_first=timestamps[4][0], 

valid_last=timestamps[5][0]-timedelta(seconds=1)) 

registry.addDataset(flatType, dataId=dataId, run=run) 

 

# without flat/bias 

originInfo = DatasetOriginInfoDef(defaultInputs=[collection], defaultOutput=collection) 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[rawType], 

futureDatasetTypes=[calexpType], 

expandDataIds=False) 

rows = preFlight.selectDimensions() 

rows = list(rows) 

self.assertEqual(len(rows), 6*5) # 6 exposures times 5 detectors 

for row in rows: 

self.assertCountEqual(row.dataId.keys(), ("instrument", "detector", "exposure", "visit")) 

self.assertCountEqual(row.datasetRefs.keys(), (rawType, calexpType)) 

 

# use bias 

originInfo = DatasetOriginInfoDef(defaultInputs=[collection], defaultOutput=collection) 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[rawType, biasType], 

futureDatasetTypes=[calexpType], 

expandDataIds=False) 

rows = preFlight.selectDimensions() 

rows = list(rows) 

self.assertEqual(len(rows), 6*5) # 6 exposures times 5 detectors 

for row in rows: 

self.assertCountEqual(row.dataId.keys(), 

("instrument", "detector", "exposure", "visit")) 

self.assertCountEqual(row.datasetRefs.keys(), (rawType, biasType, calexpType)) 

 

# use flat 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[rawType, flatType], 

futureDatasetTypes=[calexpType], 

expandDataIds=False) 

rows = preFlight.selectDimensions() 

rows = list(rows) 

self.assertEqual(len(rows), 3*3) # 3 exposures times 3 detectors 

for row in rows: 

self.assertCountEqual(row.dataId.keys(), 

("instrument", "detector", "exposure", "visit", "physical_filter")) 

self.assertCountEqual(row.datasetRefs.keys(), (rawType, flatType, calexpType)) 

 

# use both bias and flat, plus expression 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[rawType, flatType, biasType], 

futureDatasetTypes=[calexpType], 

expandDataIds=False) 

rows = preFlight.selectDimensions(expression="detector IN (1, 3)") 

rows = list(rows) 

self.assertEqual(len(rows), 3*2) # 3 exposures times 2 detectors 

for row in rows: 

self.assertCountEqual(row.dataId.keys(), 

("instrument", "detector", "exposure", "visit", "physical_filter")) 

self.assertCountEqual(row.datasetRefs.keys(), (rawType, flatType, biasType, calexpType)) 

 

# select single exposure (third) and detector and check datasetRefs 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[rawType, flatType, biasType], 

futureDatasetTypes=[calexpType], 

expandDataIds=False) 

rows = preFlight.selectDimensions(expression="Exposure.exposure = 110 AND Detector.detector = 1") 

rows = list(rows) 

self.assertEqual(len(rows), 1) 

row = rows[0] 

self.assertEqual(row.datasetRefs[flatType].dataId, 

dict(instrument="DummyCam", 

detector=1, 

physical_filter="dummy_r", 

valid_first=timestamps[2][0], 

valid_last=timestamps[3][1])) 

self.assertEqual(row.datasetRefs[biasType].dataId, 

dict(instrument="DummyCam", 

detector=1, 

valid_first=timestamps[2][0], 

valid_last=timestamps[-1][1])) 

 

def testPreFlightSkyMapUnits(self): 

"""Test involving only SkyMap units, no joins to Instrument""" 

registry = self.registry 

 

# need a bunch of units and datasets for test, we want "AbstractFilter" 

# in the test so also have to add PhysicalFilter units 

registry.addDimensionEntry("Instrument", dict(instrument="DummyCam")) 

registry.addDimensionEntry("PhysicalFilter", dict(instrument="DummyCam", 

physical_filter="dummy_r", 

abstract_filter="r")) 

registry.addDimensionEntry("PhysicalFilter", dict(instrument="DummyCam", 

physical_filter="dummy_i", 

abstract_filter="i")) 

registry.addDimensionEntry("SkyMap", dict(skymap="DummyMap", hash="sha!".encode("utf8"))) 

for tract in range(10): 

registry.addDimensionEntry("Tract", dict(skymap="DummyMap", tract=tract)) 

for patch in range(10): 

registry.addDimensionEntry("Patch", dict(skymap="DummyMap", tract=tract, patch=patch, 

cell_x=0, cell_y=0, 

region=Box(LonLat(NormalizedAngle(0.), Angle(0.))))) 

 

# dataset types 

collection = "test" 

run = registry.makeRun(collection=collection) 

storageClass = StorageClass("testDataset") 

registry.storageClasses.registerStorageClass(storageClass) 

calexpType = DatasetType(name="deepCoadd_calexp", dimensions=("SkyMap", "Tract", "Patch", 

"AbstractFilter"), 

storageClass=storageClass) 

registry.registerDatasetType(calexpType) 

mergeType = DatasetType(name="deepCoadd_mergeDet", dimensions=("SkyMap", "Tract", "Patch"), 

storageClass=storageClass) 

registry.registerDatasetType(mergeType) 

measType = DatasetType(name="deepCoadd_meas", dimensions=("SkyMap", "Tract", "Patch", 

"AbstractFilter"), 

storageClass=storageClass) 

registry.registerDatasetType(measType) 

 

# add pre-existing datasets 

for tract in (1, 3, 5): 

for patch in (2, 4, 6, 7): 

dataId = dict(skymap="DummyMap", tract=tract, patch=patch) 

registry.addDataset(mergeType, dataId=dataId, run=run) 

for aFilter in ("i", "r"): 

dataId = dict(skymap="DummyMap", tract=tract, patch=patch, abstract_filter=aFilter) 

registry.addDataset(calexpType, dataId=dataId, run=run) 

 

# with empty expression 

originInfo = DatasetOriginInfoDef(defaultInputs=[collection], defaultOutput="") 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[calexpType, mergeType], 

futureDatasetTypes=[measType], 

expandDataIds=False) 

rows = preFlight.selectDimensions() 

rows = list(rows) 

self.assertEqual(len(rows), 3*4*2) # 4 tracts x 4 patches x 2 filters 

for row in rows: 

self.assertCountEqual(row.dataId.keys(), ("skymap", "tract", "patch", "abstract_filter")) 

self.assertCountEqual(row.datasetRefs.keys(), (calexpType, mergeType, measType)) 

self.assertCountEqual(set(row.dataId["tract"] for row in rows), (1, 3, 5)) 

self.assertCountEqual(set(row.dataId["patch"] for row in rows), (2, 4, 6, 7)) 

self.assertCountEqual(set(row.dataId["abstract_filter"] for row in rows), ("i", "r")) 

 

# limit to 2 tracts and 2 patches 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[calexpType, mergeType], 

futureDatasetTypes=[measType], 

expandDataIds=False) 

rows = preFlight.selectDimensions(expression="tract IN (1, 5) AND Patch.patch IN (2, 7)") 

rows = list(rows) 

self.assertEqual(len(rows), 2*2*2) # 4 tracts x 4 patches x 2 filters 

self.assertCountEqual(set(row.dataId["tract"] for row in rows), (1, 5)) 

self.assertCountEqual(set(row.dataId["patch"] for row in rows), (2, 7)) 

self.assertCountEqual(set(row.dataId["abstract_filter"] for row in rows), ("i", "r")) 

 

# limit to single filter 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[calexpType, mergeType], 

futureDatasetTypes=[measType], 

expandDataIds=False) 

rows = preFlight.selectDimensions(expression="abstract_filter = 'i'") 

rows = list(rows) 

self.assertEqual(len(rows), 3*4*1) # 4 tracts x 4 patches x 2 filters 

self.assertCountEqual(set(row.dataId["tract"] for row in rows), (1, 3, 5)) 

self.assertCountEqual(set(row.dataId["patch"] for row in rows), (2, 4, 6, 7)) 

self.assertCountEqual(set(row.dataId["abstract_filter"] for row in rows), ("i",)) 

 

# expression excludes everyhting, specifying non-existing skymap is not a 

# fatal error, it's operator error 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[calexpType, mergeType], 

futureDatasetTypes=[measType], 

expandDataIds=False) 

rows = preFlight.selectDimensions(expression="skymap = 'Mars'") 

rows = list(rows) 

self.assertEqual(len(rows), 0) 

 

def testPreFlightSpatialMatch(self): 

"""Test involving spacial match using join tables. 

 

Note that realistic test needs a resonably-defined SkyPix and regions 

in registry tables which is hard to implement in this simple test. 

So we do not actually fill registry with any data and all queries will 

return empty result, but this is still useful for coverage of the code 

that generates query. 

""" 

registry = self.registry 

 

# dataset types 

collection = "test" 

registry.makeRun(collection=collection) 

storageClass = StorageClass("testDataset") 

registry.storageClasses.registerStorageClass(storageClass) 

 

calexpType = DatasetType(name="CALEXP", dimensions=("Instrument", "Visit", "Detector"), 

storageClass=storageClass) 

registry.registerDatasetType(calexpType) 

 

coaddType = DatasetType(name="deepCoadd_calexp", dimensions=("SkyMap", "Tract", "Patch", 

"AbstractFilter"), 

storageClass=storageClass) 

registry.registerDatasetType(coaddType) 

 

# without data this should run OK but return empty set 

originInfo = DatasetOriginInfoDef(defaultInputs=[collection], defaultOutput="") 

preFlight = SqlPreFlight(self.registry, originInfo=originInfo, 

neededDatasetTypes=[calexpType], 

futureDatasetTypes=[coaddType], 

expandDataIds=False) 

rows = preFlight.selectDimensions() 

rows = list(rows) 

self.assertEqual(len(rows), 0) 

 

 

class MemoryTester(lsst.utils.tests.MemoryTestCase): 

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()