Skip to content
Snippets Groups Projects
Commit 4c46b543 authored by Raphael's avatar Raphael
Browse files

basic features operation

parent cdc56f8a
No related branches found
No related tags found
1 merge request!6Develop
......@@ -147,6 +147,7 @@ def angle_between_three_points(p1, p2, p3):
else:
return result
def compute_point_angles(dat):
angles = np.zeros(dat.shape[0])
......@@ -193,7 +194,7 @@ def angle_dispersion(dat, radius):
return disp
@jit(nopython=True)
def apply_func_on_window(dat, func, radius, on_edge='copy'):
result = np.zeros(dat.shape)
if on_edge == 'copy':
......@@ -202,8 +203,15 @@ def apply_func_on_window(dat, func, radius, on_edge='copy'):
data = dat[i - radius:i + radius + 1]
result[i - radius] = func(data)
return result
else:
raise ValueError(f"{on_edge} not recognised, options are: ['copy']")
def apply_time_sequence(dat, time, func):
result = np.empty(dat.shape[0])
result[0] = func(dat[0], dat[1], time[0], time[1])
for i in range(1, dat.shape[0]):
result[i] = func(dat[i-1], dat[i], time[i-1], time[i])
return result
class AISTrajectory:
def __init__(self, df, interpolation_time=None):
......@@ -401,10 +409,21 @@ class AISTrajectory:
return result
def apply_func_on_time_window(self, func, radius, column, new_column=None):
dat = self.df[column]
dat = self.df[column].to_numpy()
result = apply_func_on_window(dat, func, radius, on_edge='copy')
if new_column is None:
self.df[column] = result
else:
self.df[new_column] = result
def apply_time_sequence_func(self, func, column, new_column=None):
dat = self.df[column].to_numpy()
time = self.df['ts_sec'].to_numpy()
result = apply_time_sequence(dat, time, func)
if new_column is None:
self.df[column] = result
else:
self.df[new_column] = result
......@@ -40,3 +40,7 @@ def angular_time_derivative(angle1, angle2, ts1, ts2):
z = z2 / z1
return cmath.polar(z)[1] / (ts2 - ts1)
def time_derivative(f1, f2, ts1, ts2):
return (f2 - f1) / (ts2 - ts1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment