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

"""Some basic physical quantity metrics. 

""" 

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, extendedMetrics, standardAngleMetrics, filterList 

 

__all__ = ['metadataBasics', 'metadataBasicsAngle', 'allMetadata', 'metadataMaps'] 

 

 

def metadataBasics(value, colmap=None, runName='opsim', 

valueName=None, groupName=None, extraSql=None, extraMetadata=None, nside=64): 

"""Calculate basic metrics on visit metadata 'value' (e.g. airmass, normalized airmass, seeing..). 

 

Calculates extended standard metrics (with unislicer) on the quantity (all visits and per filter), 

makes histogram of the value (all visits and per filter), 

 

TODO: handle stackers which need configuration (degrees, in particular) more automatically. 

Currently have a hack for HA & normairmass. 

 

Parameters 

---------- 

value : str 

The column name for the quantity to evaluate. (column name in the database or created by a stacker). 

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". 

valueName : str, opt 

The name of the value to be reported in the resultsDb and added to the metric. 

This is intended to help standardize metric comparison between sim versions. 

value = name as it is in the database (seeingFwhmGeom, etc). 

valueName = name to be recorded ('seeingGeom', etc.). Default is None, which will match 'value'. 

groupName : str, opt 

The group name for this quantity in the displayDict. Default is the same as 'valueName', capitalized. 

extraSql : str, opt 

Additional constraint to add to any sql constraints (e.g. 'propId=1' or 'fieldID=522'). 

Default None, for no additional constraints. 

extraMetadata : str, opt 

Additional metadata to add before any below (i.e. "WFD"). Default is None. 

nside : int, opt 

Nside value for healpix slicer. Default 64. 

If "None" is passed, the healpixslicer-based metrics will be skipped. 

 

Returns 

------- 

metricBundleDict 

""" 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

if valueName is None: 

valueName = value 

 

if groupName is None: 

groupName = valueName.capitalize() 

subgroup = extraMetadata 

else: 

groupName = groupName.capitalize() 

subgroup = valueName.capitalize() 

 

if subgroup is None: 

subgroup = 'All visits' 

 

displayDict = {'group': groupName, 'subgroup': subgroup} 

 

# Set up basic all and per filter sql constraints. 

filterlist, colors, orders, sqls, metadata = filterList(all=True, 

extraSql=extraSql, 

extraMetadata=extraMetadata) 

 

# Hack to make HA work, but really I need to account for any stackers/colmaps. 

if value == 'HA': 

stackerList = [stackers.HourAngleStacker(lstCol=colmap['lst'], raCol=colmap['ra'], 

degrees=colmap['raDecDeg'])] 

elif value == 'normairmass': 

stackerList = [stackers.NormAirmassStacker(degrees=colmap['raDecDeg'])] 

else: 

stackerList = None 

 

# Summarize values over all and per filter (min/mean/median/max/percentiles/outliers/rms). 

slicer = slicers.UniSlicer() 

for f in filterlist: 

for m in extendedMetrics(value, replace_colname=valueName): 

displayDict['caption'] = '%s for %s.' % (m.name, metadata[f]) 

displayDict['order'] = orders[f] 

bundle = mb.MetricBundle(m, slicer, sqls[f], stackerList=stackerList, 

metadata=metadata[f], displayDict=displayDict) 

bundleList.append(bundle) 

 

# Histogram values over all and per filter. 

for f in filterlist: 

displayDict['caption'] = 'Histogram of %s' % (value) 

if valueName != value: 

displayDict['caption'] += ' (%s)' % (valueName) 

displayDict['caption'] += ' for %s.' % (metadata[f]) 

displayDict['order'] = orders[f] 

m = metrics.CountMetric(value, metricName='%s Histogram' % (valueName)) 

slicer = slicers.OneDSlicer(sliceColName=value) 

bundle = mb.MetricBundle(m, slicer, sqls[f], stackerList=stackerList, 

metadata=metadata[f], displayDict=displayDict) 

bundleList.append(bundle) 

 

# Make maps of min/median/max for all and per filter, per RA/Dec, with standard summary stats. 

mList = [] 

mList.append(metrics.MinMetric(value, metricName='Min %s' % (valueName))) 

mList.append(metrics.MedianMetric(value, metricName='Median %s' % (valueName))) 

mList.append(metrics.MaxMetric(value, metricName='Max %s' % (valueName))) 

slicer = slicers.HealpixSlicer(nside=nside, latCol=colmap['dec'], lonCol=colmap['ra'], 

latLonDeg=colmap['raDecDeg']) 

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

for f in filterlist: 

for m in mList: 

displayDict['caption'] = 'Map of %s' % m.name 

if valueName != value: 

displayDict['caption'] += ' (%s)' % value 

displayDict['caption'] += ' for %s.' % metadata[f] 

displayDict['order'] = orders[f] 

bundle = mb.MetricBundle(m, slicer, sqls[f], stackerList=stackerList, 

metadata=metadata[f], plotFuncs=subsetPlots, 

displayDict=displayDict, 

summaryMetrics=standardSummary()) 

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 metadataBasicsAngle(value, colmap=None, runName='opsim', 

valueName=None, groupName=None, extraSql=None, extraMetadata=None, nside=64): 

"""Calculate basic metrics on visit metadata 'value', where value is a wrap-around angle. 

 

Calculates extended standard metrics (with unislicer) on the quantity (all visits and per filter), 

makes histogram of the value (all visits and per filter), 

 

TODO: handle stackers which need configuration (degrees, in particular) more automatically. 

Currently have a hack for HA & normairmass. 

 

Parameters 

---------- 

value : str 

The column name for the quantity to evaluate. (column name in the database or created by a stacker). 

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". 

valueName : str, opt 

The name of the value to be reported in the resultsDb and added to the metric. 

This is intended to help standardize metric comparison between sim versions. 

value = name as it is in the database (seeingFwhmGeom, etc). 

valueName = name to be recorded ('seeingGeom', etc.). Default is None, which will match 'value'. 

groupName : str, opt 

The group name for this quantity in the displayDict. Default is the same as 'valueName', capitalized. 

extraSql : str, opt 

Additional constraint to add to any sql constraints (e.g. 'propId=1' or 'fieldID=522'). 

Default None, for no additional constraints. 

extraMetadata : str, opt 

Additional metadata to add before any below (i.e. "WFD"). Default is None. 

nside : int, opt 

Nside value for healpix slicer. Default 64. 

If "None" is passed, the healpixslicer-based metrics will be skipped. 

 

Returns 

------- 

metricBundleDict 

""" 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

if valueName is None: 

valueName = value 

 

if groupName is None: 

groupName = valueName.capitalize() 

subgroup = extraMetadata 

else: 

groupName = groupName.capitalize() 

subgroup = valueName.capitalize() 

 

if subgroup is None: 

subgroup = 'All visits' 

 

displayDict = {'group': groupName, 'subgroup': subgroup} 

 

# Set up basic all and per filter sql constraints. 

filterlist, colors, orders, sqls, metadata = filterList(all=True, 

extraSql=extraSql, 

extraMetadata=extraMetadata) 

 

 

# Summarize values over all and per filter. 

slicer = slicers.UniSlicer() 

for f in filterlist: 

for m in standardAngleMetrics(value, replace_colname=valueName): 

displayDict['caption'] = '%s for %s.' % (m.name, metadata[f]) 

displayDict['order'] = orders[f] 

bundle = mb.MetricBundle(m, slicer, sqls[f], stackerList=stackerList, 

metadata=metadata[f], displayDict=displayDict) 

bundleList.append(bundle) 

 

# Histogram values over all and per filter. 

for f in filterlist: 

displayDict['caption'] = 'Histogram of %s' % (value) 

if valueName != value: 

displayDict['caption'] += ' (%s)' % (valueName) 

displayDict['caption'] += ' for %s.' % (metadata[f]) 

displayDict['order'] = orders[f] 

m = metrics.CountMetric(value, metricName='%s Histogram' % (valueName)) 

slicer = slicers.OneDSlicer(sliceColName=value) 

bundle = mb.MetricBundle(m, slicer, sqls[f], stackerList=stackerList, 

metadata=metadata[f], displayDict=displayDict) 

bundleList.append(bundle) 

 

# Make maps of min/median/max for all and per filter, per RA/Dec, with standard summary stats. 

mList = [] 

mList.append(metrics.MeanAngleMetric(value, metricName='AngleMean %s' % (valueName))) 

mList.append(metrics.FullRangeAngleMetric(value, metricName='AngleRange %s' % (valueName))) 

mList.append(metrics.RmsAngleMetric(value, metricName='AngleRms %s' % (valueName))) 

slicer = slicers.HealpixSlicer(nside=nside, latCol=colmap['dec'], lonCol=colmap['ra'], 

latLonDeg=colmap['raDecDeg']) 

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

for f in filterlist: 

for m in mList: 

displayDict['caption'] = 'Map of %s' % m.name 

if valueName != value: 

displayDict['caption'] += ' (%s)' % value 

displayDict['caption'] += ' for %s.' % metadata[f] 

displayDict['order'] = orders[f] 

bundle = mb.MetricBundle(m, slicer, sqls[f], stackerList=stackerList, 

metadata=metadata[f], plotFuncs=subsetPlots, 

displayDict=displayDict, 

summaryMetrics=standardSummary()) 

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 allMetadata(colmap=None, runName='opsim', extraSql=None, extraMetadata=None): 

"""Generate a large set of metrics about the metadata of each visit - 

distributions of airmass, normalized airmass, seeing, sky brightness, single visit depth, 

hour angle, distance to the moon, and solar elongation. 

The exact metadata which is analyzed is set by the colmap['metadataList'] value. 

 

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". 

extraSql : str, opt 

Sql constraint (such as WFD only). Default is None. 

extraMetadata : str, opt 

Metadata to identify the sql constraint (such as WFD). Default is None. 

 

Returns 

------- 

metricBundleDict 

""" 

 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

 

bdict = {} 

 

for valueName in colmap['metadataList']: 

if valueName in colmap: 

value = colmap[valueName] 

else: 

value = valueName 

bdict.update(metadataBasics(value, colmap=colmap, runName=runName, 

valueName=valueName, 

extraSql=extraSql, extraMetadata=extraMetadata)) 

return bdict 

 

 

def metadataMaps(value, colmap=None, runName='opsim', 

valueName=None, groupName=None, extraSql=None, extraMetadata=None, nside=64): 

"""Calculate 25/50/75 percentile values on maps across sky for a single metadata value. 

 

TODO: handle stackers which need configuration (degrees, in particular) more automatically. 

Currently have a hack for HA & normairmass. 

 

Parameters 

---------- 

value : str 

The column name for the quantity to evaluate. (column name in the database or created by a stacker). 

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". 

valueName : str, opt 

The name of the value to be reported in the resultsDb and added to the metric. 

This is intended to help standardize metric comparison between sim versions. 

value = name as it is in the database (seeingFwhmGeom, etc). 

valueName = name to be recorded ('seeingGeom', etc.). Default is None, which will match 'value'. 

groupName : str, opt 

The group name for this quantity in the displayDict. Default is the same as 'valueName', capitalized. 

extraSql : str, opt 

Additional constraint to add to any sql constraints (e.g. 'propId=1' or 'fieldID=522'). 

Default None, for no additional constraints. 

extraMetadata : str, opt 

Additional metadata to add before any below (i.e. "WFD"). Default is None. 

nside : int, opt 

Nside value for healpix slicer. Default 64. 

If "None" is passed, the healpixslicer-based metrics will be skipped. 

 

Returns 

------- 

metricBundleDict 

""" 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

if valueName is None: 

valueName = value 

 

if groupName is None: 

groupName = valueName.capitalize() 

subgroup = extraMetadata 

else: 

groupName = groupName.capitalize() 

subgroup = valueName.capitalize() 

 

if subgroup is None: 

subgroup = 'All visits' 

 

displayDict = {'group': groupName, 'subgroup': subgroup} 

 

# Set up basic all and per filter sql constraints. 

filterlist, colors, orders, sqls, metadata = filterList(all=True, 

extraSql=extraSql, 

extraMetadata=extraMetadata) 

 

# Hack to make HA work, but really I need to account for any stackers/colmaps. 

if value == 'HA': 

stackerList = [stackers.HourAngleStacker(lstCol=colmap['lst'], raCol=colmap['ra'], 

degrees=colmap['raDecDeg'])] 

elif value == 'normairmass': 

stackerList = [stackers.NormAirmassStacker(degrees=colmap['raDecDeg'])] 

else: 

stackerList = None 

 

# Make maps of 25/median/75 for all and per filter, per RA/Dec, with standard summary stats. 

mList = [] 

mList.append(metrics.PercentileMetric(value, percentile=25, 

metricName='25thPercentile %s' % (valueName))) 

mList.append(metrics.MedianMetric(value, metricName='Median %s' % (valueName))) 

mList.append(metrics.PercentileMetric(value, percentile=75, 

metricName='75thPercentile %s' % (valueName))) 

slicer = slicers.HealpixSlicer(nside=nside, latCol=colmap['dec'], lonCol=colmap['ra'], 

latLonDeg=colmap['raDecDeg']) 

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

for f in filterlist: 

for m in mList: 

displayDict['caption'] = 'Map of %s' % m.name 

if valueName != value: 

displayDict['caption'] += ' (%s)' % value 

displayDict['caption'] += ' for %s.' % metadata[f] 

displayDict['order'] = orders[f] 

bundle = mb.MetricBundle(m, slicer, sqls[f], stackerList=stackerList, 

metadata=metadata[f], plotFuncs=subsetPlots, 

displayDict=displayDict, 

summaryMetrics=standardSummary()) 

bundleList.append(bundle) 

 

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

for b in bundleList: 

b.setRunName(runName) 

plotBundles = [] 

return mb.makeBundlesDictFromList(bundleList), plotBundles