Coverage for python/lsst/sims/maf/stackers/snStacker.py : 29%

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
1from lsst.sims.maf.stackers import BaseStacker
2import numpy as np
3import numpy.lib.recfunctions as rf
5__all__ = ['CoaddStacker']
8class CoaddStacker(BaseStacker):
9 """
10 Stacker to estimate m5 "coadded" per band and par night
12 Parameters
13 ----------
14 list : str, opt
15 Name of the columns used.
16 Default : 'observationStartMJD', 'fieldRA', 'fieldDec','filter','fiveSigmaDepth','visitExposureTime','night','observationId', 'numExposures','visitTime'
18 """
19 colsAdded = ['coadd']
21 def __init__(self, mjdCol='observationStartMJD', RaCol='fieldRA', DecCol='fieldDec', m5Col='fiveSigmaDepth', nightcol='night', filterCol='filter', nightCol='night', numExposuresCol='numExposures', visitTimeCol='visitTime', visitExposureTimeCol='visitExposureTime'):
22 self.colsReq = [mjdCol, RaCol, DecCol, m5Col, filterCol, nightCol,
23 numExposuresCol, visitTimeCol, visitExposureTimeCol]
24 self.RaCol = RaCol
25 self.DecCol = DecCol
26 self.nightCol = nightCol
27 self.filterCol = filterCol
28 self.m5Col = m5Col
29 self.numExposuresCol = numExposuresCol
30 self.visitTimeCol = visitTimeCol
31 self.visitExposureTimeCol = visitExposureTimeCol
33 self.units = ['int']
35 def _run(self, simData, cols_present=False):
36 """
38 Parameters
39 ---------------
40 simData : simulation data
41 cols_present: to check whether the field has already been estimated
43 Returns
44 -----------
45 numpy array of initial fields plus modified fields:
46 - m5Col: "coadded" m5
47 - numExposuresCol: sum of numExposuresCol
48 - visitTimeCol: sum of visitTimeCol
49 - visitExposureTimeCol: sum of visitExposureTimeCol
50 - all other input fields except band (Ra, Dec, night) : median(field)
52 """
54 if cols_present:
55 # Column already present in data; assume it is correct and does not need recalculating.
56 return simData
57 self.dtype = simData.dtype
58 r = []
59 for ra, dec, band in np.unique(simData[[self.RaCol, self.DecCol, self.filterCol]]):
60 idx = np.abs(simData[self.RaCol]-ra) < 1.e-5
61 idx &= np.abs(simData[self.DecCol]-dec) < 1.e-5
62 idx &= simData[self.filterCol] == band
64 sel = simData[idx]
65 for night in np.unique(sel[self.nightCol]):
66 idxb = sel[self.nightCol] == night
67 r.append(tuple(self.fill(sel[idxb])))
69 myarray = np.array(r, dtype=self.dtype)
70 return myarray
72 def fill(self, tab):
73 """
74 Estimation of new fields (m5 "coadded" values, ...)
76 Parameters
77 ---------------
78 tab : array of (initial) data
81 Returns
82 -----------
83 tuple with modified field values:
84 - m5Col: "coadded" m5
85 - numExposuresCol: sum of numExposuresCol
86 - visitTimeCol: sum of visitTimeCol
87 - visitExposureTimeCol: sum of visitExposureTimeCol
88 - all other input fields except band (Ra, Dec, night) : median(field)
89 """
91 r = []
93 for colname in self.dtype.names:
94 if colname not in [self.m5Col, self.numExposuresCol, self.visitTimeCol, self.visitExposureTimeCol, self.filterCol]:
95 if colname == 'coadd':
96 r.append(1)
97 else:
98 r.append(np.median(tab[colname]))
99 if colname == self.m5Col:
100 r.append(self.m5_coadd(tab[self.m5Col]))
101 if colname in [self.numExposuresCol, self.visitTimeCol, self.visitExposureTimeCol]:
102 r.append(np.sum(tab[colname]))
103 if colname == self.filterCol:
104 r.append(np.unique(tab[self.filterCol])[0])
106 return r
108 def m5_coadd(self, m5):
109 """
110 Estimation of "coadded" m5 values based on:
111 flux_5sigma = 10**(-0.4*m5)
112 sigmas = flux_5sigma/5.
113 sigma_tot = 1./sqrt(np.sum(1/sigmas**2))
114 flux_tot = 5.*sigma_tot
116 Parameters
117 ---------------
118 m5 : set of m5 (five-sigma depths) values
120 Returns
121 -----------
122 "coadded" m5 value
123 """
125 fluxes = 10**(-0.4*m5)
126 sigmas = fluxes/5.
127 sigma_tot = 1./np.sqrt(np.sum(1./sigmas**2))
128 flux_tot = 5.*sigma_tot
130 return -2.5*np.log10(flux_tot)