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

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 standardSummary 

 

__all__ = ['filtersPerNight','filtersWholeSurvey'] 

 

 

def setupMetrics(colmap, wholesurvey=False): 

metricList = [] 

captionList = [] 

# Number of filter changes (per slice - either whole survey or X nights) 

if wholesurvey: 

metricList.append(metrics.NChangesMetric(col=colmap['filter'], orderBy=colmap['mjd'], 

metricName='Total Filter Changes')) 

else: 

metricList.append(metrics.NChangesMetric(col=colmap['filter'], orderBy=colmap['mjd'], 

metricName='Filter Changes')) 

captionList.append('Total filter changes ') 

# Minimum time between filter changes 

metricList.append(metrics.MinTimeBetweenStatesMetric(changeCol=colmap['filter'], timeCol=colmap['mjd'])) 

captionList.append('Minimum time between filter changes ') 

# Number of filter changes faster than 10 minutes 

metricList.append(metrics.NStateChangesFasterThanMetric(changeCol=colmap['filter'], timeCol=colmap['mjd'], 

cutoff=10)) 

captionList.append('Number of filter changes faster than 10 minutes ') 

# Number of filter changes faster than 20 minutes 

metricList.append(metrics.NStateChangesFasterThanMetric(changeCol=colmap['filter'], timeCol=colmap['mjd'], 

cutoff=20)) 

captionList.append('Number of filter changes faster than 20 minutes ') 

# Maximum number of filter changes faster than 10 minutes within slice 

metricList.append(metrics.MaxStateChangesWithinMetric(changeCol=colmap['filter'], timeCol=colmap['mjd'], 

timespan=10)) 

captionList.append('Max number of filter changes within a window of 10 minutes ') 

# Maximum number of filter changes faster than 20 minutes within slice 

metricList.append(metrics.MaxStateChangesWithinMetric(changeCol=colmap['filter'], timeCol=colmap['mjd'], 

timespan=20)) 

captionList.append('Max number of filter changes within a window of 20 minutes ') 

return metricList, captionList 

 

 

def filtersPerNight(colmap=None, runName='opsim', nights=1, extraSql=None, extraMetadata=None): 

"""Generate a set of metrics measuring the number and rate of filter changes over a given span of nights. 

 

Parameters 

---------- 

colmap : dict, opt 

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

run_name : str, opt 

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

nights : int, opt 

Size of night bin to use when calculating metrics. Default is 1. 

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. 

 

Returns 

------- 

metricBundleDict 

""" 

 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

# Set up sql and metadata, if passed any additional information. 

sql = '' 

metadata = 'Per' 

if nights == 1: 

metadata += ' Night' 

else: 

metadata += ' %s Nights' % nights 

metacaption = metadata.lower() 

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

sql = extraSql 

if extraMetadata is None: 

metadata += ' %s' % extraSql 

metacaption += ', with %s selection' % extraSql 

if extraMetadata is not None: 

metadata += ' %s' % extraMetadata 

metacaption += ', %s only' % extraMetadata 

metacaption += '.' 

 

 

displayDict = {'group': 'Filter Changes', 'subgroup': metadata} 

summaryStats = standardSummary() 

 

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

metricList, captionList = setupMetrics(colmap) 

for m, caption in zip(metricList, captionList): 

displayDict['caption'] = caption + metacaption 

bundle = mb.MetricBundle(m, slicer, sql, runName=runName, metadata=metadata, 

displayDict=displayDict, 

summaryMetrics=summaryStats) 

bundleList.append(bundle) 

 

for b in bundleList: 

b.setRunName(runName) 

return mb.makeBundlesDictFromList(bundleList) 

 

 

def filtersWholeSurvey(colmap=None, runName='opsim', extraSql=None, extraMetadata=None): 

"""Generate a set of metrics measuring the number and rate of filter changes over the entire survey. 

 

Parameters 

---------- 

colmap : dict, opt 

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

run_name : str, opt 

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

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. 

 

Returns 

------- 

metricBundleDict 

""" 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

# Set up sql and metadata, if passed any additional information. 

sql = '' 

metadata = 'Whole Survey' 

metacaption = 'over the whole survey' 

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

sql = extraSql 

if extraMetadata is None: 

metadata += ' %s' % extraSql 

metacaption += ', with %s selction' % extraSql 

if extraMetadata is not None: 

metadata += ' %s' % extraMetadata 

metacaption += ', %s only' % (extraMetadata) 

metacaption += '.' 

 

 

displayDict = {'group': 'Filter Changes', 'subgroup': metadata} 

 

slicer = slicers.UniSlicer() 

metricList, captionList = setupMetrics(colmap) 

for m, caption in zip(metricList, captionList): 

displayDict['caption'] = caption + metacaption 

bundle = mb.MetricBundle(m, slicer, sql, runName=runName, metadata=metadata, 

displayDict=displayDict) 

bundleList.append(bundle) 

 

for b in bundleList: 

b.setRunName(runName) 

return mb.makeBundlesDictFromList(bundleList)