yupi

This module contains the general classes defining concepts used by all the other modules.

This contains the Vector structure used across the library to store data.

class Vector(arr, dtype=None, copy=False)

Represents a vector

Parameters:
  • arr (Any)

  • dtype (Any)

  • copy (bool)

Return type:

Vector

property norm: Vector | float

Calculates the norm of the vector. If the vector is alist of vectors then the norm of each item is calculated

Type:

Vector

property delta: Vector

Calculates the differnece between each item

Type:

Vector

property x: Vector

X component of all vector items

Type:

Vector

property y: Vector

Y component of all vector items

Type:

Vector

property z: Vector

Z component of all vector items

Type:

Vector

component(dim)

Extract a given component from all vector items.

Parameters:

dim (int) – Component index.

Returns:

Component extracted.

Return type:

Vector

Raises:
  • TypeError – If the vector has no axis 1.

  • TypeError – If dim is not an integer.

  • ValueError – If the shape of axis 1 of the vector is lower than dim.

Examples

>>> v = Vector([[1,2],[0,2],[3,0]])
>>> v.component(0)
Vector([1, 0, 3])
>>> v.component(1)
Vector([2, 2, 0])

Contains the basic structures for trajectories.

Axis

Represents the data for a single axis.

alias of Sequence[float] | ndarray

Point

Represents a single point.

alias of Sequence[float] | ndarray

class TrajectoryPoint(r, v, t, extra)

Represents a point of a trajectory.

Parameters:
  • r (Vector) – Positional data.

  • v (Vector) – Velocity data.

  • t (float) – Time data.

  • extra (dict[str, Any])

class Trajectory(x=None, y=None, z=None, points=None, axes=None, t=None, dt=None, t_0=None, units=None, traj_id='', lazy=False, diff_est=None, extra=None, **kwargs)

A Trajectory object represents a multidimensional trajectory. It can be iterated to obtain the corresponding point for each timestep.

Parameters:
  • x (Axis | None) – Array containing position data of X axis, by default None

  • y (Axis | None) – Array containing position data of Y axis, by default None.

  • z (Axis | None) – Array containing position data of X axis, by default None.

  • points (Sequence[Point] | np.ndarray | None) – Array containing position data as a list of points, by default None

  • axes (Sequence[Axis] | np.ndarray | None) – Array containing position data as a list of axis, by default None

  • t (Sequence[float] | np.ndarray | None) – Array containing time data, by default None.

  • dt (float | None) – If no time data is given this represents the time between each position data value.

  • t_0 (float | None) – If no time data is given this represents the initial time value, by default 0.

  • traj_id (Any) – Id of the trajectory.

  • lazy (bool) – Defines if the velocity vector is not recalculated every time is asked. By default False.

  • diff_est (dict[str, Any]) – Dictionary containing the parameters for the differentiation estimation method used to calculate velocity.

  • extra (dict[str, Sequence[Any] | np.ndarray] | None) –

    Dictionary containing extra vectors for the trajectory, by default None. Each vector should have the same length as the trajectory. These vectors will be used when iterating, indexing, or slicing the trajectory.

    You can also add any other type of non-vector information (metadata) by using kwargs.

  • units (Units | None)

  • kwargs (Any)

r

Position vector.

Type:

Vector

t

Time vector.

Type:

Vector

v

Velocity vector.

Type:

Vector

a

Acceleration vector.

Type:

Vector

dt_mean

Mean of the time data delta.

Type:

float

dt_std

Standard deviation of the time between each position data value.

Type:

float

traj_id

Id of the trajectory.

Type:

str

lazy

Defines if the velocity vector is not recalculated every time is asked.

Type:

bool

diff_est

Dictionary containing the parameters for the differentiation estimation method used to calculate velocity.

Type:

dict

Examples

You can create a trajectory object by giving the arrays that represent it:

>>> x = [0, 1.2, 3, 2.8]
>>> y = [0, 3.1, 0.7, 1.6]
>>> Trajectory(x=x, y=y)

You can also create the trajectory given the points:

>>> points = [[0, 0], [1.2, 3.1], [3, 0.7], [2.8, 1.6]]
>>> Trajectory(points=points)

Or even create it given all the data for each dimension in a single source:

>>> axes = [[0, 1.2, 3, 2.8], [0, 3.1, 0.7, 1.6]]
>>> Trajectory(axes=axes)

All of these examples create the same trajectory.

Raises:
  • ValueError – If no positional data is given.

  • ValueError – If all the given input data (x, y, z, t) does not have the same length.

  • ValueError – If t and dt given but t is not uniformly spaced.

  • ValueError – If t and dt given but dt does not match t values delta.

  • ValueError – if t and t_0 are given but t_0 is not the same as the first value of t.

Parameters:
  • x (Axis | None)

  • y (Axis | None)

  • z (Axis | None)

  • points (Sequence[Point] | np.ndarray | None)

  • axes (Sequence[Axis] | np.ndarray | None)

  • t (Sequence[float] | np.ndarray | None)

  • dt (float | None)

  • t_0 (float | None)

  • units (Units | None)

  • traj_id (Any)

  • lazy (bool)

  • diff_est (dict[str, Any] | None)

  • extra (dict[str, Sequence[Any] | np.ndarray] | None)

  • kwargs (Any)

set_diff_method(method, window_type=WindowType.FORWARD, accuracy=1)

Set the local diferentiation method.

Parameters:
  • method (DiffMethod) – Method used to differentiate.

  • window_type (WindowType) – Type of window used in the differentiation method. By default, the central window is used.

  • accuracy (int) – Accuracy of the differentiation method (only valid for FORNBERG_DIFF method). By default, the accuracy is 1.

Return type:

None

static global_diff_method(method, window_type=WindowType.FORWARD, accuracy=1)

Set the global diferentiation method.

Parameters:
  • method (DiffMethod) – Method used to differentiate.

  • window_type (WindowType) – Type of window used in the differentiation method. By default, the central window is used.

  • accuracy (int) – Accuracy of the differentiation method (only valid for FORNBERG_DIFF method). By default, the accuracy is 1.

Return type:

None

property dt: float

Returns the time between each position data value.

If the time data is not uniformly spaced it returns an estimated value.

property uniformly_spaced: bool

True if the time data is uniformly spaced

Type:

bool

property bounds: list[tuple[float, float]]

List of tuples indicanting the min and max values of each dimension

Type:

list[tuple[float]]

property dim: int

Trajectory spacial dimensions.

Type:

int

property delta_r: Vector

Difference between each couple of consecutive points in the Trajectory.

Type:

Vector

property delta_v: Vector

Difference between each couple of consecutive sample in the velocity vector of the Trajectory.

Type:

Vector

recalculate_velocity()

Recalculates the velocity according time data or dt if time data is not available.

Returns:

Velocity vector.

Return type:

Vector

recalculate_acceleration()

Recalculates the acceleration according time data or dt if time data is not available.

Returns:

Velocity vector.

Return type:

Vector

property v: Vector

Velocity vector

Type:

Vector

property a: Vector

Velocity vector

Type:

Vector

property t: Vector

Time vector

Type:

Vector

copy()

Returns a copy of the trajectory.

Returns:

Copy of the trajectory.

Return type:

Trajectory

to(units, inplace=False)

Converts the trajectory to the given units.

Parameters:
  • units (Units) – Units to convert the trajectory to.

  • inplace (bool, optional) – If True, the conversion is done in place. Otherwise, a new trajectory is returned. By default False.

Returns:

Converted trajectory.

Return type:

Trajectory