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

1import numpy as np 

2import healpy as hp 

3import lsst.sims.maf.metrics as metrics 

4import lsst.sims.maf.slicers as slicers 

5import lsst.sims.maf.plots as plots 

6import lsst.sims.maf.maps as maps 

7import lsst.sims.maf.metricBundles as mb 

8from .common import standardSummary, filterList, combineMetadata 

9from .colMapDict import ColMapDict 

10 

11__all__ = ['descWFDBatch', 'tdcBatch'] 

12 

13 

14def descWFDBatch(colmap=None, runName='opsim', nside=64, 

15 bandpass='i', nfilters_needed=6, lim_ebv=0.2, 

16 mag_cuts = {1: 24.75 - 0.1, 3: 25.35 - 0.1, 6: 25.72 - 0.1, 10: 26.0 - 0.1}): 

17 

18 # Hide some dependencies .. we should probably bring these into MAF 

19 from mafContrib.lssmetrics.depthLimitedNumGalMetric import DepthLimitedNumGalMetric 

20 from mafContrib import (Plasticc_metric, plasticc_slicer, load_plasticc_lc) 

21 

22 # The options to add additional sql constraints are removed for now. 

23 if colmap is None: 

24 colmap = ColMapDict('fbs') 

25 

26 # Calculate a subset of DESC WFD-related metrics. 

27 displayDict = {'group': 'Cosmology'} 

28 subgroupCount = 1 

29 

30 standardStats = standardSummary(withCount=False) 

31 subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()] 

32 

33 if not isinstance(mag_cuts, dict): 

34 if isinstance(mag_cuts, float) or isinstance(mag_cuts, int): 

35 mag_cuts = {10: mag_cuts} 

36 else: 

37 raise TypeError() 

38 yrs = list(mag_cuts.keys()) 

39 maxYr = max(yrs) 

40 

41 # Load up the plastic light curves 

42 models = ['SNIa-normal'] 

43 plasticc_models_dict = {} 

44 for model in models: 

45 plasticc_models_dict[model] = list(load_plasticc_lc(model=model).values()) 

46 

47 # One of the primary concerns for DESC WFD metrics is to add dust extinction and coadded depth limits 

48 # as well as to get some coverage in all 6 bandpasses. 

49 # These cuts figure into many of the general metrics. 

50 

51 displayDict['subgroup'] = f'{subgroupCount}: Static Science' 

52 ## Static Science 

53 # Calculate the static science metrics - effective survey area, mean/median coadded depth, stdev of 

54 # coadded depth and the 3x2ptFoM emulator. 

55 

56 dustmap = maps.DustMap(nside=nside, interp=False) 

57 pix_area = hp.nside2pixarea(nside, degrees=True) 

58 summaryMetrics = [metrics.MeanMetric(), metrics.MedianMetric(), metrics.RmsMetric(), 

59 metrics.CountRatioMetric(normVal=1/pix_area, metricName='Effective Area (deg)')] 

60 bundleList = [] 

61 displayDict['order'] = 0 

62 for yr_cut in yrs: 

63 ptsrc_lim_mag_i_band = mag_cuts[yr_cut] 

64 sqlconstraint = 'night <= %s' % (yr_cut * 365.25) 

65 sqlconstraint += ' and note not like "DD%"' 

66 metadata = f'{bandpass} band non-DD year {yr_cut}' 

67 ThreebyTwoSummary = metrics.StaticProbesFoMEmulatorMetricSimple(nside=nside, year=yr_cut, 

68 metricName='3x2ptFoM') 

69 print(colmap['fiveSigmaDepth'], colmap['filter']) 

70 m = metrics.ExgalM5_with_cuts(m5Col=colmap['fiveSigmaDepth'], filterCol=colmap['filter'], 

71 lsstFilter=bandpass, nFilters=nfilters_needed, 

72 extinction_cut=lim_ebv, depth_cut=ptsrc_lim_mag_i_band) 

73 s = slicers.HealpixSlicer(nside=nside, useCache=False) 

74 caption = f'Cosmology/Static Science metrics are based on evaluating the region of ' 

75 caption += f'the sky that meets the requirements (in year {yr_cut} of coverage in ' 

76 caption += f'all {nfilters_needed}, a lower E(B-V) value than {lim_ebv}, and at ' 

77 caption += f'least a coadded depth of {ptsrc_lim_mag_i_band} in {bandpass}. ' 

78 caption += f'From there the effective survey area, coadded depth, standard deviation of the depth, ' 

79 caption += f'and a 3x2pt static science figure of merit emulator are calculated using the ' 

80 caption += f'dust-extincted coadded depth map (over that reduced footprint).' 

81 displayDict['caption'] = caption 

82 bundle = mb.MetricBundle(m, s, sqlconstraint, mapsList=[dustmap], metadata=metadata, 

83 summaryMetrics=summaryMetrics + [ThreebyTwoSummary], 

84 displayDict=displayDict) 

85 displayDict['order'] += 1 

86 bundleList.append(bundle) 

87 

88 

89 ## LSS Science 

90 # The only metric we have from LSS is the NGals metric - which is similar to the GalaxyCountsExtended 

91 # metric, but evaluated only on the depth/dust cuts footprint. 

92 subgroupCount += 1 

93 displayDict['subgroup'] = f'{subgroupCount}: LSS' 

94 displayDict['order'] = 0 

95 plotDict = {'nTicks': 5} 

96 # Have to include all filters in query, so that we check for all-band coverage. 

97 # Galaxy numbers calculated using 'bandpass' images only though. 

98 sqlconstraint = f'note not like "DD%"' 

99 metadata = f'{bandpass} band galaxies non-DD' 

100 metric = DepthLimitedNumGalMetric(m5Col=colmap['fiveSigmaDepth'], filterCol=colmap['filter'], 

101 nside=nside, filterBand=bandpass, redshiftBin='all', 

102 nfilters_needed=nfilters_needed, 

103 lim_mag_i_ptsrc=mag_cuts[maxYr], lim_ebv=lim_ebv) 

104 summary = [metrics.AreaSummaryMetric(area=18000, reduce_func=np.sum, decreasing=True, 

105 metricName='N Galaxies (18k)')] 

106 summary.append(metrics.SumMetric(metricName='N Galaxies (all)')) 

107 slicer = slicers.HealpixSlicer(nside=nside, useCache=False) 

108 bundle = mb.MetricBundle(metric, slicer, sqlconstraint, plotDict=plotDict, 

109 metadata=metadata, mapsList=[dustmap], 

110 displayDict=displayDict, summaryMetrics=summary, 

111 plotFuncs=subsetPlots) 

112 bundleList.append(bundle) 

113 

114 

115 ## WL metrics 

116 # Calculates the number of visits per pointing, after removing parts of the footprint due to dust/depth 

117 subgroupCount += 1 

118 displayDict['subgroup'] = f'{subgroupCount}: WL' 

119 displayDict['order'] = 0 

120 sqlconstraint = f'note not like "DD%" and filter = "{bandpass}"' 

121 metadata = f'{bandpass} band non-DD' 

122 minExpTime = 15 

123 m = metrics.WeakLensingNvisits(m5Col=colmap['fiveSigmaDepth'], expTimeCol=colmap['exptime'], 

124 lsstFilter=bandpass, depthlim=mag_cuts[maxYr], 

125 ebvlim=lim_ebv, min_expTime=minExpTime) 

126 s = slicers.HealpixSlicer(nside=nside, useCache=False) 

127 displayDict['caption'] = f'The number of visits per pointing, over the same reduced footprint as ' 

128 displayDict['caption'] += f'described above. A cutoff of {minExpTime} removes very short visits.' 

129 displayDict['order'] = 1 

130 bundle = mb.MetricBundle(m, s, sqlconstraint, mapsList=[dustmap], metadata=metadata, 

131 summaryMetrics=standardStats, displayDict=displayDict) 

132 bundleList.append(bundle) 

133 

134 # This probably will get replaced by @pgris's SN metrics? 

135 subgroupCount += 1 

136 displayDict['subgroup'] = f'{subgroupCount}: SNe Ia' 

137 displayDict['order'] = 0 

138 # XXX-- use the light curves from PLASTICC here 

139 displayDict['caption'] = 'Fraction of normal SNe Ia (using PLaSTICCs)' 

140 sqlconstraint = 'note not like "DD%"' 

141 metadata = 'non-DD' 

142 slicer = plasticc_slicer(plcs=plasticc_models_dict['SNIa-normal'], seed=42, badval=0) 

143 metric = Plasticc_metric(metricName='SNIa') 

144 # Set the maskval so that we count missing objects as zero. 

145 summary_stats = [metrics.MeanMetric(maskVal=0)] 

146 plotFuncs = [plots.HealpixSkyMap()] 

147 bundle = mb.MetricBundle(metric, slicer, sqlconstraint, 

148 metadata=metadata, summaryMetrics=summary_stats, 

149 plotFuncs=plotFuncs, displayDict=displayDict) 

150 bundleList.append(bundle) 

151 

152 subgroupCount += 1 

153 displayDict['subgroup'] = f'{subgroupCount}: Camera Rotator' 

154 displayDict['caption'] = 'Kuiper statistic (0 is uniform, 1 is delta function) of the ' 

155 slicer = slicers.HealpixSlicer(nside=nside) 

156 metric1 = metrics.KuiperMetric('rotSkyPos') 

157 metric2 = metrics.KuiperMetric('rotTelPos') 

158 filterlist, colors, filterorders, filtersqls, filtermetadata = filterList(all=False, 

159 extraSql=None, 

160 extraMetadata=None) 

161 for f in filterlist: 

162 for m in [metric1, metric2]: 

163 plotDict = {'color': colors[f]} 

164 displayDict['order'] = filterorders[f] 

165 displayDict['caption'] += f"{m.colname} for visits in {f} band." 

166 bundleList.append(mb.MetricBundle(m, slicer, filtersqls[f], plotDict=plotDict, 

167 displayDict=displayDict, summaryMetrics=standardStats, 

168 plotFuncs=subsetPlots)) 

169 

170 # Set the runName for all bundles and return the bundleDict. 

171 for b in bundleList: 

172 b.setRunName(runName) 

173 return mb.makeBundlesDictFromList(bundleList) 

174 

175 

176def tdcBatch(colmap=None, runName='opsim', nside=64, accuracyThreshold=0.04, 

177 extraSql=None, extraMetadata=None): 

178 # The options to add additional sql constraints are removed for now. 

179 if colmap is None: 

180 colmap = ColMapDict('fbs') 

181 

182 # Calculate a subset of DESC WFD-related metrics. 

183 displayDict = {'group': 'Strong Lensing'} 

184 displayDict['subgroup'] = 'Lens Time Delay' 

185 

186 subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()] 

187 

188 summaryMetrics = [metrics.MeanMetric(), metrics.MedianMetric(), metrics.RmsMetric()] 

189 # Ideally need a way to do better on calculating the summary metrics for the high accuracy area. 

190 

191 slicer = slicers.HealpixSlicer(nside=nside) 

192 tdcMetric = metrics.TdcMetric(metricName='TDC', nightCol=colmap['night'], 

193 expTimeCol=colmap['exptime'], mjdCol=colmap['mjd']) 

194 

195 bundle = mb.MetricBundle(tdcMetric, slicer, constraint=extraSql, metadata=extraMetadata, 

196 displayDict=displayDict, plotFuncs=subsetPlots, 

197 summaryMetrics=summaryMetrics) 

198 

199 bundleList = [bundle] 

200 

201 # Set the runName for all bundles and return the bundleDict. 

202 for b in bundleList: 

203 b.setRunName(runName) 

204 return mb.makeBundlesDictFromList(bundleList)