SimuLib: signal time offset functions (small tweaks)

This commit is contained in:
Eric Teunis de Boone 2022-03-21 14:03:05 +01:00
parent 80a79bb4c6
commit 81ec1ad7e2

View file

@ -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