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# LSST Data Management System 

2# Copyright 2008-2019 AURA/LSST. 

3# 

4# This product includes software developed by the 

5# LSST Project (http://www.lsst.org/). 

6# 

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

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

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

10# (at your option) any later version. 

11# 

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

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

14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

15# GNU General Public License for more details. 

16# 

17# You should have received a copy of the LSST License Statement and 

18# the GNU General Public License along with this program. If not, 

19# see <https://www.lsstcorp.org/LegalNotices/>. 

20"""Main driver functions for metric measurements, plotting, specification 

21grading, and persistence. 

22""" 

23 

24__all__ = ['plot_metrics', 'print_metrics', 'print_pass_fail_summary', 

25 'run', 'runOneFilter'] 

26 

27import json 

28import os 

29import numpy as np 

30import astropy.units as u 

31 

32from textwrap import TextWrapper 

33import astropy.visualization 

34 

35from lsst.verify import Name 

36from lsst.verify import Job, MetricSet, SpecificationSet 

37from lsst import log 

38from lsst.daf.persistence import Butler 

39 

40from .util import repoNameToPrefix 

41from .matchreduce import build_matched_dataset 

42from .photerrmodel import build_photometric_error_model 

43from .astromerrmodel import build_astrometric_error_model 

44from .calcnonsrd import measure_model_phot_rep 

45from .calcsrd import (measurePA1, measurePA2, measurePF1, measureAMx, 

46 measureAFx, measureADx, measureTEx) 

47from .plot import (plotAMx, plotPA1, plotTEx, plotPhotometryErrorModel, 

48 plotAstrometryErrorModel) 

49 

50 

51class Bcolors: 

52 HEADER = '\033[95m' 

53 OKBLUE = '\033[94m' 

54 OKGREEN = '\033[92m' 

55 WARNING = '\033[93m' 

56 FAIL = '\033[91m' 

57 ENDC = '\033[0m' 

58 BOLD = '\033[1m' 

59 UNDERLINE = '\033[4m' 

60 

61 

62def load_json_output(filepath, metrics_package='verify_metrics'): 

63 """Read JSON from a file into a job object. 

64 

65 Currently just does a trivial de-serialization with no checking 

66 to make sure that one results with a valid validate.base.job object. 

67 

68 Parameters 

69 ---------- 

70 filepath : `str` 

71 Source file name for JSON output. 

72 

73 Returns 

74 ------- 

75 job : A `validate.base.job` object. 

76 """ 

77 with open(filepath, 'r') as infile: 

78 json_data = json.load(infile) 

79 

80 job = Job.deserialize(**json_data) 

81 metrics = MetricSet.load_metrics_package(metrics_package) 

82 job.metrics.update(metrics) 

83 specs = SpecificationSet.load_metrics_package(metrics_package) 

84 job.specs.update(specs) 

85 return job 

86 

87 

88def get_filter_name_from_job(job): 

89 """Get the filtername from a validate.base.job object 

90 

91 Assumes there is only one filter name and that it's the one in 

92 the first measurement 

93 

94 Parameters 

95 ---------- 

96 job : `validate.base.job` object 

97 

98 Returns 

99 ------- 

100 filter_name : `str` 

101 """ 

102 

103 return job.meta['filter_name'] 

104 

105 

106def run(repo_or_json, outputPrefix=None, makePrint=True, makePlot=True, 

107 level='design', metrics_package='verify_metrics', **kwargs): 

108 """Main entrypoint from ``validateDrp.py``. 

109 

110 Parameters 

111 ---------- 

112 repo_or_json : `str` 

113 The repository. This is generally the directory on disk 

114 that contains the repository and mapper. 

115 This can also be the filepath for a JSON file that contains 

116 the cached output from a previous run. 

117 makePrint : `bool`, optional 

118 Print calculated quantities (to stdout). 

119 makePlot : `bool`, optional 

120 Create plots for metrics. Saved to current working directory. 

121 level : `str` 

122 Use <level> E.g., 'design', 'minimum', 'stretch'. 

123 """ 

124 base_name, ext = os.path.splitext(repo_or_json) 

125 if ext == '.json': 

126 load_json = True 

127 else: 

128 load_json = False 

129 

130 # I think I have to interrogate the kwargs to maintain compatibility 

131 # between Python 2 and Python 3 

132 # In Python 3 I would have let me mix in a keyword default after *args 

133 if outputPrefix is None: 

134 outputPrefix = repoNameToPrefix(base_name) 

135 

136 if load_json: 

137 if not os.path.isfile(repo_or_json): 

138 print("Could not find JSON file %s" % (repo_or_json)) 

139 return 

140 

141 json_path = repo_or_json 

142 job = load_json_output(json_path, metrics_package) 

143 filterName = get_filter_name_from_job(job) 

144 jobs = {filterName: job} 

145 else: 

146 if not os.path.isdir(repo_or_json): 

147 print("Could not find repo %s" % (repo_or_json)) 

148 return 

149 

150 repo_path = repo_or_json 

151 jobs = runOneRepo(repo_path, outputPrefix=outputPrefix, 

152 metrics_package=metrics_package, **kwargs) 

153 

154 for filterName, job in jobs.items(): 

155 if makePrint: 

156 print_metrics(job) 

157 if makePlot: 

158 if outputPrefix is None or outputPrefix == '': 

159 thisOutputPrefix = "%s" % filterName 

160 else: 

161 thisOutputPrefix = "%s_%s" % (outputPrefix, filterName) 

162 plot_metrics(job, filterName, outputPrefix=thisOutputPrefix) 

163 

164 print_pass_fail_summary(jobs, default_level=level) 

165 

166 

167def runOneRepo(repo, dataIds=None, outputPrefix='', verbose=False, 

168 instrument=None, dataset_repo_url=None, 

169 metrics_package='verify_metrics', **kwargs): 

170 r"""Calculate statistics for all filters in a repo. 

171 

172 Runs multiple filters, if necessary, through repeated calls to `runOneFilter`. 

173 Assesses results against SRD specs at specified `level`. 

174 

175 Parameters 

176 --------- 

177 repo : `str` 

178 The repository. This is generally the directory on disk 

179 that contains the repository and mapper. 

180 dataIds : `list` of `dict` 

181 List of butler data IDs of Image catalogs to compare to reference. 

182 The calexp cpixel image is needed for the photometric calibration. 

183 Tract IDs must be included if "doApplyExternalPhotoCalib" or 

184 "doApplyExternalSkyWcs" is True. 

185 outputPrefix : `str`, optional 

186 Specify the beginning filename for output files. 

187 The name of each filter will be appended to outputPrefix. 

188 level : `str`, optional 

189 The level of the specification to check: "design", "minimum", "stretch". 

190 verbose : `bool` 

191 Provide detailed output. 

192 instrument : `str` 

193 Name of the instrument. If None will be extracted from the Butler mapper. 

194 dataset_repo_url : `str` 

195 Location of the dataset used. If None will be set to the path of the repo. 

196 metrics_package : `string` 

197 Name of the metrics package to be used in the Jobs created. 

198 

199 Notes 

200 ----- 

201 Names of plot files or JSON file are generated based on repository name, 

202 unless overriden by specifying `ouputPrefix`. 

203 E.g., Analyzing a repository ``CFHT/output`` 

204 will result in filenames that start with ``CFHT_output_``. 

205 The filter name is added to this prefix. If the filter name has spaces, 

206 there will be annoyance and sadness as those spaces will appear in the filenames. 

207 """ 

208 

209 def extract_instrument_from_repo(repo): 

210 """Extract the last part of the mapper name from a Butler repo. 

211 'lsst.obs.lsstSim.lsstSimMapper.LsstSimMapper' -> 'LSSTSIM' 

212 'lsst.obs.cfht.megacamMapper.MegacamMapper' -> 'CFHT' 

213 'lsst.obs.decam.decamMapper.DecamMapper' -> 'DECAM' 

214 'lsst.obs.hsc.hscMapper.HscMapper' -> 'HSC' 

215 """ 

216 mapper_class = Butler.getMapperClass(repo) 

217 instrument = mapper_class.getCameraName() 

218 return instrument.upper() 

219 

220 if instrument is None: 

221 instrument = extract_instrument_from_repo(repo) 

222 if dataset_repo_url is None: 

223 dataset_repo_url = repo 

224 

225 allFilters = set([d['filter'] for d in dataIds]) 

226 

227 jobs = {} 

228 for filterName in allFilters: 

229 # Do this here so that each outputPrefix will have a different name for each filter. 

230 if outputPrefix is None or outputPrefix == '': 

231 thisOutputPrefix = "%s" % filterName 

232 else: 

233 thisOutputPrefix = "%s_%s" % (outputPrefix, filterName) 

234 theseVisitDataIds = [v for v in dataIds if v['filter'] == filterName] 

235 job = runOneFilter(repo, theseVisitDataIds, 

236 outputPrefix=thisOutputPrefix, 

237 verbose=verbose, filterName=filterName, 

238 instrument=instrument, 

239 dataset_repo_url=dataset_repo_url, 

240 metrics_package=metrics_package, **kwargs) 

241 jobs[filterName] = job 

242 

243 return jobs 

244 

245 

246def runOneFilter(repo, visitDataIds, brightSnrMin=None, brightSnrMax=None, 

247 makeJson=True, filterName=None, outputPrefix='', 

248 doApplyExternalPhotoCalib=False, externalPhotoCalibName=None, 

249 doApplyExternalSkyWcs=False, externalSkyWcsName=None, 

250 skipTEx=False, verbose=False, 

251 metrics_package='verify_metrics', 

252 instrument='Unknown', dataset_repo_url='./', 

253 skipNonSrd=False, **kwargs): 

254 r"""Main executable for the case where there is just one filter. 

255 

256 Plot files and JSON files are generated in the local directory 

257 prefixed with the repository name (where '_' replace path separators), 

258 unless overriden by specifying `outputPrefix`. 

259 E.g., Analyzing a repository ``CFHT/output`` 

260 will result in filenames that start with ``CFHT_output_``. 

261 

262 Parameters 

263 ---------- 

264 repo : string or Butler 

265 A Butler or a repository URL that can be used to construct one. 

266 dataIds : list of dict 

267 List of `butler` data IDs of Image catalogs to compare to reference. 

268 The `calexp` pixel image is needed for the photometric calibration 

269 unless doApplyExternalPhotoCalib is True such 

270 that the appropriate `photoCalib` dataset is used. Note that these 

271 have data IDs that include the tract number. 

272 brightSnrMin : float, optional 

273 Minimum median SNR for a source to be considered bright; passed to 

274 `lsst.validate.drp.matchreduce.build_matched_dataset`. 

275 brightSnrMax : float, optional 

276 Maximum median SNR for a source to be considered bright; passed to 

277 `lsst.validate.drp.matchreduce.build_matched_dataset`. 

278 makeJson : bool, optional 

279 Create JSON output file for metrics. Saved to current working directory. 

280 outputPrefix : str, optional 

281 Specify the beginning filename for output files. 

282 filterName : str, optional 

283 Name of the filter (bandpass). 

284 doApplyExternalPhotoCalib : bool, optional 

285 Apply external photoCalib to calibrate fluxes. 

286 externalPhotoCalibName : str, optional 

287 Type of external `PhotoCalib` to apply. Currently supported are jointcal, 

288 fgcm, and fgcm_tract. Must be set if doApplyExternalPhotoCalib is True. 

289 doApplyExternalSkyWcs : bool, optional 

290 Apply external wcs to calibrate positions. 

291 externalSkyWcsName : str, optional 

292 Type of external `wcs` to apply. Currently supported is jointcal. 

293 Must be set if "doApplyExternalSkyWcs" is True. 

294 skipTEx : bool, optional 

295 Skip TEx calculations (useful for older catalogs that don't have 

296 PsfShape measurements). 

297 verbose : bool, optional 

298 Output additional information on the analysis steps. 

299 skipNonSrd : bool, optional 

300 Skip any metrics not defined in the LSST SRD. 

301 

302 Raises 

303 ------ 

304 RuntimeError: 

305 Raised if "doApplyExternalPhotoCalib" is True and "externalPhotoCalibName" 

306 is None, or if "doApplyExternalSkyWcs" is True and "externalSkyWcsName" is 

307 None. 

308 """ 

309 

310 if kwargs: 

311 log.warn(f"Extra kwargs - {kwargs}, will be ignored. Did you add extra things to your config file?") 

312 

313 if doApplyExternalPhotoCalib and externalPhotoCalibName is None: 

314 raise RuntimeError("Must set externalPhotoCalibName if doApplyExternalPhotoCalib is True.") 

315 if doApplyExternalSkyWcs and externalSkyWcsName is None: 

316 raise RuntimeError("Must set externalSkyWcsName if doApplyExternalSkyWcs is True.") 

317 

318 job = Job.load_metrics_package(meta={'instrument': instrument, 

319 'filter_name': filterName, 

320 'dataset_repo_url': dataset_repo_url}, 

321 subset='validate_drp', 

322 package_name_or_path=metrics_package) 

323 

324 matchedDataset = build_matched_dataset(repo, visitDataIds, 

325 doApplyExternalPhotoCalib=doApplyExternalPhotoCalib, 

326 externalPhotoCalibName=externalPhotoCalibName, 

327 doApplyExternalSkyWcs=doApplyExternalSkyWcs, 

328 externalSkyWcsName=externalSkyWcsName, 

329 skipTEx=skipTEx, skipNonSrd=skipNonSrd, 

330 brightSnrMin=brightSnrMin, brightSnrMax=brightSnrMax) 

331 

332 photomModel = build_photometric_error_model(matchedDataset) 

333 astromModel = build_astrometric_error_model(matchedDataset) 

334 

335 linkedBlobs = [matchedDataset, photomModel, astromModel] 

336 

337 metrics = job.metrics 

338 specs = job.specs 

339 

340 def add_measurement(measurement): 

341 for blob in linkedBlobs: 

342 measurement.link_blob(blob) 

343 job.measurements.insert(measurement) 

344 

345 for x, D in zip((1, 2, 3), (5., 20., 200.)): 

346 amxName = 'AM{0:d}'.format(x) 

347 afxName = 'AF{0:d}'.format(x) 

348 adxName = 'AD{0:d}'.format(x) 

349 

350 amx = measureAMx(metrics['validate_drp.'+amxName], matchedDataset, D*u.arcmin, verbose=verbose) 

351 add_measurement(amx) 

352 

353 afx_spec_set = specs.subset(required_meta={'instrument': 'HSC'}, spec_tags=[afxName, ]) 

354 adx_spec_set = specs.subset(required_meta={'instrument': 'HSC'}, spec_tags=[adxName, ]) 

355 for afx_spec_key, adx_spec_key in zip(afx_spec_set, adx_spec_set): 

356 afx_spec = afx_spec_set[afx_spec_key] 

357 adx_spec = adx_spec_set[adx_spec_key] 

358 adx = measureADx(metrics[adx_spec.metric_name], amx, afx_spec) 

359 add_measurement(adx) 

360 afx = measureAFx(metrics[afx_spec.metric_name], amx, adx, adx_spec) 

361 add_measurement(afx) 

362 

363 pa1 = measurePA1( 

364 metrics['validate_drp.PA1'], filterName, matchedDataset.matchesBright, matchedDataset.magKey) 

365 add_measurement(pa1) 

366 

367 pf1_spec_set = specs.subset(required_meta={'instrument': instrument, 'filter_name': filterName}, 

368 spec_tags=['PF1', ]) 

369 pa2_spec_set = specs.subset(required_meta={'instrument': instrument, 'filter_name': filterName}, 

370 spec_tags=['PA2', ]) 

371 # I worry these might not always be in the right order. Sorting... 

372 pf1_spec_keys = list(pf1_spec_set.keys()) 

373 pa2_spec_keys = list(pa2_spec_set.keys()) 

374 pf1_spec_keys.sort() 

375 pa2_spec_keys.sort() 

376 for pf1_spec_key, pa2_spec_key in zip(pf1_spec_keys, pa2_spec_keys): 

377 pf1_spec = pf1_spec_set[pf1_spec_key] 

378 pa2_spec = pa2_spec_set[pa2_spec_key] 

379 

380 pa2 = measurePA2(metrics[pa2_spec.metric_name], pa1, pf1_spec.threshold) 

381 add_measurement(pa2) 

382 

383 pf1 = measurePF1(metrics[pf1_spec.metric_name], pa1, pa2_spec) 

384 add_measurement(pf1) 

385 

386 if not skipTEx: 

387 for x, D, bin_range_operator in zip((1, 2), (1.0, 5.0), ("<=", ">=")): 

388 texName = 'TE{0:d}'.format(x) 

389 tex = measureTEx(metrics['validate_drp.'+texName], matchedDataset, D*u.arcmin, 

390 bin_range_operator, verbose=verbose) 

391 add_measurement(tex) 

392 

393 if not skipNonSrd: 

394 model_phot_reps = measure_model_phot_rep(metrics, filterName, matchedDataset) 

395 for measurement in model_phot_reps: 

396 add_measurement(measurement) 

397 

398 if makeJson: 

399 job.write(outputPrefix+'.json') 

400 

401 return job 

402 

403 

404def get_metric(level, metric_label, in_specs): 

405 for spec in in_specs: 

406 if level in str(spec) and metric_label in str(spec): 

407 break 

408 return Name(package=spec.package, metric=spec.metric) 

409 

410 

411def plot_metrics(job, filterName, outputPrefix=''): 

412 """Plot AM1, AM2, AM3, PA1 plus related informational plots. 

413 

414 Parameters 

415 ---------- 

416 job : `lsst.validate.base.Job` 

417 The job to load data from. 

418 filterName : `str` 

419 string identifying the filter. 

420 """ 

421 astropy.visualization.quantity_support() 

422 

423 specs = job.specs 

424 measurements = job.measurements 

425 spec_name = 'design' 

426 for x in (1, 2, 3): 

427 amxName = 'AM{0:d}'.format(x) 

428 afxName = 'AF{0:d}'.format(x) 

429 # ADx is included on the AFx plots 

430 

431 amx = measurements[get_metric(spec_name, amxName, specs)] 

432 afx = measurements[get_metric(spec_name, afxName, specs)] 

433 

434 if amx.quantity is not None: 

435 try: 

436 plotAMx(job, amx, afx, filterName, amxSpecName=spec_name, 

437 outputPrefix=outputPrefix) 

438 except RuntimeError as e: 

439 print(e) 

440 print('\tSkipped plot{}'.format(amxName)) 

441 

442 try: 

443 pa1 = measurements[get_metric(spec_name, 'PA1', specs)] 

444 plotPA1(pa1, outputPrefix=outputPrefix) 

445 except RuntimeError as e: 

446 print(e) 

447 print('\tSkipped plotPA1') 

448 

449 try: 

450 matchedDataset = pa1.blobs['MatchedMultiVisitDataset'] 

451 photomModel = pa1.blobs['PhotometricErrorModel'] 

452 filterName = pa1.extras['filter_name'] 

453 plotPhotometryErrorModel(matchedDataset, photomModel, 

454 filterName=filterName, 

455 outputPrefix=outputPrefix) 

456 except KeyError as e: 

457 print(e) 

458 print('\tSkipped plotPhotometryErrorModel') 

459 

460 try: 

461 am1 = measurements[get_metric(spec_name, 'AM1', specs)] 

462 matchedDataset = am1.blobs['MatchedMultiVisitDataset'] 

463 astromModel = am1.blobs['AnalyticAstrometryModel'] 

464 plotAstrometryErrorModel(matchedDataset, astromModel, 

465 outputPrefix=outputPrefix) 

466 except KeyError as e: 

467 print(e) 

468 print('\tSkipped plotAstrometryErrorModel') 

469 

470 for x in (1, 2): 

471 texName = 'TE{0:d}'.format(x) 

472 

473 try: 

474 measurement = measurements[get_metric(spec_name, texName, specs)] 

475 plotTEx(job, measurement, filterName, 

476 texSpecName='design', 

477 outputPrefix=outputPrefix) 

478 except (RuntimeError, KeyError) as e: 

479 print(e) 

480 print('\tSkipped plot{}'.format(texName)) 

481 

482 

483def get_specs_metrics(job): 

484 # Get specs for this filter 

485 subset = job.specs.subset(required_meta={'instrument': job.meta['instrument'], 

486 'filter_name': job.meta['filter_name']}, 

487 spec_tags=['chromatic']) 

488 # Get specs that don't depend on filter 

489 subset.update(job.specs.subset(required_meta={'instrument': job.meta['instrument']}, 

490 spec_tags=['achromatic'])) 

491 metrics = {} 

492 specs = {} 

493 for spec in subset: 

494 metric_name = spec.metric.split('_')[0] # Take first part for linked metrics 

495 if metric_name in metrics: 

496 metrics[metric_name].append(Name(package=spec.package, metric=spec.metric)) 

497 specs[metric_name].append(spec) 

498 else: 

499 metrics[metric_name] = [Name(package=spec.package, metric=spec.metric), ] 

500 specs[metric_name] = [spec, ] 

501 return specs, metrics 

502 

503 

504def print_metrics(job, levels=('minimum', 'design', 'stretch')): 

505 specs, metrics = get_specs_metrics(job) 

506 

507 print(Bcolors.BOLD + Bcolors.HEADER + "=" * 65 + Bcolors.ENDC) 

508 print(Bcolors.BOLD + Bcolors.HEADER + 

509 '{band} band metric measurements'.format(band=job.meta['filter_name']) + 

510 Bcolors.ENDC) 

511 print(Bcolors.BOLD + Bcolors.HEADER + "=" * 65 + Bcolors.ENDC) 

512 

513 wrapper = TextWrapper(width=65) 

514 for metric_name, metric_set in metrics.items(): 

515 metric = job.metrics[metric_set[0]] # Pick the first one for the description 

516 print(Bcolors.HEADER + '{name} - {reference}'.format( 

517 name=metric.name, reference=metric.reference)) 

518 print(wrapper.fill(Bcolors.ENDC + '{description}'.format( 

519 description=metric.description).strip())) 

520 

521 for spec_key, metric_key in zip(specs[metric_name], metrics[metric_name]): 

522 level = None 

523 if 'release' in job.specs[spec_key].tags: 

524 # Skip release specs 

525 continue 

526 for l in levels: 

527 if l in str(spec_key): 

528 level = l 

529 try: 

530 m = job.measurements[metric_key] 

531 except KeyError: 

532 print('\tSkipped {metric_key:12s} with spec {spec}: no such measurement'.format( 

533 metric_key=metric_name, spec=level)) 

534 continue 

535 

536 if np.isnan(m.quantity): 

537 print('\tSkipped {metric_key:12s} no measurement'.format( 

538 metric_key=".".join([metric_name, level]))) 

539 continue 

540 

541 spec = job.specs[spec_key] 

542 passed = spec.check(m.quantity) 

543 if passed: 

544 prefix = Bcolors.OKBLUE + '\tPassed ' 

545 else: 

546 prefix = Bcolors.FAIL + '\tFailed ' 

547 infoStr = '{specName:12s} {meas:.4g} {op} {spec:.4g}'.format( 

548 specName=level, 

549 meas=m.quantity, 

550 op=spec.operator_str, 

551 spec=spec.threshold) 

552 print(prefix + infoStr + Bcolors.ENDC) 

553 

554 

555def print_pass_fail_summary(jobs, levels=('minimum', 'design', 'stretch'), default_level='design'): 

556 currentTestCount = 0 

557 currentFailCount = 0 

558 currentSkippedCount = 0 

559 

560 for filterName, job in jobs.items(): 

561 specs, metrics = get_specs_metrics(job) 

562 print('') 

563 print(Bcolors.BOLD + Bcolors.HEADER + "=" * 65 + Bcolors.ENDC) 

564 print(Bcolors.BOLD + Bcolors.HEADER + '{0} band summary'.format(filterName) + Bcolors.ENDC) 

565 print(Bcolors.BOLD + Bcolors.HEADER + "=" * 65 + Bcolors.ENDC) 

566 

567 for specName in levels: 

568 measurementCount = 0 

569 failCount = 0 

570 skippedCount = 0 

571 for key, m in job.measurements.items(): 

572 metric = key.metric.split("_") # For compound metrics 

573 len_metric = len(metric) 

574 if len_metric > 1: 

575 if metric[1] != specName: 

576 continue 

577 if len_metric > 2 and filterName not in metric[2]: 

578 continue 

579 spec_set = specs.get(metric[0], None) 

580 if spec_set is None: 

581 continue 

582 spec = None 

583 for spec_key in spec_set: 

584 if specName in spec_key.spec: 

585 spec = job.specs[spec_key] 

586 if spec is None: 

587 for spec_key in spec_set: 

588 if specName in spec_key.metric: # For dependent metrics 

589 spec = job.specs[spec_key] 

590 if spec is not None: 

591 measurementCount += 1 

592 if np.isnan(m.quantity): 

593 skippedCount += 1 

594 if not spec.check(m.quantity): 

595 failCount += 1 

596 

597 if specName == default_level: 

598 currentTestCount += measurementCount 

599 currentFailCount += failCount 

600 currentSkippedCount += skippedCount 

601 

602 if failCount == 0: 

603 print('Passed {level:12s} {count:d} measurements ({skipped:d} skipped)'.format( 

604 level=specName, count=measurementCount, skipped=skippedCount)) 

605 else: 

606 msg = 'Failed {level:12s} {failCount} of {count:d} failed ({skipped:d} skipped)'.format( 

607 level=specName, failCount=failCount, count=measurementCount, skipped=skippedCount) 

608 print(Bcolors.FAIL + msg + Bcolors.ENDC) 

609 

610 print(Bcolors.BOLD + Bcolors.HEADER + "=" * 65 + Bcolors.ENDC + '\n') 

611 

612 # print summary against current spec level 

613 print(Bcolors.BOLD + Bcolors.HEADER + "=" * 65 + Bcolors.ENDC) 

614 print(Bcolors.BOLD + Bcolors.HEADER + '{0} level summary'.format(default_level) + Bcolors.ENDC) 

615 print(Bcolors.BOLD + Bcolors.HEADER + "=" * 65 + Bcolors.ENDC) 

616 if currentFailCount > 0: 

617 msg = 'FAILED ({failCount:d}/{count:d} measurements, ({skipped:d} skipped))'.format( 

618 failCount=currentFailCount, count=currentTestCount, skipped=currentSkippedCount) 

619 print(Bcolors.FAIL + msg + Bcolors.ENDC) 

620 else: 

621 print('PASSED ({count:d}/{count:d} measurements ({skipped:d} skipped))'.format( 

622 count=currentTestCount, skipped=currentSkippedCount)) 

623 

624 print(Bcolors.BOLD + Bcolors.HEADER + "=" * 65 + Bcolors.ENDC)