Coverage for python/lsst/sims/maf/batches/scienceRadarBatch.py : 8%

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
1import healpy as hp
2import lsst.sims.maf.metrics as metrics
3import lsst.sims.maf.slicers as slicers
4import lsst.sims.maf.stackers as stackers
5import lsst.sims.maf.plots as plots
6import lsst.sims.maf.metricBundles as mb
7from lsst.sims.maf.batches import intraNight, interNight
8from .colMapDict import ColMapDict
9from .srdBatch import fOBatch, astrometryBatch, rapidRevisitBatch
10import numpy as np
11from lsst.sims.utils import hpid2RaDec, angularSeparation
13__all__ = ['scienceRadarBatch']
16def scienceRadarBatch(colmap=None, runName='', extraSql=None, extraMetadata=None, nside=64,
17 benchmarkArea=18000, benchmarkNvisits=825, DDF=True):
18 """A batch of metrics for looking at survey performance relative to the SRD and the main
19 science drivers of LSST.
21 Parameters
22 ----------
24 """
25 # Hide dependencies
26 from mafContrib.LSSObsStrategy.galaxyCountsMetric_extended import GalaxyCountsMetric_extended
27 from mafContrib import Plasticc_metric, plasticc_slicer, load_plasticc_lc
29 if colmap is None:
30 colmap = ColMapDict('opsimV4')
32 if extraSql is None:
33 extraSql = ''
34 if extraSql == '':
35 joiner = ''
36 else:
37 joiner = ' and '
39 bundleList = []
41 healslicer = slicers.HealpixSlicer(nside=nside)
42 subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()]
44 # Load up the plastic light curves
45 models = ['SNIa-normal', 'KN']
46 plasticc_models_dict = {}
47 for model in models:
48 plasticc_models_dict[model] = list(load_plasticc_lc(model=model).values())
50 #########################
51 # SRD, DM, etc
52 #########################
53 f0b = fOBatch(runName=runName, colmap=colmap, extraSql=extraSql, extraMetadata=extraMetadata,
54 benchmarkArea=benchmarkArea, benchmarkNvisits=benchmarkNvisits)
55 astromb = astrometryBatch(runName=runName, colmap=colmap, extraSql=extraSql, extraMetadata=extraMetadata)
56 rapidb = rapidRevisitBatch(runName=runName, colmap=colmap, extraSql=extraSql, extraMetadata=extraMetadata)
58 # loop through and modify the display dicts if needed
59 temp_list = []
60 for key in f0b:
61 temp_list.append(f0b[key])
62 for key in astromb:
63 temp_list.append(astromb[key])
64 for key in rapidb:
65 temp_list.append(rapidb[key])
66 for metricb in temp_list:
67 metricb.displayDict['subgroup'] = metricb.displayDict['group']
68 metricb.displayDict['group'] = 'SRD'
69 bundleList.extend(temp_list)
71 #########################
72 # Solar System
73 #########################
75 # XXX -- may want to do Solar system seperatly
77 # XXX--fraction of NEOs detected (assume some nominal size and albido)
78 # XXX -- fraction of MBAs detected
79 # XXX -- fraction of KBOs detected
80 # XXX--any others? Planet 9s? Comets? Neptune Trojans?
82 #########################
83 # Cosmology
84 #########################
86 displayDict = {'group': 'Cosmology', 'subgroup': 'galaxy counts', 'order': 0, 'caption': None}
87 plotDict = {'percentileClip': 95.}
88 sql = extraSql + joiner + 'filter="i"'
89 metric = GalaxyCountsMetric_extended(filterBand='i', redshiftBin='all', nside=nside)
90 summary = [metrics.AreaSummaryMetric(area=18000, reduce_func=np.sum, decreasing=True, metricName='N Galaxies (WFD)')]
91 summary.append(metrics.SumMetric(metricName='N Galaxies (all)'))
92 # make sure slicer has cache off
93 slicer = slicers.HealpixSlicer(nside=nside, useCache=False)
94 bundle = mb.MetricBundle(metric, slicer, sql, plotDict=plotDict,
95 displayDict=displayDict, summaryMetrics=summary,
96 plotFuncs=subsetPlots)
97 bundleList.append(bundle)
98 displayDict['order'] += 1
100 # let's put Type Ia SN in here
101 displayDict['subgroup'] = 'SNe Ia'
102 metadata = ''
103 # XXX-- use the light curves from PLASTICC here
104 displayDict['caption'] = 'Fraction of normal SNe Ia'
105 sql = ''
106 slicer = plasticc_slicer(plcs=plasticc_models_dict['SNIa-normal'], seed=42, badval=0)
107 metric = Plasticc_metric(metricName='SNIa')
108 # Set the maskval so that we count missing objects as zero.
109 summary_stats = [metrics.MeanMetric(maskVal=0)]
110 plotFuncs = [plots.HealpixSkyMap()]
111 bundle = mb.MetricBundle(metric, slicer, sql, runName=runName, summaryMetrics=summary_stats,
112 plotFuncs=plotFuncs, metadata=metadata, displayDict=displayDict)
113 bundleList.append(bundle)
114 displayDict['order'] += 1
116 # XXX--need some sort of metric for weak lensing and camera rotation.
118 #########################
119 # Variables and Transients
120 #########################
121 displayDict = {'group': 'Variables and Transients', 'subgroup': 'Periodic Stars',
122 'order': 0, 'caption': None}
123 periods = [0.1, 0.5, 1., 2., 5., 10., 20.] # days
124 amplitudes = [.05]*len(periods)
125 starMags = [20]*len(periods)
127 plotDict = {}
128 metadata = ''
129 sql = extraSql
130 displayDict['caption'] = 'Measure if a periodic signal can be detected for an r=%i star with amplitude of %.2f mags and variety of periods' % (max(starMags), max(amplitudes))
132 summary = metrics.MeanMetric()
133 metric = metrics.PeriodicDetectMetric(periods=periods, starMags=starMags, amplitudes=amplitudes)
134 bundle = mb.MetricBundle(metric, healslicer, sql, metadata=metadata,
135 displayDict=displayDict, plotDict=plotDict,
136 plotFuncs=subsetPlots, summaryMetrics=summary)
137 bundleList.append(bundle)
138 displayDict['order'] += 1
140 # XXX add some PLASTICC metrics for kilovnova and tidal disruption events.
141 displayDict['subgroup'] = 'KN'
142 displayDict['caption'] = 'Fraction of Kilonova (from PLASTICC)'
143 sql = ''
144 slicer = plasticc_slicer(plcs=plasticc_models_dict['KN'], seed=43, badval=0)
145 metric = Plasticc_metric(metricName='KN')
146 summary_stats = [metrics.MeanMetric(maskVal=0)]
147 plotFuncs = [plots.HealpixSkyMap()]
148 bundle = mb.MetricBundle(metric, slicer, sql, runName=runName, summaryMetrics=summary_stats,
149 plotFuncs=plotFuncs, metadata=metadata,
150 displayDict=displayDict)
151 bundleList.append(bundle)
153 displayDict['order'] += 1
155 # XXX -- would be good to add some microlensing events, for both MW and LMC/SMC.
157 #########################
158 # Milky Way
159 #########################
161 displayDict = {'group': 'Milky Way', 'subgroup': '',
162 'order': 0, 'caption': None}
164 #########################
165 # DDF
166 #########################
167 ddf_time_bundleDicts = []
168 if DDF:
169 # Hide this import to avoid adding a dependency.
170 from lsst.sims.featureScheduler.surveys import generate_dd_surveys
171 ddf_surveys = generate_dd_surveys()
172 # For doing a high-res sampling of the DDF for co-adds
173 ddf_radius = 1.8 # Degrees
174 ddf_nside = 512
176 ra, dec = hpid2RaDec(ddf_nside, np.arange(hp.nside2npix(ddf_nside)))
178 displayDict = {'group': 'DDF depths', 'subgroup': None,
179 'order': 0, 'caption': None}
181 for survey in ddf_surveys:
182 displayDict['subgroup'] = survey.survey_name
183 # Crop off the u-band only DDF
184 if survey.survey_name[0:4] != 'DD:u':
185 dist_to_ddf = angularSeparation(ra, dec, np.degrees(survey.ra), np.degrees(survey.dec))
186 goodhp = np.where(dist_to_ddf <= ddf_radius)
187 slicer = slicers.UserPointsSlicer(ra=ra[goodhp], dec=dec[goodhp], useCamera=False)
188 for filtername in ['u', 'g', 'r', 'i', 'z', 'y']:
189 metric = metrics.Coaddm5Metric(metricName=survey.survey_name+', ' + filtername)
190 summary = [metrics.MedianMetric(metricName='median depth ' + survey.survey_name+', ' + filtername)]
191 sql = extraSql + joiner + 'filter = "%s"' % filtername
192 bundle = mb.MetricBundle(metric, slicer, sql, metadata=metadata,
193 displayDict=displayDict, summaryMetrics=summary,
194 plotFuncs=[])
195 bundleList.append(bundle)
196 displayDict['order'] += 1
198 displayDict = {'group': 'DDF Transients', 'subgroup': None,
199 'order': 0, 'caption': None}
200 for survey in ddf_surveys:
201 displayDict['subgroup'] = survey.survey_name
202 if survey.survey_name[0:4] != 'DD:u':
203 slicer = plasticc_slicer(plcs=plasticc_models_dict['SNIa-normal'], seed=42,
204 ra_cen=survey.ra, dec_cen=survey.dec, radius=np.radians(3.), useCamera=False)
205 metric = Plasticc_metric(metricName=survey.survey_name+' SNIa')
206 sql = ''
207 summary_stats = [metrics.MeanMetric(maskVal=0)]
208 plotFuncs = [plots.HealpixSkyMap()]
209 bundle = mb.MetricBundle(metric, slicer, sql, runName=runName, summaryMetrics=summary_stats,
210 plotFuncs=plotFuncs, metadata=metadata,
211 displayDict=displayDict)
212 bundleList.append(bundle)
214 displayDict['order'] += 1
216 for b in bundleList:
217 b.setRunName(runName)
219 bundleDict = mb.makeBundlesDictFromList(bundleList)
221 for ddf_time in ddf_time_bundleDicts:
222 bundleDict.update(ddf_time)
224 return bundleDict