snake.core.handlers.motion.utils
#
Utility functions for motion generation.
Module Contents#
Functions#
Generate a motion trajectory. |
|
Create an array with a 4 dimensional rotation matrix. |
|
Create an array with a 2D rotation matrix. |
|
Create an array with a 3 dimensional rotation matrix. |
|
Create an array with a translation matrix. |
|
Apply the rotation at the center of the array. |
|
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