DeterministicMmaxEstimates/util/CandidateEventsTS.py

44 lines
1.4 KiB
Python

import numpy as np
class CandidateEventsTS:
def __init__(self, data, current_time, Mc, time_win, space_win=None):
assert time_win > 0, f"Time windows is {time_win}, which should be a positive number"
self.data = data
self.current_time = current_time
self.Mc = Mc
self.time_win = time_win
self.space_win = space_win
def filter_by_time(self):
indx = np.where((self.data[:, 4] > (self.current_time - self.time_win)) & (self.data[:, 4] <= self.current_time))[0]
if len(indx) > 0:
self.data = self.data[indx, :]
else:
self.data = []
def filter_by_magnitude(self):
if self.Mc:
indx = np.where(self.data[:, 5] > self.Mc)[0]
if len(indx) > 0:
self.data = self.data[indx, :]
else:
self.data = []
def filter_by_space(self):
dist = np.sqrt(np.sum((self.data[:, 1:4] - self.data[-1, 1:4]) ** 2, axis=1))
indx = np.where(dist < self.space_win)[0]
if len(indx) > 0:
self.data = self.data[indx, :]
else:
self.data = []
def filter_data(self):
self.filter_by_time()
if len(self.data) > 0:
self.filter_by_magnitude()
if len(self.data) > 0 and self.space_win:
self.filter_by_space()
return self.data