diff --git a/skais/ais/ais_trajectory.py b/skais/ais/ais_trajectory.py index ea9dad11744393879f5d551fa4c3a3480165923b..c3ea2a6cfd4a610caf89948bf3ac597087360077 100644 --- a/skais/ais/ais_trajectory.py +++ b/skais/ais/ais_trajectory.py @@ -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 \ No newline at end of file + 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 diff --git a/skais/process/basic_features_operations.py b/skais/process/basic_features_operations.py index 1a805fae767d88b76a2793ff1c4d61962a786fbf..c4c7d3bbbefe115b87696c4f02f4be8cb0ba532e 100644 --- a/skais/process/basic_features_operations.py +++ b/skais/process/basic_features_operations.py @@ -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)