Coverage for python/lsst/sims/maf/batches/timeBatch.py : 6%

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"""Sets of metrics to look at time between visits/pairs, etc.
2"""
3import numpy as np
4import lsst.sims.maf.metrics as metrics
5import lsst.sims.maf.slicers as slicers
6import lsst.sims.maf.stackers as stackers
7import lsst.sims.maf.plots as plots
8import lsst.sims.maf.metricBundles as mb
9from .colMapDict import ColMapDict
10from .common import standardSummary, filterList, combineMetadata, radecCols
12__all__ = ['intraNight', 'interNight', 'seasons']
15def intraNight(colmap=None, runName='opsim', nside=64, extraSql=None, extraMetadata=None,
16 ditherStacker=None, ditherkwargs=None, slicer=None, display_group='IntraNight', subgroup='Pairs'):
17 """Generate a set of statistics about the pair/triplet/etc. rate within a night.
19 Parameters
20 ----------
21 colmap : dict or None, opt
22 A dictionary with a mapping of column names. Default will use OpsimV4 column names.
23 runName : str, opt
24 The name of the simulated survey. Default is "opsim".
25 nside : int, opt
26 Nside for the healpix slicer. Default 64.
27 extraSql : str or None, opt
28 Additional sql constraint to apply to all metrics.
29 extraMetadata : str or None, opt
30 Additional metadata to apply to all results.
31 ditherStacker: str or lsst.sims.maf.stackers.BaseDitherStacker
32 Optional dither stacker to use to define ra/dec columns.
33 ditherkwargs: dict, opt
34 Optional dictionary of kwargs for the dither stacker.
35 slicer : slicer object (None)
36 Optinally use something other than a HealpixSlicer
38 Returns
39 -------
40 metricBundleDict
41 """
43 if colmap is None:
44 colmap = ColMapDict('opsimV4')
46 metadata = extraMetadata
47 if extraSql is not None and len(extraSql) > 0:
48 if metadata is None:
49 metadata = extraSql
51 raCol, decCol, degrees, ditherStacker, ditherMeta = radecCols(ditherStacker, colmap, ditherkwargs)
52 metadata = combineMetadata(metadata, ditherMeta)
54 bundleList = []
55 standardStats = standardSummary()
56 subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()]
58 if slicer is None:
59 slicer = slicers.HealpixSlicer(nside=nside, latCol=decCol, lonCol=raCol, latLonDeg=degrees)
61 # Look for the fraction of visits in gri where there are pairs within dtMin/dtMax.
62 displayDict = {'group': display_group, 'subgroup': subgroup, 'caption': None, 'order': 0}
63 if extraSql is not None and len(extraSql) > 0:
64 sql = '(%s) and (filter="g" or filter="r" or filter="i")' % extraSql
65 else:
66 sql = 'filter="g" or filter="r" or filter="i"'
67 md = 'gri'
68 if metadata is not None:
69 md += ' ' + metadata
70 dtMin = 15.0
71 dtMax = 60.0
72 metric = metrics.PairFractionMetric(mjdCol=colmap['mjd'], minGap=dtMin, maxGap=dtMax,
73 metricName='Fraction of visits in pairs (%.0f-%.0f min)' % (dtMin,
74 dtMax))
75 displayDict['caption'] = 'Fraction of %s visits that have a paired visit' \
76 'between %.1f and %.1f minutes away. ' % (md, dtMin, dtMax)
77 displayDict['caption'] += 'If all visits were in pairs, this fraction would be 1.'
78 displayDict['order'] += 1
79 bundle = mb.MetricBundle(metric, slicer, sql, metadata=md, summaryMetrics=standardStats,
80 plotFuncs=subsetPlots, displayDict=displayDict)
81 bundleList.append(bundle)
83 # Look at the fraction of visits which have another visit within dtMax, gri.
84 dtMax = 50.0
85 metric = metrics.NRevisitsMetric(mjdCol=colmap['mjd'], dT=dtMax, normed=True,
86 metricName='Fraction of visits with a revisit < %.0f min' % dtMax)
87 displayDict['caption'] = 'Fraction of %s visits that have another visit ' \
88 'within %.1f min. ' % (md, dtMax)
89 displayDict['caption'] += 'If all visits were in pairs (only), this fraction would be 0.5.'
90 displayDict['order'] += 1
91 bundle = mb.MetricBundle(metric, slicer, sql, metadata=md, summaryMetrics=standardStats,
92 plotFuncs=subsetPlots, displayDict=displayDict)
93 bundleList.append(bundle)
95 # Intranight gap map, all filters. Returns value in hours.
96 metric = metrics.IntraNightGapsMetric(metricName='Median Intra-Night Gap', mjdCol=colmap['mjd'],
97 reduceFunc=np.median)
98 displayDict['caption'] = 'Median gap between consecutive visits within a night, all bands'
99 if metadata is None or len(metadata) == 0:
100 displayDict['caption'] += ', all proposals.'
101 else:
102 displayDict['caption'] += ', %s.' % metadata
103 displayDict['order'] += 1
104 plotDict = {'percentileClip': 95}
105 bundle = mb.MetricBundle(metric, slicer, extraSql, metadata=metadata, displayDict=displayDict,
106 plotFuncs=subsetPlots, plotDict=plotDict,
107 summaryMetrics=standardStats)
108 bundleList.append(bundle)
110 # Histogram the number of visits per night.
111 countbins = np.arange(0, 10, 1)
112 metric = metrics.NVisitsPerNightMetric(nightCol=colmap['night'], bins=countbins,
113 metricName="NVisitsPerNight")
114 plotDict = {'bins': countbins, 'xlabel': 'Number of visits each night'}
115 displayDict['caption'] = 'Histogram of the number of visits in each night, per point on the sky'
116 if metadata is None or len(metadata) == 0:
117 displayDict['caption'] += ', all proposals.'
118 else:
119 displayDict['caption'] += ', %s.' % metadata
120 displayDict['order'] = 0
121 plotFunc = plots.SummaryHistogram()
122 bundle = mb.MetricBundle(metric, slicer, extraSql, plotDict=plotDict,
123 displayDict=displayDict, metadata=metadata, plotFuncs=[plotFunc])
124 bundleList.append(bundle)
126 # Histogram of the time between revisits (all filters) within two hours.
127 binMin = 0
128 binMax = 120.
129 binsize = 5.
130 bins_metric = np.arange(binMin / 60.0 / 24.0, (binMax + binsize) / 60. / 24., binsize / 60. / 24.)
131 bins_plot = bins_metric * 24.0 * 60.0
132 metric = metrics.TgapsMetric(bins=bins_metric, timesCol=colmap['mjd'], metricName='DeltaT Histogram')
133 plotDict = {'bins': bins_plot, 'xlabel': 'dT (minutes)'}
134 displayDict['caption'] = 'Histogram of the time between consecutive visits to a given point ' \
135 'on the sky, considering visits between %.1f and %.1f minutes' % (binMin,
136 binMax)
137 if metadata is None or len(metadata) == 0:
138 displayDict['caption'] += ', all proposals.'
139 else:
140 displayDict['caption'] += ', %s.' % metadata
141 displayDict['order'] += 1
142 plotFunc = plots.SummaryHistogram()
143 bundle = mb.MetricBundle(metric, slicer, extraSql, plotDict=plotDict,
144 displayDict=displayDict, metadata=metadata, plotFuncs=[plotFunc])
145 bundleList.append(bundle)
147 # Set the runName for all bundles and return the bundleDict.
148 for b in bundleList:
149 b.setRunName(runName)
150 plotBundles = None
151 return mb.makeBundlesDictFromList(bundleList), plotBundles
154def interNight(colmap=None, runName='opsim', nside=64, extraSql=None, extraMetadata=None,
155 ditherStacker=None, ditherkwargs=None, slicer=None, display_group='InterNight', subgroup='Night gaps'):
156 """Generate a set of statistics about the spacing between nights with observations.
158 Parameters
159 ----------
160 colmap : dict or None, opt
161 A dictionary with a mapping of column names. Default will use OpsimV4 column names.
162 runName : str, opt
163 The name of the simulated survey. Default is "opsim".
164 nside : int, opt
165 Nside for the healpix slicer. Default 64.
166 extraSql : str or None, opt
167 Additional sql constraint to apply to all metrics.
168 extraMetadata : str or None, opt
169 Additional metadata to use for all outputs.
170 ditherStacker: str or lsst.sims.maf.stackers.BaseDitherStacker
171 Optional dither stacker to use to define ra/dec columns.
172 ditherkwargs: dict, opt
173 Optional dictionary of kwargs for the dither stacker.
174 slicer : slicer object (None)
175 Optinally use something other than a HealpixSlicer
177 Returns
178 -------
179 metricBundleDict
180 """
182 if colmap is None:
183 colmap = ColMapDict('opsimV4')
185 bundleList = []
187 # Set up basic all and per filter sql constraints.
188 raCol, decCol, degrees, ditherStacker, ditherMeta = radecCols(ditherStacker, colmap, ditherkwargs)
189 metadata = combineMetadata(extraMetadata, ditherMeta)
190 filterlist, colors, orders, sqls, metadata = filterList(all=True,
191 extraSql=extraSql,
192 extraMetadata=metadata)
194 if slicer is None:
195 slicer = slicers.HealpixSlicer(nside=nside, latCol=decCol, lonCol=raCol, latLonDeg=degrees)
197 displayDict = {'group': display_group, 'subgroup': subgroup, 'caption': None, 'order': 0}
199 # Histogram of the number of nights between visits.
200 bins = np.arange(1, 20.5, 1)
201 metric = metrics.NightgapsMetric(bins=bins, nightCol=colmap['night'], metricName='DeltaNight Histogram')
202 plotDict = {'bins': bins, 'xlabel': 'dT (nights)'}
203 displayDict['caption'] = 'Histogram of the number of nights between consecutive visits to a ' \
204 'given point on the sky, considering separations between %d and %d' \
205 % (bins.min(), bins.max())
206 if metadata['all'] is None or len(metadata['all']) == 0:
207 displayDict['caption'] += ', all proposals.'
208 else:
209 displayDict['caption'] += ', %s.' % metadata['all']
210 plotFunc = plots.SummaryHistogram()
211 bundle = mb.MetricBundle(metric, slicer, sqls['all'], plotDict=plotDict,
212 displayDict=displayDict, metadata=metadata['all'], plotFuncs=[plotFunc])
213 bundleList.append(bundle)
215 standardStats = standardSummary()
216 subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()]
218 # Median inter-night gap (each and all filters)
219 metric = metrics.InterNightGapsMetric(metricName='Median Inter-Night Gap', mjdCol=colmap['mjd'],
220 reduceFunc=np.median)
221 for f in filterlist:
222 displayDict['caption'] = 'Median gap between nights with observations, %s.' % metadata[f]
223 displayDict['order'] = orders[f]
224 plotDict = {'color': colors[f], 'percentileClip': 95.}
225 bundle = mb.MetricBundle(metric, slicer, sqls[f], metadata=metadata[f],
226 displayDict=displayDict,
227 plotFuncs=subsetPlots, plotDict=plotDict,
228 summaryMetrics=standardStats)
229 bundleList.append(bundle)
231 # Maximum inter-night gap (in each and all filters).
232 metric = metrics.InterNightGapsMetric(metricName='Max Inter-Night Gap', mjdCol=colmap['mjd'],
233 reduceFunc=np.max)
234 for f in filterlist:
235 displayDict['caption'] = 'Maximum gap between nights with observations, %s.' % metadata[f]
236 displayDict['order'] = orders[f]
237 plotDict = {'color': colors[f], 'percentileClip': 95., 'binsize': 5}
238 bundle = mb.MetricBundle(metric, slicer, sqls[f], metadata=metadata[f], displayDict=displayDict,
239 plotFuncs=subsetPlots, plotDict=plotDict, summaryMetrics=standardStats)
240 bundleList.append(bundle)
242 # Set the runName for all bundles and return the bundleDict.
243 for b in bundleList:
244 b.setRunName(runName)
245 plotBundles = None
246 return mb.makeBundlesDictFromList(bundleList), plotBundles
249def seasons(colmap=None, runName='opsim', nside=64, extraSql=None, extraMetadata=None,
250 ditherStacker=None, ditherkwargs=None):
251 """Generate a set of statistics about the length and number of seasons.
253 Parameters
254 ----------
255 colmap : dict or None, opt
256 A dictionary with a mapping of column names. Default will use OpsimV4 column names.
257 runName : str, opt
258 The name of the simulated survey. Default is "opsim".
259 nside : int, opt
260 Nside for the healpix slicer. Default 64.
261 extraSql : str or None, opt
262 Additional sql constraint to apply to all metrics.
263 extraMetadata : str or None, opt
264 Additional metadata to use for all outputs.
265 ditherStacker: str or lsst.sims.maf.stackers.BaseDitherStacker
266 Optional dither stacker to use to define ra/dec columns.
267 ditherkwargs: dict, opt
268 Optional dictionary of kwargs for the dither stacker.
269 Returns
270 -------
271 metricBundleDict
272 """
274 if colmap is None:
275 colmap = ColMapDict('opsimV4')
277 bundleList = []
279 # Set up basic all and per filter sql constraints.
280 raCol, decCol, degrees, ditherStacker, ditherMeta = radecCols(ditherStacker, colmap, ditherkwargs)
281 metadata = combineMetadata(extraMetadata, ditherMeta)
282 filterlist, colors, orders, sqls, metadata = filterList(all=True,
283 extraSql=extraSql,
284 extraMetadata=metadata)
286 seasonStacker = stackers.SeasonStacker(mjdCol=colmap['mjd'], RACol=raCol,
287 degrees=degrees)
288 stackerList = [seasonStacker]
289 if ditherStacker is not None:
290 stackerList.append(ditherStacker)
291 slicer = slicers.HealpixSlicer(nside=nside, latCol=decCol, lonCol=raCol, latLonDeg=degrees)
293 displayDict = {'group': 'IntraSeason', 'subgroup': 'Season length', 'caption': None, 'order': 0}
295 # Histogram of the length of seasons.
296 """
297 bins = np.arange(1, 20.5, 1)
298 metric = metrics.NightgapsMetric(bins=bins, nightCol=colmap['night'], metricName='DeltaNight Histogram')
299 plotDict = {'bins': bins, 'xlabel': 'dT (nights)'}
300 displayDict['caption'] = 'Histogram of the number of nights between consecutive visits to a ' \
301 'given point on the sky, considering separations between %d and %d' \
302 % (bins.min(), bins.max())
303 if metadata['all'] is None or len(metadata['all']) == 0:
304 displayDict['caption'] += ', all proposals.'
305 else:
306 displayDict['caption'] += ', %s.' % metadata['all']
307 plotFunc = plots.SummaryHistogram()
308 bundle = mb.MetricBundle(metric, slicer, sqls['all'], plotDict=plotDict,
309 displayDict=displayDict, metadata=metadata['all'], plotFuncs=[plotFunc])
310 bundleList.append(bundle)
311 """
313 standardStats = standardSummary()
314 subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()]
316 # Median inter-night gap (each and all filters)
317 metric = metrics.SeasonLengthMetric(metricName='Median Season Length', mjdCol=colmap['mjd'],
318 reduceFunc=np.median)
319 for f in filterlist:
320 displayDict['caption'] = 'Median season length, %s.' % metadata[f]
321 displayDict['order'] = orders[f]
322 maxS = 250
323 if f == 'all':
324 minS = 90
325 else:
326 minS = 30
327 plotDict = {'color': colors[f], 'colorMin': minS, 'colorMax': maxS, 'xMin': minS, 'xMax': maxS}
328 bundle = mb.MetricBundle(metric, slicer, sqls[f], metadata=metadata[f],
329 stackerList=stackerList, displayDict=displayDict,
330 plotFuncs=subsetPlots, plotDict=plotDict,
331 summaryMetrics=standardStats)
332 bundleList.append(bundle)
334 # Number of seasons?
336 # Set the runName for all bundles and return the bundleDict.
337 for b in bundleList:
338 b.setRunName(runName)
339 plotBundles = None
340 return mb.makeBundlesDictFromList(bundleList), plotBundles