Coverage for python/lsst/sims/maf/metrics/snCadenceMetric.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
1import numpy as np
2import lsst.sims.maf.metrics as metrics
4__all__ = ['SNCadenceMetric']
7class SNCadenceMetric(metrics.BaseMetric):
8 """
9 Metric to estimate the redshift limit for faint supernovae (x1,color) = (-2.0,0.2)
11 Parameters
12 ----------
13 list : str, opt
14 Name of the columns used to estimate the metric
15 coadd : bool, opt
16 to make "coaddition" per night (uses snStacker)
17 Default True
18 lim_sn : class, opt
19 Reference data used to estimate redshift values (interpolation)
20 """
22 def __init__(self, metricName='SNCadenceMetric',
23 mjdCol='observationStartMJD', RaCol='fieldRA', DecCol='fieldDec',
24 filterCol='filter', m5Col='fiveSigmaDepth', exptimeCol='visitExposureTime',
25 nightCol='night', obsidCol='observationId', nexpCol='numExposures',
26 vistimeCol='visitTime', coadd=True, lim_sn=None, **kwargs):
28 self.mjdCol = mjdCol
29 self.m5Col = m5Col
30 self.filterCol = filterCol
31 self.RaCol = RaCol
32 self.DecCol = DecCol
33 self.exptimeCol = exptimeCol
34 self.seasonCol = 'season'
35 self.nightCol = nightCol
36 self.obsidCol = obsidCol
37 self.nexpCol = nexpCol
38 self.vistimeCol = vistimeCol
40 cols = [self.nightCol, self.m5Col, self.filterCol, self.mjdCol, self.obsidCol,
41 self.nexpCol, self.vistimeCol, self.exptimeCol, self.seasonCol]
42 if coadd:
43 cols += ['coadd']
45 super(SNCadenceMetric, self).__init__(
46 col=cols, metricName=metricName, **kwargs)
48 self.filterNames = np.array(['u', 'g', 'r', 'i', 'z', 'y'])
50 self.lim_sn = lim_sn
52 def run(self, dataSlice, slicePoint=None):
54 # Cut down to only include filters in correct wave range.
56 goodFilters = np.in1d(dataSlice['filter'], self.filterNames)
57 dataSlice = dataSlice[goodFilters]
58 if dataSlice.size == 0:
59 return None
60 dataSlice.sort(order=self.mjdCol)
62 r = []
63 fieldRA = np.mean(dataSlice[self.RaCol])
64 fieldDec = np.mean(dataSlice[self.DecCol])
65 band = np.unique(dataSlice[self.filterCol])[0]
67 sel = dataSlice
68 bins = np.arange(np.floor(sel[self.mjdCol].min()), np.ceil(
69 sel[self.mjdCol].max()), 1.)
70 c, b = np.histogram(sel[self.mjdCol], bins=bins)
71 if (c.mean() < 1.e-8) | np.isnan(c).any() | np.isnan(c.mean()):
72 cadence = 0.
73 else:
74 cadence = 1. / c.mean()
75 # time_diff = sel[self.mjdCol][1:]-sel[self.mjdCol][:-1]
76 r.append((fieldRA, fieldDec, band,
77 np.mean(sel[self.m5Col]), cadence))
79 res = np.rec.fromrecords(
80 r, names=['fieldRA', 'fieldDec', 'band', 'm5_mean', 'cadence_mean'])
82 zref = self.lim_sn.interp_griddata(res)
84 if np.isnan(zref):
85 zref = self.badval
87 return zref