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

1import numpy as np 

2from .baseMetric import BaseMetric 

3 

4__all__ = ['PairMetric'] 

5 

6 

7class PairMetric(BaseMetric): 

8 """ 

9 Count the number of pairs that could be used for Solar System object detection 

10 """ 

11 def __init__(self, mjdCol='observationStartMJD', metricName='Pairs', match_min=20., match_max=40., 

12 binsize=5., **kwargs): 

13 """ 

14 Parameters 

15 ---------- 

16 match_min : float (20.) 

17 Minutes after first observation to count something as a match 

18 match_max : float (40.) 

19 Minutes after first observation to count something as a match 

20 binsize : float (5.) 

21 Binsize to use (minutes) 

22 """ 

23 self.mjdCol = mjdCol 

24 self.binsize = binsize/60./24. 

25 self.match_min = match_min/60./24. 

26 self.match_max = match_max/60./24. 

27 super(PairMetric, self).__init__(col=mjdCol, metricName=metricName, 

28 units='N Pairs', **kwargs) 

29 

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

31 bins = np.arange(dataSlice[self.mjdCol].min(), 

32 dataSlice[self.mjdCol].max()+self.binsize, self.binsize) 

33 

34 hist, bin_edges = np.histogram(dataSlice[self.mjdCol], bins=bins) 

35 nbin_min = np.round(self.match_min / self.binsize) 

36 nbin_max = np.round(self.match_max / self.binsize) 

37 bins_to_check = np.arange(nbin_min, nbin_max+1, 1) 

38 bins_w_obs = np.where(hist > 0)[0] 

39 # now, for each bin with an observation, need to check if there is a bin 

40 # far enough ahead that is also populated. 

41 result = 0 

42 for binadd in bins_to_check: 

43 result += np.size(np.intersect1d(bins_w_obs, bins_w_obs+binadd)) 

44 if result == 0: 

45 result = self.badval 

46 return result 

47 

48