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

"""Sets of metrics to look at time between visits/pairs, etc. 

""" 

import numpy as np 

import lsst.sims.maf.metrics as metrics 

import lsst.sims.maf.slicers as slicers 

import lsst.sims.maf.plots as plots 

import lsst.sims.maf.metricBundles as mb 

from .colMapDict import ColMapDict 

from .common import standardSummary, filterList 

 

__all__ = ['intraNight', 'interNight'] 

 

 

def intraNight(colmap=None, runName='opsim', nside=64, extraSql=None, extraMetadata=None): 

"""Generate a set of statistics about the pair/triplet/etc. rate within a night. 

 

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. 

 

Returns 

------- 

metricBundleDict 

""" 

 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

 

metadata = extraMetadata 

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

if metadata is None: 

metadata = extraSql 

 

bundleList = [] 

standardStats = standardSummary() 

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

 

# Look for the fraction of visits in gri where there are pairs within dtMin/dtMax. 

displayDict = {'group': 'IntraNight', 'subgroup': 'Pairs', 'caption': None, 'order': 0} 

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

sql = '(%s) and (filter="g" or filter="r" or filter="i")' % extraSql 

else: 

sql = 'filter="g" or filter="r" or filter="i"' 

md = 'gri' 

if metadata is not None: 

md += ' ' + metadata 

dtMin = 15.0 

dtMax = 60.0 

metric = metrics.PairFractionMetric(mjdCol=colmap['mjd'], minGap=dtMin, maxGap=dtMax, 

metricName='Fraction of visits in pairs (%.0f-%.0f min)' % (dtMin, 

dtMax)) 

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

latLonDeg=colmap['raDecDeg']) 

displayDict['caption'] = 'Fraction of %s visits that have a paired visit' \ 

'between %.1f and %.1f minutes away. ' % (md, dtMin, dtMax) 

displayDict['caption'] += 'If all visits were in pairs, this fraction would be 1.' 

displayDict['order'] += 1 

bundle = mb.MetricBundle(metric, slicer, sql, metadata=md, summaryMetrics=standardStats, 

plotFuncs=subsetPlots, displayDict=displayDict) 

bundleList.append(bundle) 

 

# Look at the fraction of visits which have another visit within dtMax, gri. 

dtMax = 50.0 

metric = metrics.NRevisitsMetric(mjdCol=colmap['mjd'], dT=dtMax, normed=True, 

metricName='Fraction of visits with a revisit < %.0f min' % dtMax) 

displayDict['caption'] = 'Fraction of %s visits that have another visit ' \ 

'within %.1f min. ' % (md, dtMax) 

displayDict['caption'] += 'If all visits were in pairs (only), this fraction would be 0.5.' 

displayDict['order'] += 1 

bundle = mb.MetricBundle(metric, slicer, sql, metadata=md, summaryMetrics=standardStats, 

plotFuncs=subsetPlots, displayDict=displayDict) 

bundleList.append(bundle) 

 

# Intranight gap map, all filters. Returns value in hours. 

metric = metrics.IntraNightGapsMetric(metricName='Median Intra-Night Gap', mjdCol=colmap['mjd'], 

reduceFunc=np.median) 

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

latLonDeg=colmap['raDecDeg']) 

displayDict['caption'] = 'Median gap between consecutive visits within a night, all bands' 

if metadata is None or len(metadata) == 0: 

displayDict['caption'] += ', all proposals.' 

else: 

displayDict['caption'] += ', %s.' % metadata 

displayDict['order'] += 1 

plotDict = {'percentileClip': 95} 

bundle = mb.MetricBundle(metric, slicer, extraSql, metadata=metadata, displayDict=displayDict, 

plotFuncs=subsetPlots, plotDict=plotDict, 

summaryMetrics=standardStats) 

bundleList.append(bundle) 

 

# Histogram the number of visits per night. 

countbins = np.arange(0, 10, 1) 

metric = metrics.NVisitsPerNightMetric(nightCol=colmap['night'], bins=countbins, 

metricName="NVisitsPerNight") 

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

latLonDeg=colmap['raDecDeg']) 

plotDict = {'bins': countbins, 'xlabel': 'Number of visits each night'} 

displayDict['caption'] = 'Histogram of the number of visits in each night, per point on the sky' 

if metadata is None or len(metadata) == 0: 

displayDict['caption'] += ', all proposals.' 

else: 

displayDict['caption'] += ', %s.' % metadata 

displayDict['order'] = 0 

plotFunc = plots.SummaryHistogram() 

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

displayDict=displayDict, metadata=metadata, plotFuncs=[plotFunc]) 

bundleList.append(bundle) 

 

# Histogram of the time between revisits (all filters) within two hours. 

binMin = 0 

binMax = 120. 

binsize = 5. 

bins_metric = np.arange(binMin / 60.0 / 24.0, (binMax + binsize) / 60. / 24., binsize / 60. / 24.) 

bins_plot = bins_metric * 24.0 * 60.0 

metric = metrics.TgapsMetric(bins=bins_metric, timesCol=colmap['mjd'], metricName='DeltaT Histogram') 

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

latLonDeg=colmap['raDecDeg']) 

plotDict = {'bins': bins_plot, 'xlabel': 'dT (minutes)'} 

displayDict['caption'] = 'Histogram of the time between consecutive visits to a given point ' \ 

'on the sky, considering visits between %.1f and %.1f minutes,' % (binMin, 

binMax) 

if metadata is None or len(metadata) == 0: 

displayDict['caption'] += ', all proposals.' 

else: 

displayDict['caption'] += ', %s.' % metadata 

displayDict['order'] += 1 

plotFunc = plots.SummaryHistogram() 

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

displayDict=displayDict, metadata=metadata, plotFuncs=[plotFunc]) 

bundleList.append(bundle) 

 

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

for b in bundleList: 

b.setRunName(runName) 

plotBundles = None 

return mb.makeBundlesDictFromList(bundleList), plotBundles 

 

 

def interNight(colmap=None, runName='opsim', nside=64, extraSql=None, extraMetadata=None): 

"""Generate a set of statistics about the spacing between nights with observations. 

 

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 use for all outputs. 

 

Returns 

------- 

metricBundleDict 

""" 

 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

 

bundleList = [] 

 

# Set up basic all and per filter sql constraints. 

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

extraSql=extraSql, 

extraMetadata=extraMetadata) 

 

displayDict = {'group': 'InterNight', 'subgroup': 'Night gaps', 'caption': None, 'order': 0} 

# Histogram of the number of nights between visits. 

bins = np.arange(1, 20.5, 1) 

metric = metrics.NightgapsMetric(bins=bins, nightCol=colmap['night'], metricName='DeltaNight Histogram') 

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

latLonDeg=colmap['raDecDeg']) 

plotDict = {'bins': bins, 'xlabel': 'dT (nights)'} 

displayDict['caption'] = 'Histogram of the number of nights between consecutive visits to a ' \ 

'given point on the sky, considering separations between %d and %d,' \ 

% (bins.min(), bins.max()) 

if metadata['all'] is None or len(metadata['all']) == 0: 

displayDict['caption'] += ', all proposals.' 

else: 

displayDict['caption'] += ', %s.' % metadata['all'] 

plotFunc = plots.SummaryHistogram() 

bundle = mb.MetricBundle(metric, slicer, sqls['all'], plotDict=plotDict, 

displayDict=displayDict, metadata=metadata['all'], plotFuncs=[plotFunc]) 

bundleList.append(bundle) 

 

standardStats = standardSummary() 

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

 

# Median inter-night gap (each and all filters) 

metric = metrics.InterNightGapsMetric(metricName='Median Inter-Night Gap', mjdCol=colmap['mjd'], 

reduceFunc=np.median) 

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

latLonDeg=colmap['raDecDeg']) 

for f in filterlist: 

displayDict['caption'] = 'Median gap between nights with observations, %s.' % metadata[f] 

displayDict['order'] = orders[f] 

plotDict = {'color': colors[f]} 

bundle = mb.MetricBundle(metric, slicer, sqls[f], metadata=metadata[f], 

displayDict=displayDict, 

plotFuncs=subsetPlots, plotDict=plotDict, 

summaryMetrics=standardStats) 

bundleList.append(bundle) 

 

# Maximum inter-night gap (in each and all filters). 

metric = metrics.InterNightGapsMetric(metricName='Max Inter-Night Gap', mjdCol=colmap['mjd'], 

reduceFunc=np.max) 

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

latLonDeg=colmap['raDecDeg']) 

for f in filterlist: 

displayDict['caption'] = 'Maximum gap between nights with observations, %s.' % metadata[f] 

displayDict['order'] = orders[f] 

plotDict = {'color': colors[f], 'percentileClip': 95., 'binsize': 5} 

bundle = mb.MetricBundle(metric, slicer, sqls[f], metadata=metadata[f], displayDict=displayDict, 

plotFuncs=subsetPlots, plotDict=plotDict, summaryMetrics=standardStats) 

bundleList.append(bundle) 

 

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

for b in bundleList: 

b.setRunName(runName) 

plotBundles = None 

return mb.makeBundlesDictFromList(bundleList), plotBundles