Simulation: add utils

This commit is contained in:
Eric Teunis de Boone 2022-03-11 16:14:48 +01:00
parent 598d883c3e
commit e6d6d595d4
3 changed files with 24 additions and 0 deletions

View file

@ -1,2 +1,3 @@
from .travelsignal import *
from .location import *
from .util import *

View file

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

20
simulations/lib/util.py Normal file
View file

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