Coverage for python/lsst/sims/maf/batches/srdBatch.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 the SRD metrics.
2"""
3import healpy as hp
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, radecCols, combineMetadata
12__all__ = ['fOBatch', 'astrometryBatch', 'rapidRevisitBatch']
15def fOBatch(colmap=None, runName='opsim', extraSql=None, extraMetadata=None, nside=64,
16 benchmarkArea=18000, benchmarkNvisits=825, ditherStacker=None, ditherkwargs=None):
17 """Metrics for calculating fO.
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.
36 Returns
37 -------
38 metricBundleDict
39 """
40 if colmap is None:
41 colmap = ColMapDict('opsimV4')
43 bundleList = []
45 sql = ''
46 metadata = 'All visits'
47 # Add additional sql constraint (such as wfdWhere) and metadata, if provided.
48 if (extraSql is not None) and (len(extraSql) > 0):
49 sql = extraSql
50 if extraMetadata is None:
51 metadata = extraSql.replace('filter =', '').replace('filter=', '')
52 metadata = metadata.replace('"', '').replace("'", '')
53 if extraMetadata is not None:
54 metadata = extraMetadata
56 subgroup = metadata
58 raCol, decCol, degrees, ditherStacker, ditherMeta = radecCols(ditherStacker, colmap, ditherkwargs)
59 # Don't want dither info in subgroup (too long), but do want it in bundle name.
60 metadata = combineMetadata(metadata, ditherMeta)
62 # Set up fO metric.
63 slicer = slicers.HealpixSlicer(nside=nside, lonCol=raCol, latCol=decCol, latLonDeg=degrees)
65 displayDict = {'group': 'FO metrics', 'subgroup': subgroup, 'order': 0}
67 # Configure the count metric which is what is used for f0 slicer.
68 metric = metrics.CountMetric(col=colmap['mjd'], metricName='fO')
69 plotDict = {'xlabel': 'Number of Visits', 'Asky': benchmarkArea,
70 'Nvisit': benchmarkNvisits, 'xMin': 0, 'xMax': 1500}
71 summaryMetrics = [metrics.fOArea(nside=nside, norm=False, metricName='fOArea',
72 Asky=benchmarkArea, Nvisit=benchmarkNvisits),
73 metrics.fOArea(nside=nside, norm=True, metricName='fOArea/benchmark',
74 Asky=benchmarkArea, Nvisit=benchmarkNvisits),
75 metrics.fONv(nside=nside, norm=False, metricName='fONv',
76 Asky=benchmarkArea, Nvisit=benchmarkNvisits),
77 metrics.fONv(nside=nside, norm=True, metricName='fONv/benchmark',
78 Asky=benchmarkArea, Nvisit=benchmarkNvisits)]
79 caption = 'The FO metric evaluates the overall efficiency of observing. '
80 caption += ('foNv: out of %.2f sq degrees, the area receives at least X and a median of Y visits '
81 '(out of %d, if compared to benchmark). ' % (benchmarkArea, benchmarkNvisits))
82 caption += ('fOArea: this many sq deg (out of %.2f sq deg if compared '
83 'to benchmark) receives at least %d visits. ' % (benchmarkArea, benchmarkNvisits))
84 displayDict['caption'] = caption
85 bundle = mb.MetricBundle(metric, slicer, sql, plotDict=plotDict,
86 stackerList = [ditherStacker],
87 displayDict=displayDict, summaryMetrics=summaryMetrics,
88 plotFuncs=[plots.FOPlot()], metadata=metadata)
89 bundleList.append(bundle)
90 # Set the runName for all bundles and return the bundleDict.
91 for b in bundleList:
92 b.setRunName(runName)
93 return mb.makeBundlesDictFromList(bundleList)
96def astrometryBatch(colmap=None, runName='opsim',
97 extraSql=None, extraMetadata=None,
98 nside=64, ditherStacker=None, ditherkwargs=None):
99 """Metrics for evaluating proper motion and parallax.
101 Parameters
102 ----------
103 colmap : dict or None, opt
104 A dictionary with a mapping of column names. Default will use OpsimV4 column names.
105 runName : str, opt
106 The name of the simulated survey. Default is "opsim".
107 nside : int, opt
108 Nside for the healpix slicer. Default 64.
109 extraSql : str or None, opt
110 Additional sql constraint to apply to all metrics.
111 extraMetadata : str or None, opt
112 Additional metadata to apply to all results.
113 ditherStacker: str or lsst.sims.maf.stackers.BaseDitherStacker
114 Optional dither stacker to use to define ra/dec columns.
115 ditherkwargs: dict, opt
116 Optional dictionary of kwargs for the dither stacker.
118 Returns
119 -------
120 metricBundleDict
121 """
122 if colmap is None:
123 colmap = ColMapDict('opsimV4')
124 bundleList = []
126 sql = ''
127 metadata = 'All visits'
128 # Add additional sql constraint (such as wfdWhere) and metadata, if provided.
129 if (extraSql is not None) and (len(extraSql) > 0):
130 sql = extraSql
131 if extraMetadata is None:
132 metadata = extraSql.replace('filter =', '').replace('filter=', '')
133 metadata = metadata.replace('"', '').replace("'", '')
134 if extraMetadata is not None:
135 metadata = extraMetadata
137 subgroup = metadata
139 raCol, decCol, degrees, ditherStacker, ditherMeta = radecCols(ditherStacker, colmap, ditherkwargs)
140 # Don't want dither info in subgroup (too long), but do want it in bundle name.
141 metadata = combineMetadata(metadata, ditherMeta)
143 rmags_para = [22.4, 24.0]
144 rmags_pm = [20.5, 24.0]
146 # Set up parallax/dcr stackers.
147 parallaxStacker = stackers.ParallaxFactorStacker(raCol=raCol, decCol=decCol,
148 dateCol=colmap['mjd'], degrees=degrees)
149 dcrStacker = stackers.DcrStacker(filterCol=colmap['filter'], altCol=colmap['alt'], degrees=degrees,
150 raCol=raCol, decCol=decCol, lstCol=colmap['lst'],
151 site='LSST', mjdCol=colmap['mjd'])
153 # Set up parallax metrics.
154 slicer = slicers.HealpixSlicer(nside=nside, lonCol=raCol, latCol=decCol, latLonDeg=degrees)
155 subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()]
157 displayDict = {'group': 'Parallax', 'subgroup': subgroup,
158 'order': 0, 'caption': None}
159 # Expected error on parallax at 10 AU.
160 plotmaxVals = (2.0, 15.0)
161 for rmag, plotmax in zip(rmags_para, plotmaxVals):
162 plotDict = {'xMin': 0, 'xMax': plotmax, 'colorMin': 0, 'colorMax': plotmax}
163 metric = metrics.ParallaxMetric(metricName='Parallax Error @ %.1f' % (rmag), rmag=rmag,
164 seeingCol=colmap['seeingGeom'], filterCol=colmap['filter'],
165 m5Col=colmap['fiveSigmaDepth'], normalize=False)
166 bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata,
167 stackerList=[parallaxStacker, ditherStacker],
168 displayDict=displayDict, plotDict=plotDict,
169 summaryMetrics=standardSummary(),
170 plotFuncs=subsetPlots)
171 bundleList.append(bundle)
172 displayDict['order'] += 1
174 # Parallax normalized to 'best possible' if all visits separated by 6 months.
175 # This separates the effect of cadence from depth.
176 for rmag in rmags_para:
177 metric = metrics.ParallaxMetric(metricName='Normalized Parallax @ %.1f' % (rmag), rmag=rmag,
178 seeingCol=colmap['seeingGeom'], filterCol=colmap['filter'],
179 m5Col=colmap['fiveSigmaDepth'], normalize=True)
180 bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata,
181 stackerList=[parallaxStacker, ditherStacker],
182 displayDict=displayDict,
183 summaryMetrics=standardSummary(),
184 plotFuncs=subsetPlots)
185 bundleList.append(bundle)
186 displayDict['order'] += 1
187 # Parallax factor coverage.
188 for rmag in rmags_para:
189 metric = metrics.ParallaxCoverageMetric(metricName='Parallax Coverage @ %.1f' % (rmag),
190 rmag=rmag, m5Col=colmap['fiveSigmaDepth'],
191 mjdCol=colmap['mjd'], filterCol=colmap['filter'],
192 seeingCol=colmap['seeingGeom'])
193 bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata,
194 stackerList=[parallaxStacker, ditherStacker],
195 displayDict=displayDict, summaryMetrics=standardSummary(),
196 plotFuncs=subsetPlots)
197 bundleList.append(bundle)
198 displayDict['order'] += 1
199 # Parallax problems can be caused by HA and DCR degeneracies. Check their correlation.
200 for rmag in rmags_para:
201 metric = metrics.ParallaxDcrDegenMetric(metricName='Parallax-DCR degeneracy @ %.1f' % (rmag),
202 rmag=rmag, seeingCol=colmap['seeingEff'],
203 filterCol=colmap['filter'], m5Col=colmap['fiveSigmaDepth'])
204 caption = 'Correlation between parallax offset magnitude and hour angle for a r=%.1f star.' % (rmag)
205 caption += ' (0 is good, near -1 or 1 is bad).'
206 bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata,
207 stackerList=[dcrStacker, parallaxStacker, ditherStacker],
208 displayDict=displayDict, summaryMetrics=standardSummary(),
209 plotFuncs=subsetPlots)
210 bundleList.append(bundle)
211 displayDict['order'] += 1
213 # Proper Motion metrics.
214 displayDict = {'group': 'Proper Motion', 'subgroup': subgroup, 'order': 0, 'caption': None}
215 # Proper motion errors.
216 plotmaxVals = (1.0, 5.0)
217 for rmag, plotmax in zip(rmags_pm, plotmaxVals):
218 plotDict = {'xMin': 0, 'xMax': plotmax, 'colorMin': 0, 'colorMax': plotmax}
219 metric = metrics.ProperMotionMetric(metricName='Proper Motion Error @ %.1f' % rmag,
220 rmag=rmag, m5Col=colmap['fiveSigmaDepth'],
221 mjdCol=colmap['mjd'], filterCol=colmap['filter'],
222 seeingCol=colmap['seeingGeom'], normalize=False)
223 bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata,
224 stackerList=[ditherStacker],
225 displayDict=displayDict, plotDict=plotDict,
226 summaryMetrics=standardSummary(),
227 plotFuncs=subsetPlots)
228 bundleList.append(bundle)
229 displayDict['order'] += 1
230 # Normalized proper motion.
231 for rmag in rmags_pm:
232 metric = metrics.ProperMotionMetric(metricName='Normalized Proper Motion @ %.1f' % rmag,
233 rmag=rmag, m5Col=colmap['fiveSigmaDepth'],
234 mjdCol=colmap['mjd'], filterCol=colmap['filter'],
235 seeingCol=colmap['seeingGeom'], normalize=True)
236 bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata,
237 stackerList=[ditherStacker],
238 displayDict=displayDict, summaryMetrics=standardSummary(),
239 plotFuncs=subsetPlots)
240 bundleList.append(bundle)
241 displayDict['order'] += 1
243 # Set the runName for all bundles and return the bundleDict.
244 for b in bundleList:
245 b.setRunName(runName)
246 return mb.makeBundlesDictFromList(bundleList)
249def rapidRevisitBatch(colmap=None, runName='opsim',
250 extraSql=None, extraMetadata=None, nside=64,
251 ditherStacker=None, ditherkwargs=None):
252 """Metrics for evaluating proper motion and parallax.
254 Parameters
255 ----------
256 colmap : dict or None, opt
257 A dictionary with a mapping of column names. Default will use OpsimV4 column names.
258 runName : str, opt
259 The name of the simulated survey. Default is "opsim".
260 nside : int, opt
261 Nside for the healpix slicer. Default 64.
262 extraSql : str or None, opt
263 Additional sql constraint to apply to all metrics.
264 extraMetadata : str or None, opt
265 Additional metadata to apply to all results.
266 ditherStacker: str or lsst.sims.maf.stackers.BaseDitherStacker
267 Optional dither stacker to use to define ra/dec columns.
268 ditherkwargs: dict, opt
269 Optional dictionary of kwargs for the dither stacker.
271 Returns
272 -------
273 metricBundleDict
274 """
275 if colmap is None:
276 colmap = ColMapDict('opsimV4')
277 bundleList = []
279 sql = ''
280 metadata = 'All visits'
281 # Add additional sql constraint (such as wfdWhere) and metadata, if provided.
282 if (extraSql is not None) and (len(extraSql) > 0):
283 sql = extraSql
284 if extraMetadata is None:
285 metadata = extraSql.replace('filter =', '').replace('filter=', '')
286 metadata = metadata.replace('"', '').replace("'", '')
287 if extraMetadata is not None:
288 metadata = extraMetadata
290 subgroup = metadata
292 raCol, decCol, degrees, ditherStacker, ditherMeta = radecCols(ditherStacker, colmap, ditherkwargs)
293 # Don't want dither info in subgroup (too long), but do want it in bundle name.
294 metadata = combineMetadata(metadata, ditherMeta)
296 slicer = slicers.HealpixSlicer(nside=nside, lonCol=raCol, latCol=decCol, latLonDeg=degrees)
297 subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()]
299 displayDict = {'group': 'Rapid Revisits', 'subgroup': subgroup,
300 'order': 0, 'caption': None}
302 """
303 # Calculate the uniformity (KS test) of the quick revisits.
304 dTmin = 40.0 # seconds
305 dTmax = 30.0 # minutes
306 minNvisit = 100
307 pixArea = float(hp.nside2pixarea(nside, degrees=True))
308 scale = pixArea * hp.nside2npix(nside)
309 m1 = metrics.RapidRevisitUniformityMetric(metricName='RapidRevisitUniformity', mjdCol=colmap['mjd'],
310 dTmin=dTmin / 60.0 / 60.0 / 24.0, dTmax=dTmax / 60.0 / 24.0,
311 minNvisits=minNvisit)
312 plotDict = {'xMin': 0, 'xMax': 1}
313 cutoff1 = 0.20
314 summaryStats = [metrics.FracBelowMetric(cutoff=cutoff1, scale=scale, metricName='Area (sq deg)')]
315 summaryStats.extend(standardSummary())
316 caption = 'Deviation from uniformity for short revisit timescales, between %s seconds and %s minutes, ' \
317 % (dTmin, dTmax)
318 caption += 'for pointings with at least %d visits in this time range. ' % (minNvisit)
319 caption += 'Summary statistic "Area" indicates the area on the sky which has a '
320 caption += 'deviation from uniformity of < %.2f.' % (cutoff1)
321 displayDict['caption'] = caption
322 bundle = mb.MetricBundle(m1, slicer, sql, plotDict=plotDict, plotFuncs=subsetPlots,
323 stackerList=[ditherStacker],
324 metadata=metadata, displayDict=displayDict, summaryMetrics=summaryStats)
325 bundleList.append(bundle)
326 displayDict['order'] += 1
328 # Calculate the actual number of quick revisits.
329 dTmax = dTmax # time in minutes
330 m2 = metrics.NRevisitsMetric(dT=dTmax, mjdCol=colmap['mjd'], normed=False, metricName='RapidRevisitN')
331 plotDict = {'xMin': 600, 'xMax': 1500, 'logScale': False}
332 cutoff2 = 800
333 summaryStats = [metrics.FracAboveMetric(cutoff=cutoff2, scale=scale, metricName='Area (sq deg)')]
334 summaryStats.extend(standardSummary())
335 caption = 'Number of consecutive visits with return times faster than %.1f minutes, ' % (dTmax)
336 caption += 'in any filter, all proposals. '
337 caption += 'Summary statistic "Area" indicates the area on the sky which has more than '
338 caption += '%d revisits within this time window.' % (cutoff2)
339 displayDict['caption'] = caption
340 bundle = mb.MetricBundle(m2, slicer, sql, plotDict=plotDict, plotFuncs=subsetPlots,
341 stackerList=[ditherStacker],
342 metadata=metadata, displayDict=displayDict, summaryMetrics=summaryStats)
343 bundleList.append(bundle)
344 displayDict['order'] += 1
345 """
347 # Calculate whether a healpix gets enough rapid revisits in the right windows.
348 dTmin = 40.0/60.0 # (minutes) 40s minumum for rapid revisit range
349 dTpairs = 20.0 # minutes (time when pairs should start kicking in)
350 dTmax = 30.0 # 30 minute maximum for rapid revisit range
351 nOne = 82 # Number of revisits between 40s-30m required
352 nTwo = 28 # Number of revisits between 40s - tPairs required.
353 pixArea = float(hp.nside2pixarea(nside, degrees=True))
354 scale = pixArea * hp.nside2npix(nside)
355 m1 = metrics.RapidRevisitMetric(metricName='RapidRevisits', mjdCol=colmap['mjd'],
356 dTmin=dTmin / 60.0 / 60.0 / 24.0, dTpairs = dTpairs / 60.0 / 24.0,
357 dTmax=dTmax / 60.0 / 24.0, minN1=nOne, minN2=nTwo)
358 plotDict = {'xMin': 0, 'xMax': 1, 'colorMin': 0, 'colorMax': 1, 'logScale': False}
359 cutoff1 = 0.9
360 summaryStats = [metrics.FracAboveMetric(cutoff=cutoff1, scale=scale, metricName='Area (sq deg)')]
361 summaryStats.extend(standardSummary())
362 caption = 'Area that receives at least %d visits between %.3f and %.1f minutes, ' \
363 % (nOne, dTmin, dTmax)
364 caption += 'with at least %d of those visits falling between %.3f and %.1f minutes. ' \
365 % (nTwo, dTmin, dTpairs)
366 caption += 'Summary statistic "Area" indicates the area on the sky which meets this requirement.'
367 displayDict['caption'] = caption
368 bundle = mb.MetricBundle(m1, slicer, sql, plotDict=plotDict, plotFuncs=subsetPlots,
369 stackerList=[ditherStacker],
370 metadata=metadata, displayDict=displayDict, summaryMetrics=summaryStats)
371 bundleList.append(bundle)
372 displayDict['order'] += 1
374 # Set the runName for all bundles and return the bundleDict.
375 for b in bundleList:
376 b.setRunName(runName)
377 return mb.makeBundlesDictFromList(bundleList)