Commit 2ddf04a8 authored by Raphael Sturgis's avatar Raphael Sturgis
Browse files

update

parent 9487015c
......@@ -53,6 +53,19 @@ def apply_func_on_window(dat, func, radius, on_edge='copy'):
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):
result = np.empty(dat.shape[0])
result[0] = func(dat[0], dat[1], time[0], time[1])
......@@ -252,6 +265,19 @@ class AISTrajectory(AISPoints):
else:
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
def apply_func_on_time_sequence(self, func, column, new_column=None):
dat = self.df[column].to_numpy()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment