Trajectory¶
- class acoular.trajectory.Trajectory¶
Bases:
HasStrictTraits
Represents a trajectory as a continuous curve derived from sampled points.
The
Trajectory
class computes a smooth, continuous path through a set of discrete points in space and time using spline interpolation. It also supports evaluating the trajectory and its derivatives at arbitrary time instants.- It can be used to:
define the traveling path of a moving sound source, e.g. for microphone array data simulation (see
MovingPointSource
)move a source grid along a certain path to create a fixed focus (see
BeamformerTimeTraj
andBeamformerCleantTraj
)
Exemplary use can also be seen in the rotating point source example.
See also
MovingPointSource
Model a point source moving along a trajectory.
MovingPointSourceDipole
Model a point source dipole moving along a trajectory.
MovingLineSource
Model a line source moving along a trajectory.
BeamformerCleantTraj
Beamformer implementing the CLEAN method [21] in time domain for moving sources with known trajectory.
BeamformerTimeTraj
Basic time domain beamformer with time signal output for a grid moving along a trajectory.
scipy.interpolate.splprep()
Underlying spline generation function.
scipy.interpolate.splev()
Used for evaluating the spline.
Notes
Spline interpolation provides a smooth trajectory that passes through all sampled points. The interpolation order is adjusted automatically based on the number of points.
The trajectory can be used in simulations where a source’s motion must be modeled continuously.
Examples
Create a trajectory and evaluate positions and velocities:
>>> from acoular import Trajectory >>> points = {0.0: (0.0, 0.0, 0.0), 1.0: (1.0, 0.0, 0.0), 2.0: (2.0, 1.0, 0.0)} >>> tr = Trajectory(points=points) >>> >>> tr.location(1.5) # Position at t=1.5 [array(1.5), array(0.375), array(0.)] >>> >>> for pos in tr.traj(0.0, 2.0, 0.5): # Positions every 0.5 seconds ... print(pos) (np.float64(0.0), np.float64(0.0), np.float64(0.0)) (np.float64(0.5), np.float64(-0.125), np.float64(0.0)) (np.float64(1.0), np.float64(0.0), np.float64(0.0)) (np.float64(1.5), np.float64(0.375), np.float64(0.0))
- points = Dict( …¶
Dictionary mapping time instants (keys, as floats) to sampled
(x, y, z)
positions (values, as tuples of floats) along the trajectory.
- interval = Property()¶
Automatically determined tuple
(t_min, t_max)
representing the start and end times of the trajectory, based on the keys inpoints
.
- tck = Property()¶
Internal representation of the spline, generated using
scipy.interpolate.splprep()
.
- digest = Property(depends_on=['points[]'])¶
A unique identifier for the trajectory, based on its points. (read-only)
- location(t, der=0)¶
Compute the trajectory’s position or derivatives at specified times.
- Parameters:
- Returns:
numpy.ndarray
(x, y, z)
arrays representing the trajectory’s position (or derivative) at the given time(s). The shape matches that oft
.
Examples
>>> import acoular as ac >>> >>> points = {0.0: (0.0, 0.0, 0.0), 1.0: (1.0, 2.0, 0.0), 2.0: (2.0, 4.0, 0.0)} >>> tr = ac.Trajectory(points=points) >>> tr.location(1.0) # Position at t=1.0 [array(1.), array(2.), array(0.)] >>> tr.location([0.5, 1.5], der=1) # Velocity at t=0.5 and t=1.5 [array([1., 1.]), array([2., 2.]), array([0., 0.])]
- traj(t_start, t_end=None, delta_t=None, der=0)¶
Interate through trajectory positions or derivatives at specified intervals.
- Parameters:
- t_start
float
Start time for the trajectory. Default is earliest key in
points
.- t_end
float
, optional End time of the trajectory. Default is the latest key in
points
.- delta_t
float
, optional Time interval between consecutive points to yield. Default is the value of
t_start
.- derint, optional
- Order of the derivative to compute:
0
for positions (default),1
for velocities,2
for accelerations, etc.
- t_start
- Yields:
Notes
The function precomputes all interpolated locations for efficiency and yields them sequentially.
Examples
Create a trajectory and iterate through the positions in the
interval
:>>> import acoular as ac >>> >>> points = {0.0: (0.0, 0.0, 0.0), 1.0: (1.0, 0.0, 0.0), 2.0: (2.0, 1.0, 0.0)} >>> tr = ac.Trajectory(points=points) >>> for pos in tr.traj(0.0, 2.0, 0.5): ... print(pos) (np.float64(0.0), np.float64(0.0), np.float64(0.0)) (np.float64(0.5), np.float64(-0.125), np.float64(0.0)) (np.float64(1.0), np.float64(0.0), np.float64(0.0)) (np.float64(1.5), np.float64(0.375), np.float64(0.0))