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

import numpy as np 

from .baseMetric import BaseMetric 

 

__all__ = ['PairMetric'] 

 

 

class PairMetric(BaseMetric): 

""" 

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

""" 

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

binsize=5., **kwargs): 

""" 

Parameters 

---------- 

match_min : float (20.) 

Minutes after first observation to count something as a match 

match_max : float (40.) 

Minutes after first observation to count something as a match 

binsize : float (5.) 

Binsize to use (minutes) 

""" 

self.mjdCol = mjdCol 

self.binsize = binsize/60./24. 

self.match_min = match_min/60./24. 

self.match_max = match_max/60./24. 

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

units='N Pairs', **kwargs) 

 

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

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

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

 

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

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

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

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

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

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

# far enough ahead that is also populated. 

result = 0 

for binadd in bins_to_check: 

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

if result == 0: 

result = self.badval 

return result