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

"""Sets of slew metrics. 

""" 

import warnings 

import lsst.sims.maf.metrics as metrics 

import lsst.sims.maf.slicers as slicers 

import lsst.sims.maf.metricBundles as mb 

from .colMapDict import ColMapDict 

from .common import standardMetrics 

 

__all__ = ['slewBasics', 'slewAngles', 'slewSpeeds', 'slewActivities'] 

 

 

def slewBasics(colmap=None, runName='opsim', sqlConstraint=None): 

"""Generate a simple set of statistics about the slew times and distances. 

These slew statistics can be run on the summary or default tables. 

 

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

sqlConstraint : str or None, opt 

SQL constraint to add to metrics. (note this runs on summary table). 

 

Returns 

------- 

metricBundleDict 

""" 

 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

 

bundleList = [] 

 

# Calculate basic stats on slew times. (mean/median/min/max + total). 

slicer = slicers.UniSlicer() 

 

metadata = 'All visits' 

displayDict = {'group': 'Slew', 'subgroup': 'Slew Basics', 'order': -1, 'caption': None} 

# Add total number of slews. 

metric = metrics.CountMetric(colmap['slewtime'], metricName='Slew Count') 

displayDict['caption'] = 'Total number of slews recorded in summary table.' 

displayDict['order'] += 1 

bundle = mb.MetricBundle(metric, slicer, sqlConstraint, metadata=metadata, displayDict=displayDict) 

bundleList.append(bundle) 

for metric in standardMetrics(colmap['slewtime']): 

displayDict['caption'] = '%s in seconds.' % (metric.name) 

displayDict['order'] += 1 

bundle = mb.MetricBundle(metric, slicer, sqlConstraint, metadata=metadata, displayDict=displayDict) 

bundleList.append(bundle) 

 

# Slew Time histogram. 

slicer = slicers.OneDSlicer(sliceColName=colmap['slewtime'], binsize=2) 

metric = metrics.CountMetric(col=colmap['slewtime'], metricName='Slew Time Histogram') 

metadata = 'All visits' 

plotDict = {'logScale': True, 'ylabel': 'Count'} 

displayDict['caption'] = 'Histogram of slew times (seconds) for all visits.' 

displayDict['order'] += 1 

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

plotDict=plotDict, displayDict=displayDict) 

bundleList.append(bundle) 

# Zoom in on slew time histogram near 0. 

slicer = slicers.OneDSlicer(sliceColName=colmap['slewtime'], binsize=0.2, binMin=0, binMax=20) 

metric = metrics.CountMetric(col=colmap['slewtime'], metricName='Zoom Slew Time Histogram') 

metadata = 'All visits' 

plotDict = {'logScale': True, 'ylabel': 'Count'} 

displayDict['caption'] = 'Histogram of slew times (seconds) for all visits (zoom).' 

displayDict['order'] += 1 

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

plotDict=plotDict, displayDict=displayDict) 

bundleList.append(bundle) 

 

# Slew distance histogram, if available. 

if colmap['slewdist'] is not None: 

binsize = 2.0 

if not colmap['raDecDeg']: 

binsize = np.radians(binsize) 

slicer = slicers.OneDSlicer(sliceColName=colmap['slewdist'], binsize=binsize) 

metric = metrics.CountMetric(col=colmap['slewdist'], metricName='Slew Distance Histogram') 

plotDict = {'logScale': True, 'ylabel': 'Count'} 

displayDict['caption'] = 'Histogram of slew distances (angle) for all visits.' 

displayDict['order'] += 1 

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

plotDict=plotDict, displayDict=displayDict) 

bundleList.append(bundle) 

# Zoom on slew distance histogram. 

binMax = 20.0 

if not colmap['raDecDeg']: 

binMax = np.radians(binMax) 

slicer = slicers.OneDSlicer(sliceColName=colmap['slewdist'], binsize=binsize/10., 

binMin=0, binMax=binMax) 

metric = metrics.CountMetric(col=colmap['slewdist'], metricName='Zoom Slew Distance Histogram') 

plotDict = {'logScale': True, 'ylabel': 'Count'} 

displayDict['caption'] = 'Histogram of slew distances (angle) for all visits.' 

displayDict['order'] += 1 

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

plotDict=plotDict, 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) 

 

 

def slewAngles(colmap=None, runName='opsim', sqlConstraint=None): 

"""Generate a set of slew statistics focused on the angles of each component (dome and telescope). 

These slew statistics must be run on the SlewFinalState or SlewInitialState table in opsimv4, 

and on the SlewState table in opsimv3. 

 

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

sqlConstraint : str or None, opt 

SQL constraint to apply to metrics. Note this runs on Slew*State table, so constraints 

should generally be based on slew_slewCount. 

 

Returns 

------- 

metricBundleDict 

""" 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

# All of these metrics are run with a unislicer. 

slicer = slicers.UniSlicer() 

 

# For each angle, we will compute mean/median/min/max and rms. 

# Note that these angles can range over more than 360 degrees, because of cable wrap. 

# This is why we're not using the Angle metrics - here 380 degrees is NOT the same as 20 deg. 

# Stats for angle: 

angles = ['Tel Alt', 'Tel Az', 'Rot Tel Pos'] 

 

displayDict = {'group': 'Slew', 'subgroup': 'Slew Angles', 'order': -1, 'caption': None} 

for angle in angles: 

metadata = angle 

metriclist = standardMetrics(colmap[angle], replace_colname='') 

metriclist += [metrics.RmsMetric(colmap[angle], metricName='RMS')] 

for metric in metriclist: 

displayDict['caption'] = '%s %s' % (metric.name, angle) 

displayDict['order'] += 1 

bundle = mb.MetricBundle(metric, slicer, sqlConstraint, 

displayDict=displayDict, metadata=metadata) 

bundleList.append(bundle) 

 

for b in bundleList: 

b.setRunName(runName) 

return mb.makeBundlesDictFromList(bundleList) 

 

 

def slewSpeeds(colmap=None, runName='opsim', sqlConstraint=None): 

"""Generate a set of slew statistics focused on the speeds of each component (dome and telescope). 

These slew statistics must be run on the SlewMaxSpeeds table in opsimv4 and opsimv3. 

 

Parameters 

---------- 

colmap : dict or None, opt 

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

Note that for these metrics, the column names are distinctly different in v3/v4. 

runName : str, opt 

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

sqlConstraint : str or None, opt 

SQL constraint to apply to metrics. Note this runs on Slew*State table, so constraints 

should generally be based on slew_slewCount. 

 

Returns 

------- 

metricBundleDict 

""" 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

# All of these metrics run with a unislicer, on all the slew data. 

slicer = slicers.UniSlicer() 

 

speeds = ['Dome Alt Speed', 'Dome Az Speed', 'Tel Alt Speed', 'Tel Az Speed', 'Rotator Speed'] 

 

displayDict = {'group': 'Slew', 'subgroup': 'Slew Speeds', 'order': -1, 'caption': None} 

for speed in speeds: 

metadata = speed 

metric = metrics.AbsMaxMetric(col=colmap[speed], metricName='Max (Abs)') 

displayDict['caption'] = 'Maximum absolute value of %s.' % speed 

displayDict['order'] += 1 

bundle = mb.MetricBundle(metric, slicer, sqlConstraint, displayDict=displayDict, metadata=metadata) 

bundleList.append(bundle) 

 

metric = metrics.AbsMeanMetric(col=colmap[speed], metricName='Mean (Abs)') 

displayDict['caption'] = 'Mean absolute value of %s.' % speed 

displayDict['order'] += 1 

bundle = mb.MetricBundle(metric, slicer, sqlConstraint, displayDict=displayDict, metadata=metadata) 

bundleList.append(bundle) 

 

metric = metrics.AbsMaxPercentMetric(col=colmap[speed], metricName='% @ Max') 

displayDict['caption'] = 'Percent of slews at the maximum %s (absolute value).' % speed 

displayDict['order'] += 1 

bundle = mb.MetricBundle(metric, slicer, sqlConstraint, displayDict=displayDict, metadata=metadata) 

bundleList.append(bundle) 

 

for b in bundleList: 

b.setRunName(runName) 

 

return mb.makeBundlesDictFromList(bundleList) 

 

 

def slewActivities(colmap=None, runName='opsim', totalSlewN=1, sqlConstraint=None): 

"""Generate a set of slew statistics focused on finding the contributions to the overall slew time. 

These slew statistics must be run on the SlewActivities table in opsimv4 and opsimv3. 

 

Note that the type of activities listed are different between v3 and v4. 

 

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

totalSlewN : int, opt 

The total number of slews in the simulated survey. 

Used to calculate % of slew activities for each component. 

Default is 1. 

sqlConstraint : str or None, opt 

SQL constraint to apply to metrics. Note this runs on Slew*State table, so constraints 

should generally be based on slew_slewCount. 

 

 

Returns 

------- 

metricBundleDict 

""" 

if totalSlewN == 1: 

warnings.warn('TotalSlewN should be set (using 1). Percents from activities may be incorrect.') 

 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

# All of these metrics run with a unislicer, on all the slew data. 

slicer = slicers.UniSlicer() 

 

if 'slewactivities' not in colmap: 

raise ValueError("List of slewactivities not in colmap! Will not create slewActivities bundles.") 

 

slewTypeDict = colmap['slewactivities'] 

 

displayDict = {'group': 'Slew', 'subgroup': 'Slew Activities', 'order': -1, 'caption': None} 

 

for slewType in slewTypeDict: 

metadata = slewType 

if sqlConstraint is not None: 

metadata += sqlConstraint 

tableValue = slewTypeDict[slewType] 

 

# Metrics for all activities of this type. 

sql = 'activityDelay>0 and activity="%s"' % tableValue 

if sqlConstraint is not None: 

sql = '(%s) and (%s)' % (sql, sqlConstraint) 

 

# Percent of slews which include this activity. 

metric = metrics.CountRatioMetric(col='activityDelay', normVal=totalSlewN / 100.0, 

metricName='ActivePerc') 

displayDict['caption'] = 'Percent of total slews which include %s movement.' % slewType 

displayDict['order'] += 1 

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

bundleList.append(bundle) 

 

# Mean time for this activity, in all slews. 

metric = metrics.MeanMetric(col='activityDelay', metricName='Ave T(s)') 

displayDict['caption'] = 'Mean amount of time (in seconds) for %s movements.' % (slewType) 

displayDict['order'] += 1 

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

bundleList.append(bundle) 

 

# Maximum time for this activity, in all slews. 

metric = metrics.MaxMetric(col='activityDelay', metricName='Max T(s)') 

displayDict['caption'] = 'Max amount of time (in seconds) for %s movement.' % (slewType) 

displayDict['order'] += 1 

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

bundleList.append(bundle) 

 

# Metrics for activities of this type which are in the critical path. 

sql = 'activityDelay>0 and inCriticalPath="True" and activity="%s"' % tableValue 

if sqlConstraint is not None: 

sql = '(%s) and (%s)' % (sql, sqlConstraint) 

 

# Percent of slews which include this activity in the critical path. 

metric = metrics.CountRatioMetric(col='activityDelay', normVal=totalSlewN / 100.0, 

metricName='ActivePerc in crit') 

displayDict['caption'] = 'Percent of total slew which include %s movement, ' \ 

'and are in critical path.' % (slewType) 

displayDict['order'] += 1 

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

bundleList.append(bundle) 

 

# Mean time for slews which include this activity, in the critical path. 

metric = metrics.MeanMetric(col='activityDelay', metricName='Ave T(s) in crit') 

displayDict['caption'] = 'Mean time (in seconds) for %s movements, ' \ 

'when in critical path.' % (slewType) 

displayDict['order'] += 1 

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

bundleList.append(bundle) 

 

# Total time that this activity was in the critical path. 

metric = metrics.SumMetric(col='activityDelay', metricName='Total T(s) in crit') 

displayDict['caption'] = 'Total time (in seconds) for %s movements, ' \ 

'when in critical path.' % (slewType) 

displayDict['order'] += 1 

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

bundleList.append(bundle) 

 

for b in bundleList: 

b.setRunName(runName) 

return mb.makeBundlesDictFromList(bundleList)