Skip to content
Snippets Groups Projects
Commit 2ddf04a8 authored by Raphael Sturgis's avatar Raphael Sturgis
Browse files

update

parent 9487015c
No related branches found
No related tags found
No related merge requests found
...@@ -53,6 +53,19 @@ def apply_func_on_window(dat, func, radius, on_edge='copy'): ...@@ -53,6 +53,19 @@ def apply_func_on_window(dat, func, radius, on_edge='copy'):
raise ValueError raise ValueError
def apply_func_on_window_2(dat, func, radius):
result = np.zeros(dat.shape[0])
for i in range(0, dat.shape[0]):
ts = dat[i][0]
lower_bound = max(0, np.argmin(dat > (ts - radius)))
upper_bound = np.argmax(dat < ts + radius)
if upper_bound == 0:
upper_bound = dat.shape[0]
data = dat[lower_bound:upper_bound]
result[i] = func(data)
return result
def apply_time_sequence(dat, time, func): def apply_time_sequence(dat, time, func):
result = np.empty(dat.shape[0]) result = np.empty(dat.shape[0])
result[0] = func(dat[0], dat[1], time[0], time[1]) result[0] = func(dat[0], dat[1], time[0], time[1])
...@@ -252,6 +265,19 @@ class AISTrajectory(AISPoints): ...@@ -252,6 +265,19 @@ class AISTrajectory(AISPoints):
else: else:
self.df[new_column] = result self.df[new_column] = result
def apply_func_on_time_window_2(self, func, radius, column, new_column=None):
if type(column) is not list:
df_column = ['ts_sec', column]
else:
df_column = column + ['ts_sec']
dat = self.df[df_column].to_numpy()
result = apply_func_on_window_2(dat, func, radius)
if new_column is None:
self.df[column] = result
else:
self.df[new_column] = result
# TODO rename function/simplify # TODO rename function/simplify
def apply_func_on_time_sequence(self, func, column, new_column=None): def apply_func_on_time_sequence(self, func, column, new_column=None):
dat = self.df[column].to_numpy() dat = self.df[column].to_numpy()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment