anatomy
Anatomical definitions for the fly body, including enums for categorical options for model configuration, classes representing body features, and constants specifying anatomical structures and nomenclature.
Attributes:
| Name | Type | Description |
|---|---|---|
SIDES |
list[str]
|
Alias for ["l", "r"]. |
LEGS |
list[str]
|
List of leg position identifiers (e.g., "lf" for left front leg). |
BODY_POSITIONS |
list[str]
|
List of body position identifiers including |
LEG_LINKS |
list[str]
|
List of segment names in the leg kinematic chain (i.e., coxa, trochanterfemur, femur, tibia, tarsus1, ..., tarsus5). Note that trochanter and femur are fused. |
ANTENNA_LINKS |
list[str]
|
Alias for ["pedicel", "funiculus", "arista"]. |
PROBOSCIS_LINKS |
list[str]
|
Alias for ["rostrum", "haustellum"]. |
ABDOMEN_LINKS |
list[str]
|
List of segment names in the abdomen kinematic chain (i.e., abdomen12, abdomen3, abdomen4, abdomen5, abdomen6). Note that abdomen1 and abdomen2 are fused. |
PASSIVE_TARSAL_LINKS |
list[str]
|
List of tarsal segments that are unactuated in the real fly and therefore often kept passive in simulation (i.e., tarsus 2-to-3, 3-to-4, and 4-to-5). |
ALL_CONNECTED_SEGMENT_PAIRS |
list[tuple[str, str]]
|
List of all parent-child pairs of body segments that are connected by anatomical joints. |
ALL_SEGMENT_NAMES |
list[str]
|
List of all body segment names. |
ActuatedDOFPreset
¶
Bases: Enum
Presets for which joint DoFs present in a skeleton should be actuated. The exact list of DoFs therefore depends on which ones are present in the skeleton.
Attributes:
| Name | Type | Description |
|---|---|---|
ALL |
Every DoF that is present in the skeleton. |
|
LEGS_ONLY |
Only leg DoFs in the skeleton. |
|
LEGS_ACTIVE_ONLY |
Only active leg DoFs in the skeleton (i.e., excluding passive tarsal links). |
Source code in src/flygym/anatomy.py
filter(jointdofs)
¶
Filter given joint DoFs according to the preset.
Source code in src/flygym/anatomy.py
AnatomicalJoint
dataclass
¶
Represents an anatomical joint connecting two body segments (e.g., thorax to
left-front coxa). This can encompass multiple rotational DoFs (e.g., pitch, roll,
and yaw for a ball joint), which are specified by the axes attribute.
Source code in src/flygym/anatomy.py
iter_dofs(axis_order)
¶
Iterate through the JointDOFs at to this anatomical joint in the specified
axis order.
Source code in src/flygym/anatomy.py
AxesSet
¶
Bases: set[RotationAxis]
Set of rotation axes with automatic RotationAxis conversion. Useful for specifying which rotational DoFs are present at an anatomical joint.
Source code in src/flygym/anatomy.py
AxisOrder
¶
Bases: Enum
An enum specifying the order by which one-axis DoFs are chained together at anatomical joints with multiple DoFs.
This is important because 3D rotations do not commute under Euler angle representations. Keep this consistent with your data (e.g., axis order used for inverse kinematics on experimental recordings).
Special case: sometimes we might not care about the within-joint DoF order (e.g.
when iterate over the skeleton to configure body segments but not joints). In this
case, we can use DONTCARE (which aliases to PITCH_ROLL_YAW) to make our
intention explicit.
Source code in src/flygym/anatomy.py
BodySegment
dataclass
¶
Represents a body segment in the fly anatomy.
See flygym.anatomy.ALL_SEGMENT_NAMES for all possible names.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier for the body segment following the pattern |
pos |
str
|
Body location (e.g., |
link |
str
|
Name of the segment in the kinematic chain (e.g., |
Source code in src/flygym/anatomy.py
ContactBodiesPreset
¶
Bases: Enum
Presets for which body segments should be able to collide with the ground.
This is useful because excluding contacts that we do not care about (e.g. wing-to-ground) can speed up simulation.
Attributes:
| Name | Type | Description |
|---|---|---|
ALL |
All body segments have ground contact. |
|
LEGS_THORAX_ABDOMEN_HEAD |
Legs, thorax, abdomen, and head segments (i.e., the big ones). This is a good default choice for most purposes. |
|
LEGS_ONLY |
All leg segments. |
|
TIBIA_TARSUS_ONLY |
Only tibia and tarsus segments (i.e., the most distal leg segments). |
Source code in src/flygym/anatomy.py
to_body_segments_list()
¶
Return the list of BodySegment objects defined by this preset.
Source code in src/flygym/anatomy.py
JointDOF
dataclass
¶
A single rotational degree of freedom in an anatomical joint.
For example, the thorax-coxa joint of a leg is an AnatomicalJoint. It has 3
JointDOFs corresponding to the three rotation axes as it is a ball joint.
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
BodySegment
|
Parent body segment. |
child |
BodySegment
|
Child body segment. |
axis |
RotationAxis
|
Rotation axis for this DOF. |
name |
str
|
Unique identifier for the joint DOF following the pattern
|
Source code in src/flygym/anatomy.py
name
property
¶
Unique name following the pattern {parent}-{child}-{axis}.
from_name(name)
classmethod
¶
Create a JointDOF instance by parsing a name string.
Source code in src/flygym/anatomy.py
JointPreset
¶
Bases: Enum
Presets for which rotational DoFs are present at which anatomical joints.
This is useful because excluding DoFs that we do not care about (e.g., wing joints in walking tasks) can speed up simulation and simplify control.
Attributes:
| Name | Type | Description |
|---|---|---|
ALL_POSSIBLE |
All theoretically possible joint DoFs (i.e., 3 DoFs per anatomical joint). |
|
ALL_BIOLOGICAL |
All biologically plausible joint DoFs (e.g., some leg joints do not have all three DoFs). |
|
LEGS_ONLY |
|
|
LEGS_ACTIVE_ONLY |
|
Source code in src/flygym/anatomy.py
to_joint_list()
¶
Return the list of AnatomicalJoint objects defined by this preset.
Source code in src/flygym/anatomy.py
RotationAxis
¶
Bases: Enum
Enumeration of rotation axes for joints.
Supports pitch (P), roll (R), and yaw (Y) rotations with both full names and single-letter aliases.
Source code in src/flygym/anatomy.py
Skeleton
¶
Fly skeleton defining joint structure and degrees of freedom.
The skeleton manages the hierarchical structure of body segments and their connections, generating appropriate DoFs based on axis ordering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis_order
|
AxisOrder | list[RotationAxis | str]
|
Order of rotation axes (e.g., |
required |
joint_preset
|
JointPreset | str | None
|
Preset defining which joints to include. Either this or |
None
|
anatomical_joints
|
list[AnatomicalJoint] | None
|
Explicit list of |
None
|
Source code in src/flygym/anatomy.py
get_actuated_dofs_from_preset(preset)
¶
Given a preset of actuated DoFs, return an explicit list of JointDOF
objects that are actuated according to the preset.
Source code in src/flygym/anatomy.py
get_tree()
¶
Construct a tree data structure representing the skeleton.
Source code in src/flygym/anatomy.py
iter_jointdofs(root='c_thorax')
¶
Iterate through joint DOFs in depth-first order starting from the root.