Coverage for python/lsst/sims/maf/batches/hourglassBatch.py : 12%

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"""Run the hourglass metric.
2"""
3import lsst.sims.maf.metrics as metrics
4import lsst.sims.maf.slicers as slicers
5import lsst.sims.maf.metricBundles as mb
6from .colMapDict import ColMapDict
8__all__ = ['hourglassPlots']
11def hourglassPlots(colmap=None, runName='opsim', nyears=10, extraSql=None, extraMetadata=None):
12 """Run the hourglass metric, for each individual year.
14 Parameters
15 ----------
16 colmap : dict, opt
17 A dictionary with a mapping of column names. Default will use OpsimV4 column names.
18 run_name : str, opt
19 The name of the simulated survey. Default is "opsim".
20 nyears : int (10), opt
21 How many years to attempt to make hourglass plots for. Default is 10.
22 extraSql : str, opt
23 Add an extra sql constraint before running metrics. Default None.
24 extraMetadata : str, opt
25 Add an extra piece of metadata before running metrics. Default None.
26 """
27 if colmap is None:
28 colmap = ColMapDict('opsimV4')
29 bundleList = []
31 sql = ''
32 metadata = ''
33 # Add additional sql constraint (such as wfdWhere) and metadata, if provided.
34 if (extraSql is not None) and (len(extraSql) > 0):
35 sql = extraSql
36 if extraMetadata is None:
37 metadata = extraSql.replace('filter =', '').replace('filter=', '')
38 metadata = metadata.replace('"', '').replace("'", '')
39 if extraMetadata is not None:
40 metadata = extraMetadata
42 years = list(range(nyears + 1))
43 displayDict = {'group': 'Hourglass'}
44 for year in years[1:]:
45 displayDict['subgroup'] = 'Year %d' % year
46 displayDict['caption'] = 'Visualization of the filter usage of the telescope. ' \
47 'The black wavy line indicates lunar phase; the red and blue ' \
48 'solid lines indicate nautical and civil twilight.'
49 sqlconstraint = 'night > %i and night <= %i' % (365.25 * (year - 1), 365.25 * year)
50 if len(sql) > 0:
51 sqlconstraint = '(%s) and (%s)' % (sqlconstraint, sql)
52 md = metadata + ' year %i-%i' % (year - 1, year)
53 slicer = slicers.HourglassSlicer()
54 metric = metrics.HourglassMetric(nightCol=colmap['night'], mjdCol=colmap['mjd'],
55 metricName='Hourglass')
56 bundle = mb.MetricBundle(metric, slicer, constraint=sqlconstraint, metadata=md,
57 displayDict=displayDict)
58 bundleList.append(bundle)
60 # Set the runName for all bundles and return the bundleDict.
61 for b in bundleList:
62 b.setRunName(runName)
63 return mb.makeBundlesDictFromList(bundleList)