From 81ec1ad7e2a2d9481429e00b58585305690c0569 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Mon, 21 Mar 2022 14:03:05 +0100 Subject: [PATCH] SimuLib: signal time offset functions (small tweaks) --- simulations/lib/signals/signal.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/simulations/lib/signals/signal.py b/simulations/lib/signals/signal.py index 4b3935d..68cdd70 100644 --- a/simulations/lib/signals/signal.py +++ b/simulations/lib/signals/signal.py @@ -43,7 +43,7 @@ class Signal(): raise NotImplementedError - def spatial_time(self, x_f, velocity=None, x_0=None): + def spatial_time_offset(self, x_f, velocity=None, x_0=None): """ Calculate the time offset caused by a spatial difference. """ @@ -55,6 +55,16 @@ class Signal(): return np.sum(np.sqrt( (x_f - x_0)**2 )/velocity) + def temporal_time_offset(self, t_f, t_0=None): + """ + Calculate the time offset caused by a temporal difference. + """ + if t_0 is None: + t_0 = self.t_0 + + return t_f - t_0 + + def total_time_offset(self, t_f = None, x_f = None, t_0 = None, x_0 = None, velocity = None): """ Calculate how much time shifting is needed to go from (t_0, x_0) to (t_f, x_f). @@ -75,7 +85,7 @@ class Signal(): if x_0 is None: x_0 = self.x_0 - spatial_time_offset = self.spatial_time(x_f, x_0=x_0, velocity=velocity) + spatial_time_offset = self.spatial_time_offset(x_f, x_0=x_0, velocity=velocity) ## temporal offset if t_f is None: @@ -86,6 +96,6 @@ class Signal(): if t_0 is None: t_0 = self.t_0 - temporal_time_offset = t_f - t_0 + temporal_time_offset = self.temporal_time_offset(t_f, t_0=t_0) return temporal_time_offset - spatial_time_offset