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

"""Sets of metrics to look at the SRD metrics. 

""" 

import healpy as hp 

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 standardSummary, radecCols, combineMetadata 

 

__all__ = ['fOBatch', 'astrometryBatch', 'rapidRevisitBatch'] 

 

 

def fOBatch(colmap=None, runName='opsim', extraSql=None, extraMetadata=None, nside=64, 

benchmarkArea=18000, benchmarkNvisits=825, ditherStacker=None, ditherkwargs=None): 

"""Metrics for calculating fO. 

 

Parameters 

---------- 

colmap : dict or None, opt 

A dictionary with a mapping of column names. Default will use OpsimV4 column names. 

runName : str, opt 

The name of the simulated survey. Default is "opsim". 

nside : int, opt 

Nside for the healpix slicer. Default 64. 

extraSql : str or None, opt 

Additional sql constraint to apply to all metrics. 

extraMetadata : str or None, opt 

Additional metadata to apply to all results. 

ditherStacker: str or lsst.sims.maf.stackers.BaseDitherStacker 

Optional dither stacker to use to define ra/dec columns. 

ditherkwargs: dict, opt 

Optional dictionary of kwargs for the dither stacker. 

 

Returns 

------- 

metricBundleDict 

""" 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

 

bundleList = [] 

 

sql = '' 

metadata = 'All visits' 

# Add additional sql constraint (such as wfdWhere) and metadata, if provided. 

if (extraSql is not None) and (len(extraSql) > 0): 

sql = extraSql 

if extraMetadata is None: 

metadata = extraSql.replace('filter =', '').replace('filter=', '') 

metadata = metadata.replace('"', '').replace("'", '') 

if extraMetadata is not None: 

metadata = extraMetadata 

 

subgroup = metadata 

 

raCol, decCol, degrees, ditherStacker, ditherMeta = radecCols(ditherStacker, colmap, ditherkwargs) 

# Don't want dither info in subgroup (too long), but do want it in bundle name. 

metadata = combineMetadata(metadata, ditherMeta) 

 

# Set up fO metric. 

slicer = slicers.HealpixSlicer(nside=nside, lonCol=raCol, latCol=decCol, latLonDeg=degrees) 

 

displayDict = {'group': 'FO metrics', 'subgroup': subgroup, 'order': 0} 

 

# Configure the count metric which is what is used for f0 slicer. 

metric = metrics.CountMetric(col=colmap['mjd'], metricName='fO') 

plotDict = {'xlabel': 'Number of Visits', 'Asky': benchmarkArea, 

'Nvisit': benchmarkNvisits, 'xMin': 0, 'xMax': 1500} 

summaryMetrics = [metrics.fOArea(nside=nside, norm=False, metricName='fOArea', 

Asky=benchmarkArea, Nvisit=benchmarkNvisits), 

metrics.fOArea(nside=nside, norm=True, metricName='fOArea/benchmark', 

Asky=benchmarkArea, Nvisit=benchmarkNvisits), 

metrics.fONv(nside=nside, norm=False, metricName='fONv', 

Asky=benchmarkArea, Nvisit=benchmarkNvisits), 

metrics.fONv(nside=nside, norm=True, metricName='fONv/benchmark', 

Asky=benchmarkArea, Nvisit=benchmarkNvisits)] 

caption = 'The FO metric evaluates the overall efficiency of observing. ' 

caption += ('foNv: out of %.2f sq degrees, the area receives at least X and a median of Y visits ' 

'(out of %d, if compared to benchmark). ' % (benchmarkArea, benchmarkNvisits)) 

caption += ('fOArea: this many sq deg (out of %.2f sq deg if compared ' 

'to benchmark) receives at least %d visits. ' % (benchmarkArea, benchmarkNvisits)) 

displayDict['caption'] = caption 

bundle = mb.MetricBundle(metric, slicer, sql, plotDict=plotDict, 

stackerList = [ditherStacker], 

displayDict=displayDict, summaryMetrics=summaryMetrics, 

plotFuncs=[plots.FOPlot()], metadata=metadata) 

bundleList.append(bundle) 

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

for b in bundleList: 

b.setRunName(runName) 

return mb.makeBundlesDictFromList(bundleList) 

 

 

def astrometryBatch(colmap=None, runName='opsim', 

extraSql=None, extraMetadata=None, 

nside=64, ditherStacker=None, ditherkwargs=None): 

"""Metrics for evaluating proper motion and parallax. 

 

Parameters 

---------- 

colmap : dict or None, opt 

A dictionary with a mapping of column names. Default will use OpsimV4 column names. 

runName : str, opt 

The name of the simulated survey. Default is "opsim". 

nside : int, opt 

Nside for the healpix slicer. Default 64. 

extraSql : str or None, opt 

Additional sql constraint to apply to all metrics. 

extraMetadata : str or None, opt 

Additional metadata to apply to all results. 

ditherStacker: str or lsst.sims.maf.stackers.BaseDitherStacker 

Optional dither stacker to use to define ra/dec columns. 

ditherkwargs: dict, opt 

Optional dictionary of kwargs for the dither stacker. 

 

Returns 

------- 

metricBundleDict 

""" 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

sql = '' 

metadata = 'All visits' 

# Add additional sql constraint (such as wfdWhere) and metadata, if provided. 

if (extraSql is not None) and (len(extraSql) > 0): 

sql = extraSql 

if extraMetadata is None: 

metadata = extraSql.replace('filter =', '').replace('filter=', '') 

metadata = metadata.replace('"', '').replace("'", '') 

if extraMetadata is not None: 

metadata = extraMetadata 

 

subgroup = metadata 

 

raCol, decCol, degrees, ditherStacker, ditherMeta = radecCols(ditherStacker, colmap, ditherkwargs) 

# Don't want dither info in subgroup (too long), but do want it in bundle name. 

metadata = combineMetadata(metadata, ditherMeta) 

 

rmags_para = [22.4, 24.0] 

rmags_pm = [20.5, 24.0] 

 

# Set up parallax/dcr stackers. 

parallaxStacker = stackers.ParallaxFactorStacker(raCol=raCol, decCol=decCol, 

dateCol=colmap['mjd'], degrees=degrees) 

dcrStacker = stackers.DcrStacker(filterCol=colmap['filter'], altCol=colmap['alt'], degrees=degrees, 

raCol=raCol, decCol=decCol, lstCol=colmap['lst'], 

site='LSST', mjdCol=colmap['mjd']) 

 

# Set up parallax metrics. 

slicer = slicers.HealpixSlicer(nside=nside, lonCol=raCol, latCol=decCol, latLonDeg=degrees) 

subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()] 

 

displayDict = {'group': 'Parallax', 'subgroup': subgroup, 

'order': 0, 'caption': None} 

# Expected error on parallax at 10 AU. 

plotmaxVals = (2.0, 15.0) 

for rmag, plotmax in zip(rmags_para, plotmaxVals): 

plotDict = {'xMin': 0, 'xMax': plotmax, 'colorMin': 0, 'colorMax': plotmax} 

metric = metrics.ParallaxMetric(metricName='Parallax Error @ %.1f' % (rmag), rmag=rmag, 

seeingCol=colmap['seeingGeom'], filterCol=colmap['filter'], 

m5Col=colmap['fiveSigmaDepth'], normalize=False) 

bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata, 

stackerList=[parallaxStacker, ditherStacker], 

displayDict=displayDict, plotDict=plotDict, 

summaryMetrics=standardSummary(), 

plotFuncs=subsetPlots) 

bundleList.append(bundle) 

displayDict['order'] += 1 

 

# Parallax normalized to 'best possible' if all visits separated by 6 months. 

# This separates the effect of cadence from depth. 

for rmag in rmags_para: 

metric = metrics.ParallaxMetric(metricName='Normalized Parallax @ %.1f' % (rmag), rmag=rmag, 

seeingCol=colmap['seeingGeom'], filterCol=colmap['filter'], 

m5Col=colmap['fiveSigmaDepth'], normalize=True) 

bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata, 

stackerList=[parallaxStacker, ditherStacker], 

displayDict=displayDict, 

summaryMetrics=standardSummary(), 

plotFuncs=subsetPlots) 

bundleList.append(bundle) 

displayDict['order'] += 1 

# Parallax factor coverage. 

for rmag in rmags_para: 

metric = metrics.ParallaxCoverageMetric(metricName='Parallax Coverage @ %.1f' % (rmag), 

rmag=rmag, m5Col=colmap['fiveSigmaDepth'], 

mjdCol=colmap['mjd'], filterCol=colmap['filter'], 

seeingCol=colmap['seeingGeom']) 

bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata, 

stackerList=[parallaxStacker, ditherStacker], 

displayDict=displayDict, summaryMetrics=standardSummary(), 

plotFuncs=subsetPlots) 

bundleList.append(bundle) 

displayDict['order'] += 1 

# Parallax problems can be caused by HA and DCR degeneracies. Check their correlation. 

for rmag in rmags_para: 

metric = metrics.ParallaxDcrDegenMetric(metricName='Parallax-DCR degeneracy @ %.1f' % (rmag), 

rmag=rmag, seeingCol=colmap['seeingEff'], 

filterCol=colmap['filter'], m5Col=colmap['fiveSigmaDepth']) 

caption = 'Correlation between parallax offset magnitude and hour angle for a r=%.1f star.' % (rmag) 

caption += ' (0 is good, near -1 or 1 is bad).' 

bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata, 

stackerList=[dcrStacker, parallaxStacker, ditherStacker], 

displayDict=displayDict, summaryMetrics=standardSummary(), 

plotFuncs=subsetPlots) 

bundleList.append(bundle) 

displayDict['order'] += 1 

 

# Proper Motion metrics. 

displayDict = {'group': 'Proper Motion', 'subgroup': subgroup, 'order': 0, 'caption': None} 

# Proper motion errors. 

plotmaxVals = (1.0, 5.0) 

for rmag, plotmax in zip(rmags_pm, plotmaxVals): 

plotDict = {'xMin': 0, 'xMax': plotmax, 'colorMin': 0, 'colorMax': plotmax} 

metric = metrics.ProperMotionMetric(metricName='Proper Motion Error @ %.1f' % rmag, 

rmag=rmag, m5Col=colmap['fiveSigmaDepth'], 

mjdCol=colmap['mjd'], filterCol=colmap['filter'], 

seeingCol=colmap['seeingGeom'], normalize=False) 

bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata, 

stackerList=[ditherStacker], 

displayDict=displayDict, plotDict=plotDict, 

summaryMetrics=standardSummary(), 

plotFuncs=subsetPlots) 

bundleList.append(bundle) 

displayDict['order'] += 1 

# Normalized proper motion. 

for rmag in rmags_pm: 

metric = metrics.ProperMotionMetric(metricName='Normalized Proper Motion @ %.1f' % rmag, 

rmag=rmag, m5Col=colmap['fiveSigmaDepth'], 

mjdCol=colmap['mjd'], filterCol=colmap['filter'], 

seeingCol=colmap['seeingGeom'], normalize=True) 

bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata, 

stackerList=[ditherStacker], 

displayDict=displayDict, summaryMetrics=standardSummary(), 

plotFuncs=subsetPlots) 

bundleList.append(bundle) 

displayDict['order'] += 1 

 

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

for b in bundleList: 

b.setRunName(runName) 

return mb.makeBundlesDictFromList(bundleList) 

 

 

def rapidRevisitBatch(colmap=None, runName='opsim', 

extraSql=None, extraMetadata=None, nside=64, 

ditherStacker=None, ditherkwargs=None): 

"""Metrics for evaluating proper motion and parallax. 

 

Parameters 

---------- 

colmap : dict or None, opt 

A dictionary with a mapping of column names. Default will use OpsimV4 column names. 

runName : str, opt 

The name of the simulated survey. Default is "opsim". 

nside : int, opt 

Nside for the healpix slicer. Default 64. 

extraSql : str or None, opt 

Additional sql constraint to apply to all metrics. 

extraMetadata : str or None, opt 

Additional metadata to apply to all results. 

ditherStacker: str or lsst.sims.maf.stackers.BaseDitherStacker 

Optional dither stacker to use to define ra/dec columns. 

ditherkwargs: dict, opt 

Optional dictionary of kwargs for the dither stacker. 

 

Returns 

------- 

metricBundleDict 

""" 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

sql = '' 

metadata = 'All visits' 

# Add additional sql constraint (such as wfdWhere) and metadata, if provided. 

if (extraSql is not None) and (len(extraSql) > 0): 

sql = extraSql 

if extraMetadata is None: 

metadata = extraSql.replace('filter =', '').replace('filter=', '') 

metadata = metadata.replace('"', '').replace("'", '') 

if extraMetadata is not None: 

metadata = extraMetadata 

 

subgroup = metadata 

 

raCol, decCol, degrees, ditherStacker, ditherMeta = radecCols(ditherStacker, colmap, ditherkwargs) 

# Don't want dither info in subgroup (too long), but do want it in bundle name. 

metadata = combineMetadata(metadata, ditherMeta) 

 

# Set up parallax metrics. 

slicer = slicers.HealpixSlicer(nside=nside, lonCol=raCol, latCol=decCol, latLonDeg=degrees) 

subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()] 

 

displayDict = {'group': 'Rapid Revisits', 'subgroup': subgroup, 

'order': 0, 'caption': None} 

 

# Calculate the uniformity (KS test) of the quick revisits. 

dTmin = 40.0 # seconds 

dTmax = 30.0 # minutes 

minNvisit = 100 

pixArea = float(hp.nside2pixarea(nside, degrees=True)) 

scale = pixArea * hp.nside2npix(nside) 

m1 = metrics.RapidRevisitUniformityMetric(metricName='RapidRevisitUniformity', mjdCol=colmap['mjd'], 

dTmin=dTmin / 60.0 / 60.0 / 24.0, dTmax=dTmax / 60.0 / 24.0, 

minNvisits=minNvisit) 

plotDict = {'xMin': 0, 'xMax': 1} 

cutoff1 = 0.20 

summaryStats = [metrics.FracBelowMetric(cutoff=cutoff1, scale=scale, metricName='Area (sq deg)')] 

summaryStats.extend(standardSummary()) 

caption = 'Deviation from uniformity for short revisit timescales, between %s seconds and %s minutes, ' \ 

% (dTmin, dTmax) 

caption += 'for pointings with at least %d visits in this time range. ' % (minNvisit) 

caption += 'Summary statistic "Area" indicates the area on the sky which has a ' 

caption += 'deviation from uniformity of < %.2f.' % (cutoff1) 

displayDict['caption'] = caption 

bundle = mb.MetricBundle(m1, slicer, sql, plotDict=plotDict, plotFuncs=subsetPlots, 

stackerList=[ditherStacker], 

metadata=metadata, displayDict=displayDict, summaryMetrics=summaryStats) 

bundleList.append(bundle) 

displayDict['order'] += 1 

 

# Calculate the actual number of quick revisits. 

dTmax = dTmax # time in minutes 

m2 = metrics.NRevisitsMetric(dT=dTmax, mjdCol=colmap['mjd'], normed=False, metricName='RapidRevisitN') 

plotDict = {'xMin': 600, 'xMax': 1500, 'logScale': False} 

cutoff2 = 800 

summaryStats = [metrics.FracAboveMetric(cutoff=cutoff2, scale=scale, metricName='Area (sq deg)')] 

summaryStats.extend(standardSummary()) 

caption = 'Number of consecutive visits with return times faster than %.1f minutes, ' % (dTmax) 

caption += 'in any filter, all proposals. ' 

caption += 'Summary statistic "Area" indicates the area on the sky which has more than ' 

caption += '%d revisits within this time window.' % (cutoff2) 

displayDict['caption'] = caption 

bundle = mb.MetricBundle(m2, slicer, sql, plotDict=plotDict, plotFuncs=subsetPlots, 

stackerList=[ditherStacker], 

metadata=metadata, displayDict=displayDict, summaryMetrics=summaryStats) 

bundleList.append(bundle) 

displayDict['order'] += 1 

 

# Calculate whether a healpix gets enough rapid revisits in the right windows. 

dTmin = 40.0/60.0 # (minutes) 40s minumum for rapid revisit range 

dTpairs = 20.0 # minutes (time when pairs should start kicking in) 

dTmax = 30.0 # 30 minute maximum for rapid revisit range 

nOne = 82 # Number of revisits between 40s-30m required 

nTwo = 28 # Number of revisits between 40s - tPairs required. 

pixArea = float(hp.nside2pixarea(nside, degrees=True)) 

scale = pixArea * hp.nside2npix(nside) 

m1 = metrics.RapidRevisitMetric(metricName='RapidRevisits', mjdCol=colmap['mjd'], 

dTmin=dTmin / 60.0 / 60.0 / 24.0, dTpairs = dTpairs / 60.0 / 24.0, 

dTmax=dTmax / 60.0 / 24.0, minN1=nOne, minN2=nTwo) 

plotDict = {'xMin': 0, 'xMax': 1, 'colorMin': 0, 'colorMax': 1, 'logScale': False} 

cutoff1 = 0.9 

summaryStats = [metrics.FracAboveMetric(cutoff=cutoff1, scale=scale, metricName='Area (sq deg)')] 

summaryStats.extend(standardSummary()) 

caption = 'Area that receives at least %d visits between %.3f and %.1f minutes, ' \ 

% (nOne, dTmin, dTmax) 

caption += 'with at least %d of those visits falling between %.3f and %.1f minutes. ' \ 

% (nTwo, dTmin, dTpairs) 

caption += 'Summary statistic "Area" indicates the area on the sky which meets this requirement.' 

displayDict['caption'] = caption 

bundle = mb.MetricBundle(m1, slicer, sql, plotDict=plotDict, plotFuncs=subsetPlots, 

stackerList=[ditherStacker], 

metadata=metadata, displayDict=displayDict, summaryMetrics=summaryStats) 

bundleList.append(bundle) 

displayDict['order'] += 1 

 

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

for b in bundleList: 

b.setRunName(runName) 

return mb.makeBundlesDictFromList(bundleList)