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

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

 

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

 

 

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

benchmarkArea=18000, benchmarkNvisits=825, 

raCol=None, decCol=None, degrees=None, stackerList=None): 

 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

 

if raCol is None: 

raCol = colmap['ra'] 

if decCol is None: 

decCol = colmap['dec'] 

if degrees is None: 

degrees = colmap['raDecDeg'] 

 

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 

 

# 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: Nvisits (#)', 

Asky=benchmarkArea, Nvisit=benchmarkNvisits), 

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

Asky=benchmarkArea, Nvisit=benchmarkNvisits), 

metrics.fONv(nside=nside, norm=False, metricName='fONv: Area (sqdeg)', 

Asky=benchmarkArea, Nvisit=benchmarkNvisits), 

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

Asky=benchmarkArea, Nvisit=benchmarkNvisits)] 

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

caption += ('fOArea: Nvisits = %.1f sq degrees receive at least this many visits out of %d. ' 

% (benchmarkArea, benchmarkNvisits)) 

caption += ('fONv: Area = this many square degrees out of %.1f receive at least %d visits.' 

% (benchmarkArea, benchmarkNvisits)) 

displayDict['caption'] = caption 

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

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): 

# Allow user to add dithering. 

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 = colmap['ra'] 

decCol = colmap['dec'] 

degrees = colmap['raDecDeg'] 

 

rmags_para = [22.4, 24.0] 

rmags_pm = [20.5, 24.0] 

 

# Set up 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], 

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], 

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], 

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], 

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, 

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, 

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): 

# Allow user to add dithering. 

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 = colmap['ra'] 

decCol = colmap['dec'] 

degrees = colmap['raDecDeg'] 

 

# 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.RapidRevisitMetric(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 and %s seconds, ' % ( 

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, 

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) 

plotDict = {'xMin': 0.1, 'xMax': 2000, 'logScale': True} 

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, 

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)