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

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

from __future__ import print_function, division 

 

import numpy as np 

import lsst.sims.maf.metrics as metrics 

import lsst.sims.maf.slicers as slicers 

import lsst.sims.maf.stackers as stackers 

import lsst.sims.maf.plots as plots 

import lsst.sims.maf.metricBundles as mb 

from .colMapDict import ColMapDict 

from .common import summaryCompletenessAtTime, summaryCompletenessOverH 

import warnings 

 

__all__ = ['setupMoSlicer', 'quickDiscoveryBatch', 'discoveryBatch', 'addMoCompletenessBundles', 

'characterizationBatch'] 

 

 

def setupMoSlicer(orbitFile, Hrange, obsFile=None): 

""" 

Set up the slicer and read orbitFile and obsFile from disk. 

 

Parameters 

---------- 

orbitFile : str 

The file containing the orbit information. 

Hrange : numpy.ndarray or None 

The Hrange parameter to pass to slicer.readOrbits 

obsFile : str, optional 

The file containing the observations of each object, optional. 

If not provided (default, None), then the slicer will not be able to 'slice', but can still plot. 

 

Returns 

------- 

~lsst.sims.maf.slicer.MoObjSlicer 

""" 

# Read the orbit file and set the H values for the slicer. 

slicer = slicers.MoObjSlicer(Hrange=Hrange) 

slicer.setupSlicer(orbitFile=orbitFile, obsFile=obsFile) 

return slicer 

 

 

def quickDiscoveryBatch(slicer, colmap=None, runName='opsim', detectionLosses='detection', metadata='', 

albedo=None, Hmark=None, npReduce=np.mean, times=None, constraint=None): 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

plotBundles = [] 

 

basicPlotDict = {'albedo': albedo, 'Hmark': Hmark, 'npReduce': npReduce, 

'nxbins': 200, 'nybins': 200} 

plotFuncs = [plots.MetricVsH()] 

displayDict ={'group': 'Discovery'} 

 

if detectionLosses not in ('detection', 'trailing'): 

raise ValueError('Please choose detection or trailing as options for detectionLosses.') 

if detectionLosses == 'trailing': 

magStacker = stackers.MoMagStacker(lossCol='dmagTrail') 

detectionLosses = ' trailing loss' 

else: 

magStacker = stackers.MoMagStacker(lossCol='dmagDetect') 

detectionLosses = ' detection loss' 

 

if times is None: 

try: 

timestep = 30 

times = np.arange(slicer.obs[colmap['mjd']].min(), slicer.obs[colmap['mjd']].max() + timestep/2, 

timestep) 

except AttributeError: 

raise warnings.warn('Cannot set times for completeness summary metrics. Will set up bundles, ' 

'but without summary metrics.') 

 

if Hmark is None: 

Hval = slicer.Hrange.mean() 

else: 

Hval = Hmark 

 

# Set up the summary metrics. 

if times is not None: 

summaryTimeMetrics = summaryCompletenessAtTime(times, Hval=Hval, Hindex=0.33) 

else: 

summaryTimeMetrics = None 

summaryHMetrics = summaryCompletenessOverH(requiredChances=1, Hindex=0.33) 

 

# Set up a dictionary to pass to each metric for the column names. 

colkwargs = {'mjdCol': colmap['mjd'], 'seeingCol': colmap['seeingGeom'], 

'expTimeCol': colmap['exptime'], 'm5Col': colmap['fiveSigmaDepth'], 

'nightCol': colmap['night'], 'filterCol': colmap['filter']} 

 

def _setup_child_metrics(parentMetric): 

childMetrics = {} 

childMetrics['Time'] = metrics.Discovery_TimeMetric(parentMetric, **colkwargs) 

childMetrics['N_Chances'] = metrics.Discovery_N_ChancesMetric(parentMetric, **colkwargs) 

# Could expand to add N_chances per year, but not really necessary. 

return childMetrics 

 

def _configure_child_bundles(parentBundle): 

dispDict = {'group': 'Discovery', 'subgroup': 'Time', 

'caption': 'Time of discovery of objects', 'order': 0} 

parentBundle.childBundles['Time'].setDisplayDict(dispDict) 

parentBundle.childBundles['Time'].setSummaryMetrics(summaryTimeMetrics) 

dispDict = {'group': 'Discovery', 'subgroup': 'NChances', 

'caption': 'Number of chances for discovery of objects', 'order': 0} 

parentBundle.childBundles['N_Chances'].setDisplayDict(dispDict) 

parentBundle.childBundles['N_Chances'].setSummaryMetrics(summaryHMetrics) 

return 

 

# 3 pairs in 15 

md = metadata + ' 3 pairs in 15 nights SNR=5' + detectionLosses 

# Set up plot dict. 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90./60./24., 

nNightsPerWindow=3, tWindow=15, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# 3 pairs in 30 

md = metadata + ' 3 pairs in 30 nights SNR=5' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=3, tWindow=30, snrLimit=5, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# Set the runName for all bundles and return the bundleDict. 

for b in bundleList: 

b.setRunName(runName) 

return mb.makeBundlesDictFromList(bundleList), plotBundles 

 

 

def discoveryBatch(slicer, colmap=None, runName='opsim', detectionLosses='detection', metadata='', 

albedo=None, Hmark=None, npReduce=np.mean, times=None, constraint=None): 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

plotBundles = [] 

 

basicPlotDict = {'albedo': albedo, 'Hmark': Hmark, 'npReduce': npReduce, 

'nxbins': 200, 'nybins': 200} 

plotFuncs = [plots.MetricVsH()] 

displayDict ={'group': 'Discovery'} 

 

if detectionLosses not in ('detection', 'trailing'): 

raise ValueError('Please choose detection or trailing as options for detectionLosses.') 

if detectionLosses == 'trailing': 

# These are the SNR-losses only. 

magStacker = stackers.MoMagStacker(lossCol='dmagTrail') 

detectionLosses = ' trailing loss' 

else: 

# This is SNR losses, plus additional loss due to detecting with stellar PSF. 

magStacker = stackers.MoMagStacker(lossCol='dmagDetect') 

detectionLosses = ' detection loss' 

 

if times is None: 

try: 

timestep = 30 

times = np.arange(slicer.obs[colmap['mjd']].min(), slicer.obs[colmap['mjd']].max() + timestep/2, 

timestep) 

except AttributeError: 

raise warnings.warn('Cannot set times for completeness summary metrics. Will set up bundles, ' 

'but without summary metrics.') 

 

if Hmark is None: 

Hval = slicer.Hrange.mean() 

else: 

Hval = Hmark 

 

# Set up the summary metrics. 

if times is not None: 

summaryTimeMetrics = summaryCompletenessAtTime(times, Hval=Hval, Hindex=0.33) 

else: 

summaryTimeMetrics = None 

summaryHMetrics = summaryCompletenessOverH(requiredChances=1, Hindex=0.33) 

 

# Set up a dictionary to pass to each metric for the column names. 

colkwargs = {'mjdCol': colmap['mjd'], 'seeingCol': colmap['seeingGeom'], 

'expTimeCol': colmap['exptime'], 'm5Col': colmap['fiveSigmaDepth'], 

'nightCol': colmap['night'], 'filterCol': colmap['filter']} 

 

def _setup_child_metrics(parentMetric): 

childMetrics = {} 

childMetrics['Time'] = metrics.Discovery_TimeMetric(parentMetric, **colkwargs) 

childMetrics['N_Chances'] = metrics.Discovery_N_ChancesMetric(parentMetric, **colkwargs) 

# Could expand to add N_chances per year, but not really necessary. 

return childMetrics 

 

def _configure_child_bundles(parentBundle): 

dispDict = {'group': 'Discovery', 'subgroup': 'Time', 

'caption': 'Time of discovery of objects', 'order': 0} 

parentBundle.childBundles['Time'].setDisplayDict(dispDict) 

parentBundle.childBundles['Time'].setSummaryMetrics(summaryTimeMetrics) 

dispDict = {'group': 'Discovery', 'subgroup': 'NChances', 

'caption': 'Number of chances for discovery of objects', 'order': 0} 

parentBundle.childBundles['N_Chances'].setDisplayDict(dispDict) 

parentBundle.childBundles['N_Chances'].setSummaryMetrics(summaryHMetrics) 

return 

 

# First standard SNR / probabilistic visibility (SNR~5) 

# 3 pairs in 15 

md = metadata + ' 3 pairs in 15 nights' + detectionLosses 

# Set up plot dict. 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90./60./24., 

nNightsPerWindow=3, tWindow=15, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# 3 pairs in 12 

md = metadata + ' 3 pairs in 12 nights' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=3, tWindow=12, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# 3 pairs in 20 

md = metadata + ' 3 pairs in 20 nights' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=3, tWindow=20, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# 3 pairs in 25 

md = metadata + ' 3 pairs in 25 nights' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=3, tWindow=25, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# 3 pairs in 30 

md = metadata + ' 3 pairs in 30 nights' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=3, tWindow=30, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# 4 pairs in 20 

md = metadata + ' 4 pairs in 20 nights' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=4, tWindow=20, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# 3 triplets in 30 

md = metadata + ' 3 triplets in 30 nights' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=3, tMin=0, tMax=120. / 60. / 24., 

nNightsPerWindow=3, tWindow=30, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# 3 quads in 30 

md = metadata + ' 3 quads in 30 nights' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=4, tMin=0, tMax=150. / 60. / 24., 

nNightsPerWindow=3, tWindow=30, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# Play with SNR. SNR=4. Normal detection losses. 

# 3 pairs in 15 

md = metadata + ' 3 pairs in 15 nights SNR=4' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=3, tWindow=15, snrLimit=4, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# 3 pairs in 30, SNR=4 

md = metadata + ' 3 pairs in 30 nights SNR=4' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=3, tWindow=30, snrLimit=4, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# Play with SNR. SNR=3 

# 3 pairs in 15, SNR=3 

md = metadata + ' 3 pairs in 15 nights SNR=3' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=3, tWindow=15, snrLimit=3, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# SNR = 0 

# 3 pairs in 15, SNR=0 

md = metadata + ' 3 pairs in 15 nights SNR=0' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=3, tWindow=15, snrLimit=0, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# Play with weird strategies. 

# Single detection. 

md = metadata + ' Single detection' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=1, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=1, tWindow=5, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# Single pair of detections. 

md = metadata + ' Single pair' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.DiscoveryMetric(nObsPerNight=2, tMin=0, tMax=90. / 60. / 24., 

nNightsPerWindow=1, tWindow=5, **colkwargs) 

childMetrics = _setup_child_metrics(metric) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

childMetrics=childMetrics, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

_configure_child_bundles(bundle) 

bundleList.append(bundle) 

 

# High velocity discovery. 

displayDict['subgroup'] = 'High Velocity' 

 

# High velocity. 

md = metadata + ' High velocity pair' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.HighVelocityNightsMetric(psfFactor=2., nObsPerNight=2, **colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

plotDict=plotDict, plotFuncs=plotFuncs, 

summaryMetrics=summaryTimeMetrics, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

# "magic" detection - 6 in 60 days (at SNR=5). 

md = metadata + ' 6 detections in 60 nights' + detectionLosses 

plotDict = {'title': '%s: %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.MagicDiscoveryMetric(nObs=6, tWindow=60, **colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

stackerList=[magStacker], 

runName=runName, metadata=md, 

plotDict=plotDict, plotFuncs=plotFuncs, 

summaryMetrics=summaryHMetrics, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

# Set the runName for all bundles and return the bundleDict. 

for b in bundleList: 

b.setRunName(runName) 

return mb.makeBundlesDictFromList(bundleList), plotBundles 

 

def addMoCompletenessBundles(bdict, Hmark, outDir, resultsDb): 

""" 

Generate completeness bundles from all N_Chances and Time child metrics of the (discovery) bundles in 

bdict, and write completeness at Hmark to resultsDb, save bundle to disk. 

 

Parameters 

---------- 

bdict : dict of metricBundles 

Dict containing ~lsst.sims.maf.MoMetricBundles, 

including bundles we're expecting to contain completeness. 

Hmark : float 

Hmark value to add to completeness plotting dict. 

outDir : str 

Output directory to save completeness bundles to disk. 

resultsDb : ~lsst.sims.maf.db.ResultsDb 

Results database to save information about completeness bundle. 

 

Returns 

------- 

dict of metricBundles 

Now the resulting metricBundles also includes new nested dicts with keys "DifferentialCompleteness" 

and "CumulativeCompleteness", which contain bundles of completeness metrics at each year. 

""" 

# Add completeness bundles and write completeness at Hmark to resultsDb. 

completeness = {} 

group = 'Discovery' 

subgroup = 'Completeness @ H=%.1f' % (Hmark) 

 

def _compbundles(b, bundle, Hmark, resultsDb): 

comp = {} 

newkey = b + ' differential completeness' 

comp[newkey] = mb.makeCompletenessBundle(bundle, summaryName='DifferentialCompleteness', 

Hmark=Hmark, resultsDb=resultsDb) 

newkey = b + ' cumulative completeness' 

comp[newkey] = mb.makeCompletenessBundle(bundle, summaryName='CumulativeCompleteness', 

Hmark=Hmark, resultsDb=resultsDb) 

return comp 

 

# Generate the completeness bundles for the various discovery metrics. 

for b, bundle in bdict.items(): 

if isinstance(bundle.metric, metrics.DiscoveryMetric): 

childkeys = ['Time', 'N_Chances'] 

for k in bundle.childBundles: 

if k in childkeys: 

childbundle = bundle.childBundles[k] 

completeness.update(_compbundles(b, childbundle, Hmark, resultsDb)) 

if isinstance(bundle.metric, metrics.HighVelocityNightsMetric): 

completeness.update(_compbundles(b, bundle, Hmark, resultsDb)) 

if isinstance(bundle.metric, metrics.MagicDiscoveryMetric): 

completeness.update(_compbundles(b, bundle, Hmark, resultsDb)) 

 

# Write the completeness bundles to disk, so we can re-read them later. 

# (also set the display dict properties, for the resultsDb output). 

for b, bundle in completeness.items(): 

bundle.setDisplayDict({'group': group, 'subgroup': subgroup}) 

bundle.write(outDir=outDir, resultsDb=resultsDb) 

 

return completeness 

 

 

def characterizationBatch(slicer, colmap=None, runName='opsim', metadata='', 

albedo=None, Hmark=None, npReduce=np.mean, constraint=None, 

windows=None, bins=None): 

 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

plotBundles = [] 

 

# Set up a dictionary to pass to each metric for the column names. 

colkwargs = {'mjdCol': colmap['mjd'], 'seeingCol': colmap['seeingGeom'], 

'expTimeCol': colmap['exptime'], 'm5Col': colmap['fiveSigmaDepth'], 

'nightCol': colmap['night'], 'filterCol': colmap['filter']} 

 

basicPlotDict = {'albedo': albedo, 'Hmark': Hmark, 'npReduce': npReduce, 

'nxbins': 200, 'nybins': 200} 

plotFuncs = [plots.MetricVsH()] 

displayDict ={'group': 'Characterization'} 

 

if windows is None: 

windows = np.arange(1, 200, 15.) 

if bins is None: 

bins = np.arange(5, 95, 10.) 

 

# Number of observations. 

md = metadata 

plotDict = {'ylabel': 'Number of observations (#)', 

'title': '%s: Number of observations %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.NObsMetric(**colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

runName=runName, metadata=md, 

plotDict=plotDict, plotFuncs=plotFuncs, 

summaryMetrics=None, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

# Observational arc. 

md = metadata 

plotDict = {'ylabel': 'Observational Arc (days)', 

'title': '%s: Observational Arc Length %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.ObsArcMetric(**colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

runName=runName, metadata=md, 

plotDict=plotDict, plotFuncs=plotFuncs, 

summaryMetrics=None, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

# Activity detection. 

for w in windows: 

md = metadata + ' activity lasting %.0f days' % w 

plotDict = {'title': '%s: Chances of detecting %s' % (runName, md), 

'ylabel': 'Probability of detection per %.0f day window' % w} 

metricName = 'Chances of detecting activity lasting %.0f days' % w 

metric = metrics.ActivityOverTimeMetric(w, metricName=metricName, **colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

runName=runName, metadata=metadata, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

for b in bins: 

md = metadata + ' activity lasting %.2f of period' % (b/360.) 

plotDict = {'title': '%s: Chances of detecting %s' % (runName, md), 

'ylabel': 'Probability of detection per %.2f deg window' % b} 

metricName = 'Chances of detecting activity lasting %.2f of the period' % (b/360.) 

metric = metrics.ActivityOverPeriodMetric(b, metricName=metricName, **colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

runName=runName, metadata=metadata, 

plotDict=plotDict, plotFuncs=plotFuncs, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

# Lightcurve inversion. 

md = metadata 

plotDict = {'yMin': 0, 'yMax': 1, 'ylabel': 'Fraction of objects', 

'title': '%s: Fraction with potential lightcurve inversion %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.LightcurveInversionMetric(snrLimit=20, nObs=100, nDays=5*365, **colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

runName=runName, metadata=md, 

plotDict=plotDict, plotFuncs=plotFuncs, 

summaryMetrics=None, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

# Color determination. 

snrLimit = 10 

nHours = 2.0 

nPairs = 1 

md = metadata + ' u-g color' 

plotDict = {'label': md, 

'title': '%s: Fraction with potential u-g color measurement %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.ColorDeterminationMetric(nPairs=nPairs, snrLimit=snrLimit, nHours=nHours, 

bOne='u', bTwo='g', **colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

runName=runName, metadata=md, 

plotDict=plotDict, plotFuncs=plotFuncs, 

summaryMetrics=None, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

md = metadata + ' g-r color' 

plotDict = {'label': md, 

'title': '%s: Fraction with potential g-r color measurement %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.ColorDeterminationMetric(nPairs=nPairs, snrLimit=snrLimit, nHours=nHours, 

bOne='g', bTwo='r', **colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

runName=runName, metadata=md, 

plotDict=plotDict, plotFuncs=plotFuncs, 

summaryMetrics=None, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

md = metadata + ' r-i color' 

plotDict = {'label': md, 

'title': '%s: Fraction with potential r-i color measurement %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.ColorDeterminationMetric(nPairs=nPairs, snrLimit=snrLimit, nHours=nHours, 

bOne='r', bTwo='i', **colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

runName=runName, metadata=md, 

plotDict=plotDict, plotFuncs=plotFuncs, 

summaryMetrics=None, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

md = metadata + ' i-z color' 

plotDict = {'label': md, 

'title': '%s: Fraction with potential i-z color measurement %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.ColorDeterminationMetric(nPairs=nPairs, snrLimit=snrLimit, nHours=nHours, 

bOne='i', bTwo='z', **colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

runName=runName, metadata=md, 

plotDict=plotDict, plotFuncs=plotFuncs, 

summaryMetrics=None, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

md = metadata + ' z-y color' 

plotDict = {'label': md, 

'title': '%s: Fraction with potential z-y color measurement %s' % (runName, md)} 

plotDict.update(basicPlotDict) 

metric = metrics.ColorDeterminationMetric(nPairs=nPairs, snrLimit=snrLimit, nHours=nHours, 

bOne='z', bTwo='y', **colkwargs) 

bundle = mb.MoMetricBundle(metric, slicer, constraint, 

runName=runName, metadata=md, 

plotDict=plotDict, plotFuncs=plotFuncs, 

summaryMetrics=None, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

# Set the runName for all bundles and return the bundleDict. 

for b in bundleList: 

b.setRunName(runName) 

return mb.makeBundlesDictFromList(bundleList), plotBundles