Features¶
features
¶
Feature export for ML pipelines.
Composes the per-frame motion descriptors from :mod:pybvh.analysis
(rotations, root position, velocities, foot contacts) into a single flat
(F, D) array, plus the column-layout helper that describes it.
feature_array_layout(*, num_joints: int, num_feet: int = 0, representation: str = '6d', include_root_pos: bool = True, include_velocities: bool = False, include_foot_contacts: bool = False) -> dict[str, slice]
¶
Column layout of the array returned by :func:to_feature_array.
Returns a dict mapping block name to column slice so callers can
write feat[:, layout['rotations']] without counting columns.
Pure function — no :class:~pybvh.bvh.Bvh required; useful for
model-shape setup before any data is loaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_joints
|
int
|
Number of joints (excluding end sites). Used for both the rotation and velocity blocks: velocities are per-joint (not per-node), aligning with the rotation block's joint axis. |
required |
num_feet
|
int
|
Number of foot joints for contact detection. Required (>0)
when |
0
|
representation
|
str
|
Rotation representation: |
'6d'
|
include_root_pos
|
bool
|
Mirror the flags of :func: |
True
|
include_velocities
|
bool
|
Mirror the flags of :func: |
True
|
include_foot_contacts
|
bool
|
Mirror the flags of :func: |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Notes
Within the rotations and velocities blocks joints are in
skeleton hierarchy order — the file's declaration order, i.e.
Bvh.joint_names, end sites excluded — not alphabetical. For
representation='euler' the three columns per joint follow that
joint's own channel order from the file (which can differ per
joint and between files), not a fixed XYZ; every other
representation is order-independent. 'rotmat' flattens each 3×3
row-major (C order).
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
to_feature_array(bvh: Bvh, representation: str = '6d', include_root_pos: bool = True, include_velocities: bool = False, include_foot_contacts: bool = False, centered: str = 'world', foot_joints: list[str] | None = None, stencil: str = 'central', pad: str = 'edge') -> npt.NDArray[np.float64]
¶
Export motion as a single flat feature array for ML pipelines.
Composes root position, joint rotations, velocities, and foot
contacts into a single (F, D) array ready for model input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bvh
|
Bvh
|
Input motion. |
required |
representation
|
str
|
Rotation representation: |
'6d'
|
include_root_pos
|
bool
|
If True (default), include root position (3 columns). |
True
|
include_velocities
|
bool
|
If True, include joint velocity features, in units per
frame — deliberately not :func: |
False
|
include_foot_contacts
|
bool
|
If True, include foot contact labels. Contacts are always
detected in world frame (see :func: |
False
|
centered
|
str
|
Coordinate centering mode (default |
'world'
|
foot_joints
|
list of str or None
|
Foot joints for contact detection. Only used when
|
None
|
stencil
|
optional
|
Only affect output when |
'central'
|
pad
|
optional
|
Only affect output when |
'central'
|
Returns:
| Type | Description |
|---|---|
ndarray, shape (F, D), (F-1, D), or (F-2, D)
|
See :func: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |