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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

import numpy as np 

import lsst.sims.maf.metrics as metrics 

 

__all__ = ['SNcadenceMetric'] 

 

 

class SNcadenceMetric(metrics.BaseMetric): 

""" 

Metric to estimate the redshift limit for faint supernovae (x1,color) = (-2.0,0.2) 

 

Parameters 

---------- 

list : str, opt 

Name of the columns used to estimate the metric 

coadd : bool, opt 

to make "coaddition" per night (uses snStacker) 

Default True 

lim_sn : class, opt 

Reference data used to estimate redshift values (interpolation) 

""" 

 

def __init__(self, metricName='SNCadenceMetric', 

mjdCol='observationStartMJD', RaCol='fieldRA', DecCol='fieldDec', 

filterCol='filter', m5Col='fiveSigmaDepth', exptimeCol='visitExposureTime', 

nightCol='night', obsidCol='observationId', nexpCol='numExposures', 

vistimeCol='visitTime', coadd=True, lim_sn=None, **kwargs): 

 

self.mjdCol = mjdCol 

self.m5Col = m5Col 

self.filterCol = filterCol 

self.RaCol = RaCol 

self.DecCol = DecCol 

self.exptimeCol = exptimeCol 

self.seasonCol = 'season' 

self.nightCol = nightCol 

self.obsidCol = obsidCol 

self.nexpCol = nexpCol 

self.vistimeCol = vistimeCol 

 

cols = [self.nightCol, self.m5Col, self.filterCol, self.mjdCol, self.obsidCol, 

self.nexpCol, self.vistimeCol, self.exptimeCol, self.seasonCol] 

if coadd: 

cols += ['coadd'] 

 

super(SNcadenceMetric, self).__init__( 

col=cols, metricName=metricName, **kwargs) 

 

self.filterNames = np.array(['u', 'g', 'r', 'i', 'z', 'y']) 

 

self.lim_sn = lim_sn 

 

def run(self, dataSlice, slicePoint=None): 

 

# Cut down to only include filters in correct wave range. 

 

goodFilters = np.in1d(dataSlice['filter'], self.filterNames) 

dataSlice = dataSlice[goodFilters] 

if dataSlice.size == 0: 

return None 

dataSlice.sort(order=self.mjdCol) 

 

r = [] 

fieldRA = np.mean(dataSlice[self.RaCol]) 

fieldDec = np.mean(dataSlice[self.DecCol]) 

band = np.unique(dataSlice[self.filterCol])[0] 

 

sel = dataSlice 

bins = np.arange(np.floor(sel[self.mjdCol].min()), np.ceil( 

sel[self.mjdCol].max()), 1.) 

c, b = np.histogram(sel[self.mjdCol], bins=bins) 

if c.mean() < 1.e-8: 

cadence = 0. 

else: 

cadence = 1. / c.mean() 

# time_diff = sel[self.mjdCol][1:]-sel[self.mjdCol][:-1] 

r.append((fieldRA, fieldDec, band, 

np.mean(sel[self.m5Col]), cadence)) 

 

res = np.rec.fromrecords( 

r, names=['fieldRA', 'fieldDec', 'band', 'm5_mean', 'cadence_mean']) 

 

zref = self.lim_sn.Interp_griddata(res) 

 

return zref