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

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

import numpy as np 

from .baseMetric import BaseMetric 

 

__all__ = ['TgapsMetric', 'NightgapsMetric', 'NVisitsPerNightMetric', 'MaxGapMetric'] 

 

 

class TgapsMetric(BaseMetric): 

"""Histogram the times of the gaps between observations. 

 

 

Measure the gaps between observations. By default, only gaps 

between neighboring visits are computed. If allGaps is set to true, all gaps are 

computed (i.e., if there are observations at 10, 20, 30 and 40 the default will 

return a histogram of [10,10,10] while allGaps returns a histogram of [10,10,10,20,20,30]) 

 

Parameters 

---------- 

timesCol : str, opt 

The column name for the exposure times. Values assumed to be in days. 

Default observationStartMJD. 

allGaps : bool, opt 

Histogram the gaps between all observations (True) or just successive observations (False)? 

Default is False. If all gaps are used, this metric can become significantly slower. 

bins : np.ndarray, opt 

The bins to use for the histogram of time gaps (in days, or same units as timesCol). 

Default values are bins from 0 to 2 hours, in 5 minute intervals. 

 

Returns a histogram at each slice point; these histograms can be combined and plotted using the 

'SummaryHistogram plotter'. 

""" 

 

def __init__(self, timesCol='observationStartMJD', allGaps=False, bins=np.arange(0, 120.0, 5.0)/60./24., 

units='days', **kwargs): 

# Pass the same bins to the plotter. 

self.bins = bins 

self.timesCol = timesCol 

super(TgapsMetric, self).__init__(col=[self.timesCol], metricDtype='object', units=units, **kwargs) 

self.allGaps = allGaps 

 

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

if dataSlice.size < 2: 

return self.badval 

times = np.sort(dataSlice[self.timesCol]) 

if self.allGaps: 

allDiffs = [] 

for i in np.arange(1,times.size,1): 

allDiffs.append((times-np.roll(times,i))[i:]) 

dts = np.concatenate(allDiffs) 

else: 

dts = np.diff(times) 

result, bins = np.histogram(dts, self.bins) 

return result 

 

 

class NightgapsMetric(BaseMetric): 

"""Histogram the number of nights between observations. 

 

 

Measure the gaps between observations. By default, only gaps 

between neighboring visits are computed. If allGaps is set to true, all gaps are 

computed (i.e., if there are observations at 10, 20, 30 and 40 the default will 

histogram [10,10,10] while allGaps histograms [10,10,10,20,20,30]) 

 

Parameters 

---------- 

nightCol : str, opt 

The column name for the night of each observation. 

Default 'night'. 

allGaps : bool, opt 

Histogram the gaps between all observations (True) or just successive observations (False)? 

Default is False. If all gaps are used, this metric can become significantly slower. 

bins : np.ndarray, opt 

The bins to use for the histogram of time gaps (in days, or same units as timesCol). 

Default values are bins from 0 to 10 days, in 1 day intervals. 

 

Returns a histogram at each slice point; these histograms can be combined and plotted using the 

'SummaryHistogram plotter'. 

""" 

 

def __init__(self, nightCol='night', allGaps=False, bins=np.arange(0, 10, 1), 

units='nights', **kwargs): 

# Pass the same bins to the plotter. 

self.bins = bins 

self.nightCol = nightCol 

super(NightgapsMetric, self).__init__(col=[self.nightCol], metricDtype='object', 

units=units, **kwargs) 

self.allGaps = allGaps 

 

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

if dataSlice.size < 2: 

return self.badval 

nights = np.sort(np.unique(dataSlice[self.nightCol])) 

if self.allGaps: 

allDiffs = [] 

for i in np.arange(1, nights.size,1): 

allDiffs.append((nights-np.roll(nights,i))[i:]) 

dnights = np.concatenate(allDiffs) 

else: 

dnights = np.diff(nights) 

result, bins = np.histogram(dnights, self.bins) 

return result 

 

 

class NVisitsPerNightMetric(BaseMetric): 

"""Histogram the number of visits in each night. 

 

Splits the visits by night, then histograms how many visits occur in each night. 

 

Parameters 

---------- 

nightCol : str, opt 

The column name for the night of each observation. 

Default 'night'. 

bins : np.ndarray, opt 

The bins to use for the histogram of time gaps (in days, or same units as timesCol). 

Default values are bins from 0 to 5 visits, in steps of 1. 

 

Returns a histogram at each slice point; these histograms can be combined and plotted using the 

'SummaryHistogram plotter'. 

""" 

 

def __init__(self, nightCol='night', bins=np.arange(0, 10, 1), units='#', **kwargs): 

# Pass the same bins to the plotter. 

self.bins = bins 

self.nightCol = nightCol 

super(NVisitsPerNightMetric, self).__init__(col=[self.nightCol], metricDtype='object', 

units=units, **kwargs) 

 

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

n, counts = np.unique(dataSlice[self.nightCol], return_counts=True) 

result, bins = np.histogram(counts, self.bins) 

return result 

 

 

class MaxGapMetric(BaseMetric): 

"""Find the maximum gap in observations. Useful for making sure there is an image within the last year that would 

make a good template image. 

""" 

 

def __init__(self, mjdCol='observationStartMJD', **kwargs): 

self.mjdCol = mjdCol 

units = 'Days' 

super(MaxGapMetric, self).__init__(col=[self.mjdCol], units=units, **kwargs) 

 

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

gaps = np.diff(np.sort(dataSlice[self.mjdCol])) 

if np.size(gaps) > 0: 

result = np.max(gaps) 

else: 

result = self.badval 

return result