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

1from builtins import str 

2from .baseMetric import BaseMetric 

3from .simpleMetrics import Coaddm5Metric 

4import numpy as np 

5import warnings 

6 

7__all__ = ['OptimalM5Metric'] 

8 

9 

10class OptimalM5Metric(BaseMetric): 

11 """Compare the co-added depth of the survey to one where 

12 all the observations were taken on the meridian. 

13 

14 Parameters 

15 ---------- 

16 m5Col : str ('fiveSigmaDepth') 

17 Column name that contains the five-sigma limiting depth of 

18 each observation 

19 optM5Col : str ('m5Optimal') 

20 The column name of the five-sigma-limiting depth if the 

21 observation had been taken on the meridian. 

22 normalize : bool (False) 

23 If False, metric returns how many more observations would need 

24 to be taken to reach the optimal depth. If True, the number 

25 is normalized by the total number of observations already taken 

26 at that position. 

27 magDiff : bool (False) 

28 If True, metric returns the magnitude difference between the 

29 achieved coadded depth and the optimal coadded depth. 

30 

31 Returns 

32 -------- 

33 numpy.array 

34 

35 If magDiff is True, returns the magnitude difference between the 

36 optimal and actual coadded depth. If normalize is False 

37 (default), the result is the number of additional observations 

38 (taken at the median depth) the survey needs to catch up to 

39 optimal. If normalize is True, the result is divided by the 

40 number of observations already taken. So if a 10-year survey 

41 returns 20%, it would need to run for 12 years to reach the same 

42 depth as a 10-year meridian survey. 

43 

44 """ 

45 

46 def __init__(self, m5Col='fiveSigmaDepth', optM5Col='m5Optimal', 

47 filterCol='filter', magDiff=False, normalize=False, **kwargs): 

48 

49 if normalize: 

50 self.units = '% behind' 

51 else: 

52 self.units = 'N visits behind' 

53 if magDiff: 

54 self.units = 'mags' 

55 super(OptimalM5Metric, self).__init__(col=[m5Col, optM5Col,filterCol], 

56 units=self.units, **kwargs) 

57 self.m5Col = m5Col 

58 self.optM5Col = optM5Col 

59 self.normalize = normalize 

60 self.filterCol = filterCol 

61 self.magDiff = magDiff 

62 self.coaddRegular = Coaddm5Metric(m5Col=m5Col) 

63 self.coaddOptimal = Coaddm5Metric(m5Col=optM5Col) 

64 

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

66 

67 filters = np.unique(dataSlice[self.filterCol]) 

68 if np.size(filters) > 1: 

69 warnings.warn("OptimalM5Metric does not make sense mixing filters. Currently using filters " + 

70 str(filters)) 

71 regularDepth = self.coaddRegular.run(dataSlice) 

72 optimalDepth = self.coaddOptimal.run(dataSlice) 

73 if self.magDiff: 

74 return optimalDepth-regularDepth 

75 

76 medianSingle = np.median(dataSlice[self.m5Col]) 

77 

78 # Number of additional median observations to get as deep as optimal 

79 result = (10.**(0.8 * optimalDepth)-10.**(0.8 * regularDepth)) / \ 

80 (10.**(0.8 * medianSingle)) 

81 

82 if self.normalize: 

83 result = result/np.size(dataSlice)*100. 

84 

85 return result