From e6d6d595d4bbb2854a28fa3f2e7e0feec9cd4f4f Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Fri, 11 Mar 2022 16:14:48 +0100 Subject: [PATCH] Simulation: add utils --- simulations/lib/__init__.py | 1 + simulations/lib/location.py | 3 +++ simulations/lib/util.py | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 simulations/lib/util.py diff --git a/simulations/lib/__init__.py b/simulations/lib/__init__.py index 75a5779..82df24a 100644 --- a/simulations/lib/__init__.py +++ b/simulations/lib/__init__.py @@ -1,2 +1,3 @@ from .travelsignal import * from .location import * +from .util import * diff --git a/simulations/lib/location.py b/simulations/lib/location.py index c088f87..666af82 100644 --- a/simulations/lib/location.py +++ b/simulations/lib/location.py @@ -77,6 +77,9 @@ class Emitter(Location): """ Emit a signal from position x_0 (and time t_0) """ + def __repr__(self): + return "Emitter({})".format(repr(self.x)) + def emit(self, travel_signal: TravelSignal) -> TravelSignal: return partial(travel_signal, x_0=self.x) diff --git a/simulations/lib/util.py b/simulations/lib/util.py new file mode 100644 index 0000000..ef69931 --- /dev/null +++ b/simulations/lib/util.py @@ -0,0 +1,20 @@ +""" +Various useful utilities (duh) +""" + +import numpy as np + +def sampled_time(sample_rate=1, start=0, end=1, offset=0): + return offset + np.arange(start, end, 1/sample_rate) + +def rot_vector(phi1=0.12345): + """ + Return a unit vector rotated by phi radians. + """ + + unit = np.array([ + phi1, + phi1 - np.pi/2 + ]) + + return np.cos(unit)