snake.core.handlers.motion.utils#

Utility functions for motion generation.

Module Contents#

Functions#

motion_generator

Generate a motion trajectory.

rotation

Create an array with a 4 dimensional rotation matrix.

rotation2D

Create an array with a 2D rotation matrix.

rotation3d

Create an array with a 3 dimensional rotation matrix.

translation

Create an array with a translation matrix.

apply_rotation_at_center

Apply the rotation at the center of the array.

add_motion

Add motion to a base array.

Data#

API#

snake.core.handlers.motion.utils.motion_generator(n_frames: int, t_std: tuple[float, float, float], r_std: tuple[float, float, float], time_res: float, rng: numpy.random.Generator) numpy.ndarray[source]#

Generate a motion trajectory.

Parameters:
  • n_frames – Number of frames.

  • t_std – Translation standard deviation, in mm/s

  • r_std – Rotation standard deviation, in radians/s.

  • time_res – Time resolution, in seconds.

  • rng – Random number generator.

Returns:

Cumulative Motion trajectory.

Return type:

np.ndarray

Notes

The motion is generated by drawing from a normal distribution with standard deviation for the 6 motion parameters: 3 rotation (x,y,z) and 3 translations. Then the cumulative motion is computed by summing the motion at each frame, to derive the absolute displacement compared to the base reference.

snake.core.handlers.motion.utils.rotation(x: float = 0.0, y: float = 0.0, z: float = 0.0, dtype: numpy.typing.DTypeLike = 'float32') numpy.typing.NDArray[source]#

Create an array with a 4 dimensional rotation matrix.

Parameters:
  • x (scalar) – Rotation around the origin (in rad).

  • y (scalar) – Rotation around the origin (in rad).

  • z (scalar) – Rotation around the origin (in rad).

Returns:

r – The rotation matrix.

Return type:

array, shape = (4, 4)

snake.core.handlers.motion.utils.rotation2D(angle: float, dtype: numpy.typing.DTypeLike = 'float32') numpy.typing.NDArray[source]#

Create an array with a 2D rotation matrix.

snake.core.handlers.motion.utils.rotation3d(x: float = 0.0, y: float = 0.0, z: float = 0.0, dtype: numpy.typing.DTypeLike = 'float32') numpy.typing.NDArray[source]#

Create an array with a 3 dimensional rotation matrix.

Parameters:
  • x (scalar) – Rotation around each axis (in rad).

  • y (scalar) – Rotation around each axis (in rad).

  • z (scalar) – Rotation around each axis (in rad).

Returns:

r – The rotation matrix.

Return type:

array, shape = (3, 3)

snake.core.handlers.motion.utils.translation(x: float = 0.0, y: float = 0.0, z: float = 0.0, dtype: numpy.typing.DTypeLike = 'float32') numpy.ndarray[source]#

Create an array with a translation matrix.

Parameters:
  • x (scalar) – Translation parameters.

  • y (scalar) – Translation parameters.

  • z (scalar) – Translation parameters.

Returns:

m – The translation matrix.

Return type:

array, shape = (4, 4)

snake.core.handlers.motion.utils.apply_rotation_at_center(data: numpy.typing.NDArray, angles: tuple[float, float, float]) numpy.typing.NDArray[source]#

Apply the rotation at the center of the array.

snake.core.handlers.motion.utils.apply_shift = 'partial(...)'#
snake.core.handlers.motion.utils.add_motion(data: numpy.typing.NDArray[numpy.complexfloating] | numpy.typing.NDArray[numpy.floating], motion_params: numpy.typing.NDArray[numpy.floating], idx: int = 0) numpy.ndarray[source]#

Add motion to a base array.

Parameters:
  • data (np.ndarray) – The data to which motion is added.

  • motion (np.ndarray) – The N_frames x 6 motion trajectory.

  • frame_idx (int) – The frame index used to compute the motion at that frame.

Returns:

The data with motion added.

Return type:

np.ndarray