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

"""Evaluate the open shutter fraction. 

""" 

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__ = ['openshutterFractions'] 

 

 

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

"""Evaluate open shutter fraction over whole survey and per night. 

 

Parameters 

---------- 

colmap : dict, 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 

Additional constraint to add to any sql constraints (e.g. 'night<365') 

Default None, for no additional constraints. 

extraMetadata : str, opt 

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

""" 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

group = 'Open Shutter Fraction' 

 

subgroup = 'All visits' 

if extraMetadata is not None: 

subgroup = extraMetadata + ' ' + subgroup.lower() 

elif extraSql is not None and extraMetadata is None: 

subgroup = subgroup + ' ' + extraSql 

 

# Open Shutter fraction over whole survey. 

displayDict = {'group': group, 'subgroup': subgroup, 'order': 0} 

displayDict['caption'] = 'Total open shutter fraction over %s. ' % subgroup.lower() 

displayDict['caption'] += 'Does not include downtime due to weather.' 

metric = metrics.OpenShutterFractionMetric(slewTimeCol=colmap['slewtime'], 

expTimeCol=colmap['exptime'], 

visitTimeCol=colmap['visittime']) 

slicer = slicers.UniSlicer() 

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

displayDict=displayDict) 

bundleList.append(bundle) 

# Count the number of nights on-sky in the survey. 

displayDict['caption'] = 'Number of nights on the sky during the survey, %s.' % subgroup.lower() 

metric = metrics.CountUniqueMetric(colmap['night']) 

slicer = slicers.UniSlicer() 

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

displayDict=displayDict) 

bundleList.append(bundle) 

# Count the number of nights total in the survey (start to finish of observations). 

displayDict['caption'] = 'Number of nights from start to finish of survey, %s.' % subgroup.lower() 

metric = metrics.FullRangeMetric(colmap['night']) 

slicer = slicers.UniSlicer() 

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

displayDict=displayDict) 

bundleList.append(bundle) 

 

# Open shutter fraction per night. 

subgroup = 'Per night' 

if extraMetadata is not None: 

subgroup = extraMetadata + ' ' + subgroup.lower() 

elif extraSql is not None and extraMetadata is None: 

subgroup = subgroup + ' ' + extraSql 

displayDict = {'group': group, 'subgroup': subgroup, 'order': 0} 

displayDict['caption'] = 'Open shutter fraction %s.' % (subgroup.lower()) 

displayDict['caption'] += ' This compares on-sky image time against on-sky time + slews + filter ' \ 

'changes + readout, but does not include downtime due to weather.' 

metric = metrics.OpenShutterFractionMetric(slewTimeCol=colmap['slewtime'], 

expTimeCol=colmap['exptime'], 

visitTimeCol=colmap['visittime']) 

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

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

summaryMetrics=standardSummary(), 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)