yupi.transformations

This module contains a set of functions capable of applying transformations to trajectories such as filtering, resampling, etc.

All the resources of this module should be imported directly from yupi.transormations.

add_moving_FoR(traj, reference, start_at_origin=True, new_traj_id=None)

This function fuses the information of a trajectory with an external reference of the motion of the Frame of Reference (FoR).

It allows to remap the information gathered in local SoRs to a more general FoR.

Parameters:
  • traj (Trajectory) – Input trajectory.

  • reference (tuple[np.ndarray,np.ndarray,np.ndarray]) – Angular and translational parameters of the form (ang:np.ndarray, tx:np.ndarray, ty:np.ndarray) that accounts for the orientation and displacement of the reference.

  • start_at_origin (bool, optional) – If True, set initial position at the origin. By default True.

  • new_traj_id (str | None)

Returns:

Output trajectory in the lab frame of reference.

Return type:

Trajectory

add_polar_offset(traj, radius, angle)

Adds an offset given a point in polar coordinates.

Parameters:
  • radius (float) – Point’s radius.

  • angle (float) – Point’s angle.

  • traj (Trajectory)

Raises:

TypeError – If the trajectory is not 2 dimensional.

Return type:

None

exp_convolutional_filter(traj, gamma, new_traj_id=None)

Returns a smoothed version of the trajectory traj by taking a weighted average over past values.

Parameters:
  • traj (Trajectory) – Input trajectory.

  • gamma (float) – Inverse of the characteristic time window of the average.

  • new_traj_id (str | None) – New trajectory ID. By default None.

Returns:

Smoothed trajectory.

Return type:

Trajectory

exp_moving_average_filter(traj, alpha, tau=None, new_traj_id=None)

Returns a smoothed version of the trajectory traj using the exponential moving average defined as

s(0) = x(0) s(t_n) = alpha x(t_{n-1}) + (1-alpha) s(t_{n-1})

If the the trajectory times are non-uniform then tau must be provided. The non-uniform time filter is computed as

s(0) = x(0) alpha(t_n) = 1 - exp(-(t_n - t_{n-1}) / tau)) s(t_n) = alpha(t_n) x(t_{n-1}) + (1-alpha(t_n)) s(t_{n-1})

Parameters:
  • traj (Trajectory) – Input trajectory.

  • alpha (float) – Exponential smoothing paramter.

  • tau (float [optional, default=None]) – Smoothing factor that must be provided if the trajectory timeseries is non-uniform.

  • new_traj_id (str | None) – New trajectory ID. By default None.

Returns:

Smoothed trajectory.

Return type:

Trajectory

resample(traj, new_dt=None, new_t=None, new_traj_id=None, order=1)

Resamples a trajectory to a new dt or a new array of time.

One of new_dt or new_t must be specified.

Parameters:
  • traj (Trajectory) – Input trajectory.

  • new_dt (float | None) – New dt. By default None.

  • new_t (Collection[float] | None) – New sample rate or array of time. By default None.

  • new_traj_id (str | None) – New trajectory ID. By default None.

  • order (int, optional) – How many points to use for the interpolation of each value. By default 2.

Returns:

Output trajectory.

Return type:

Trajectory

Raises:
  • ValueError – If neither new_dt nor new_t is specified.

  • ValueError – If both new_dt and new_t are specified.

rotate_2d(traj, angle)

Rotates a trajectory around the center coordinates [0,0]

Parameters:
  • angle (float) – Angle in radians to rotate the trajectory.

  • traj (Trajectory)

Return type:

None

rotate_3d(traj, angle, vector)

Rotates a trajectory around a given vector.

Parameters:
  • vector (Collection[float]) – Vector to rotate the trajectory around.

  • angle (float) – Angle in radians to rotate the trajectory.

  • traj (Trajectory)

Raises:
  • TypeError – If the trajectory is not 3 dimensional.

  • ValueError – If the vector has shape different than (3,).

Return type:

None

subsample(traj, step=1, new_traj_id=None)

Sample the trajectory traj by removing evenly spaced points according to step.

Parameters:
  • traj (Trajectory) – Input trajectory.

  • step (int, optional) – Number of sample points or period. By default 1.

  • new_traj_id (str | None) – New trajectory ID. By default None.

Returns:

Output trajectory.

Return type:

Trajectory