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

"""Run the hourglass metric. 

""" 

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

 

def hourglassPlots(colmap=None, runName='opsim', nyears=10, extraSql=None, extraMetadata=None): 

"""Run the hourglass metric, for each individual year. 

 

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

nyears : int (10), opt 

How many years to attempt to make hourglass plots for. Default is 10. 

extraSql : str, opt 

Add an extra sql constraint before running metrics. Default None. 

extraMetadata : str, opt 

Add an extra piece of metadata before running metrics. Default None. 

""" 

if colmap is None: 

colmap = ColMapDict('opsimV4') 

bundleList = [] 

 

sql = '' 

metadata = '' 

# 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 

 

years = list(range(nyears + 1)) 

displayDict = {'group': 'Hourglass'} 

for year in years[1:]: 

displayDict['subgroup'] = 'Year %d' % year 

displayDict['caption'] = 'Visualization of the filter usage of the telescope. ' \ 

'The black wavy line indicates lunar phase; the red and blue ' \ 

'solid lines indicate nautical and civil twilight.' 

sqlconstraint = 'night > %i and night <= %i' % (365.25 * (year - 1), 365.25 * year) 

if len(sql) > 0: 

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

md = metadata + ' year %i-%i' % (year - 1, year) 

slicer = slicers.HourglassSlicer() 

metric = metrics.HourglassMetric(nightCol=colmap['night'], mjdCol=colmap['mjd'], 

metricName='Hourglass') 

bundle = mb.MetricBundle(metric, slicer, constraint=sqlconstraint, metadata=md, 

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)