unilab.tasks.motion_tracking.common.motion_loader

Shared motion loading and sampling for motion-tracking tasks.

Functions

compute_frame_blend(times, duration, ...)

Compute frame indices and blend weights for interpolation.

compute_motion_velocities(base_poss, ...)

Numerically differentiate a trajectory into base/dof velocities.

ensure_quat_continuity(q)

Flip quaternion signs in a time sequence to keep adjacent dots positive.

interpolate_motion(base_poss_input, ...)

Resample a root+joint trajectory from input_fps to output_fps.

quat_slerp(q1, q2, t)

Spherical linear interpolation between two quaternions (wxyz format).

Classes

InterpolatedMotion

Root/joint trajectory resampled to the output frame rate.

MotionData

Container for motion data at specific frame(s).

MotionLoader

Loads and provides access to motion data from NPZ files.

class unilab.tasks.motion_tracking.common.motion_loader.MotionData[source]

Bases: object

Container for motion data at specific frame(s).

Parameters:
joint_pos: Tensor
joint_vel: Tensor
body_pos_w: Tensor
body_quat_w: Tensor
body_lin_vel_w: Tensor
body_ang_vel_w: Tensor
__init__(joint_pos, joint_vel, body_pos_w, body_quat_w, body_lin_vel_w, body_ang_vel_w)
Parameters:
unilab.tasks.motion_tracking.common.motion_loader.quat_slerp(q1, q2, t)[source]

Spherical linear interpolation between two quaternions (wxyz format).

The computation runs in the input dtype; pass float64 arrays for a float64 interpolation path.

Parameters:
Return type:

ndarray

unilab.tasks.motion_tracking.common.motion_loader.ensure_quat_continuity(q)[source]

Flip quaternion signs in a time sequence to keep adjacent dots positive.

Parameters:

q (ndarray)

Return type:

ndarray

class unilab.tasks.motion_tracking.common.motion_loader.InterpolatedMotion[source]

Bases: object

Root/joint trajectory resampled to the output frame rate.

Parameters:
output_frames: int
base_poss: ndarray
base_rots: ndarray
dof_poss: ndarray
base_lin_vels: ndarray
base_ang_vels: ndarray
dof_vels: ndarray
__init__(output_frames, base_poss, base_rots, dof_poss, base_lin_vels, base_ang_vels, dof_vels)
Parameters:
unilab.tasks.motion_tracking.common.motion_loader.compute_motion_velocities(base_poss, base_rots, dof_poss, dt)[source]

Numerically differentiate a trajectory into base/dof velocities.

Parameters:
Return type:

tuple[ndarray, ndarray, ndarray]

unilab.tasks.motion_tracking.common.motion_loader.compute_frame_blend(times, duration, input_frames)[source]

Compute frame indices and blend weights for interpolation.

Parameters:
Return type:

tuple[ndarray, ndarray, ndarray]

unilab.tasks.motion_tracking.common.motion_loader.interpolate_motion(base_poss_input, base_rots_input, dof_poss_input, *, input_fps, output_fps)[source]

Resample a root+joint trajectory from input_fps to output_fps.

Positions and joint angles are linearly interpolated, root quaternions (wxyz) use slerp, and velocities are computed by numerical differentiation at the output rate.

Parameters:
Return type:

InterpolatedMotion

class unilab.tasks.motion_tracking.common.motion_loader.MotionLoader[source]

Bases: object

Loads and provides access to motion data from NPZ files.

Parameters:
__init__(motion_file, body_indices=None)[source]

Initialize motion loader.

Parameters:
  • motion_file (str | Sequence[str]) – Path to one NPZ file, or a sequence of NPZ files

  • body_indices (Sequence[int] | None) – Optional indices into the NPZ body axis. The exported motion files currently keep MuJoCo body-id layout, so these indices are expected to follow that convention.

get_clip_indices(frame_idx)[source]

Map global frame indices to clip indices.

Parameters:

frame_idx (ndarray)

Return type:

ndarray

motion_features_torch(device)[source]

Return the immutable motion feature table on the requested device.

NPZ parsing and validation remain inside this cold-path leaf. Runtime consumers receive one contiguous float32 table with columns packed in the documented motion-feature order rather than mutable NumPy arrays.

Parameters:

device (str | device)

Return type:

Tensor

clip_offsets_torch(device)[source]

Return immutable clip start frames as a device-resident Torch table.

Parameters:

device (str | device)

Return type:

Tensor

clip_end_frames_torch(device)[source]

Return immutable clip end frames as a device-resident Torch table.

Parameters:

device (str | device)

Return type:

Tensor