Muscle#
- class Muscle(
- recruitment_thresholds,
- radius__mm=6.91,
- length__mm=30.0,
- fiber_density__fibers_per_mm2=400,
- max_innervation_area_to_total_muscle_area__ratio=1 / 4,
- mean_conduction_velocity__m_s=4.2,
- mean_fiber_length__mm=31.7,
- var_fiber_length__mm=2.8,
- radius_bone__mm=0,
- fat_thickness__mm=0.3,
- skin_thickness__mm=1.29,
- muscle_conductivity_radial__S_m=0.09,
- muscle_conductivity_longitudinal__S_m=0.4,
- fat_conductivity__S_m=4.7e-2,
- skin_conductivity__S_m=4.88e-4,
- grid_resolution=256,
- autorun=False,
Bases:
object
A muscle model based on the cylindrical description of the volume conductor by Farina et al. 2004 [1] and the motor unit distribution by Konstantin et al. 2020 [2].
Note
All default values are set to simulate the First Dorsal Interosseous (FDI) muscle. Values are pulled from the literature.
- Parameters:
recruitment_thresholds (
RECRUITMENT_THRESHOLDS__ARRAY
) – Array of recruitment thresholds for each motor unit (see myogen.simulator.generate_mu_recruitment_thresholds). Values range from 0 to 1 with the largest motor units having thresholds near 1.radius__mm (
float
, default6.91
) – Radius of the muscle cross-section in millimeters. Default is set to 6.91 mm as determined by Jacobson et al. 1992 [3].length__mm (
float
, default30.0
) – Length of the muscle in millimeters. Default is set to 30.0 mm as determined by no one.fiber_density__fibers_per_mm2 (
float
, default400
) – Density of muscle fibers per square millimeter. Default is set to 400 fibers/mm² as determined by no one.max_innervation_area_to_total_muscle_area__ratio (
float
, default0.25
) – Ratio defining the maximum territory size relative to total muscle area. Default is set to 0.25 as determined by no one but it is a good starting point. A value of 0.25 means the largest motor unit can innervate up to 25% of the total muscle cross-sectional area. Must be in range (0, 1].mean_conduction_velocity__m_s (
float
, default4.2
) – Mean conduction velocity in m/s. Default is set to 4.2 m/s as determined by Nishizono et al. 1990 [4]. Experimental range determined by Nishizono et al. 1990 [4] is between 3.2 and 5.0 m/s.mean_fiber_length__mm (
float
, default31.7
) – Mean fiber length in mm. Default is set to 31.7 mm as determined by Jacobson et al. 1992 [3] (Table 1).var_fiber_length__mm (
float
, default2.8
) – Fiber length variance in mm. Default is set to 2.8 mm as determined by Jacobson et al. 1992 [3] (Table 1).radius_bone__mm (
float
, default0
) – Bone radius in mm. Default is set to 0 mm as the FDI muscle doesn’t surround a bone.fat_thickness__mm (
float
, default0.3
) – Fat thickness in mm. Default is set to 0.3 mm as determined by Störchle et al. 2018 [5].skin_thickness__mm (
float
, default1.29
) – Skin thickness in mm. Default is set to the male skin thickness average of 1.29 mm as determined by Brodar 1960 [6].muscle_conductivity_radial__S_m (
float
, default0.09
) – Muscle conductivity in radial direction. Default is set to 0.09 S/m as determined by Botelho et al. 2019 [7] (Table 1).muscle_conductivity_longitudinal__S_m (
float
, default0.4
) – Muscle conductivity in longitudinal direction. Default is set to 0.4 S/m as determined by Botelho et al. 2019 [7] (Table 1).fat_conductivity__S_m (
float
, default4.7E-2
) – Fat conductivity. Default is set to 4.7E-2 S/m as determined by Botelho et al. 2019 [7] (Table 1).skin_conductivity__S_m (
float
, default4.88E-4
) – Skin conductivity. Default is set to 4.88E-4 S/m as determined by Botelho et al. 2019 [7] (Table 1).grid_resolution (
int
, default256
) – Resolution of the computational grid used for innervation the muscle. Higher values provide more accurate spatial distribution but increase computational cost. Default is set to 256.autorun (
bool
, defaultFalse
) – If True, automatically executes the complete muscle simulation pipeline: innervation distribution, muscle fiber generation, and fiber-to-motor unit assignment. If False, these steps must be called manually.
- innervation_center_positions__mm#
Motor unit innervation center positions [x, y] in mm. Available after distribute_innervation_centers().
- Type:
- muscle_fiber_centers__mm#
Muscle fiber center positions [x, y] in mm. Available after generate_muscle_fiber_centers().
- Type:
- muscle_fiber_diameters__mm#
Muscle fiber diameters in mm. Available after _generate_fiber_properties().
- Type:
- muscle_fiber_conduction_velocities__mm_per_s#
Muscle fiber conduction velocities in mm/s. Available after _generate_fiber_properties().
- Type:
- assignment#
Motor unit assignment for each muscle fiber. Available after assign_mfs2mns().
- Type:
- number_of_muscle_fibers#
Total number of muscle fibers. Available after generate_muscle_fiber_centers().
- Type:
- muscle_border__mm#
Muscle boundary points for visualization. Available after generate_muscle_fiber_centers().
- Type:
- resulting_number_of_innervated_fibers#
Actual number of fibers per motor unit. Available after assign_mfs2mns().
- Type:
- resulting_innervation_areas__mm2#
Actual innervation areas per motor unit in mm². Available after assign_mfs2mns().
- Type:
- Raises:
ValueError – If max_innervation_area_to_total_muscle_area__ratio is not in (0, 1].
- Parameters:
recruitment_thresholds (Annotated[ndarray[tuple[int, ...], dtype[floating]], beartype.vale.Is[lambda x: x.ndim == 1]])
radius__mm (float)
length__mm (float)
fiber_density__fibers_per_mm2 (float)
max_innervation_area_to_total_muscle_area__ratio (float)
mean_conduction_velocity__m_s (float)
mean_fiber_length__mm (float)
var_fiber_length__mm (float)
radius_bone__mm (float)
fat_thickness__mm (float)
skin_thickness__mm (float)
muscle_conductivity_radial__S_m (float)
muscle_conductivity_longitudinal__S_m (float)
fat_conductivity__S_m (float)
skin_conductivity__S_m (float)
grid_resolution (int)
autorun (bool)
References
Methods
Assign muscle fibers to motor neurons using biologically realistic principles.
Distribute innervation center positions using the fast marching method.
Generate muscle fiber center positions using a pre-computed Voronoi distribution.
Get the muscle fiber positions assigned to a specific motor unit.
Attributes
Motor unit assignment for each muscle fiber.
Motor unit innervation center positions [x, y] in mm.
Muscle boundary points for visualization.
Muscle fiber center positions [x, y] in mm.
Muscle fiber conduction velocities in mm/s.
Muscle fiber diameters in mm.
Total number of muscle fibers.
Motor unit recruitment thresholds.
Calculate the actual innervation areas for each motor unit based on assigned fibers.
Calculate the actual number of muscle fibers assigned to each motor unit.
- distribute_innervation_centers()[source]#
Distribute innervation center positions using the fast marching method.
This method implements an optimal packing algorithm to distribute motor unit innervation centers within the circular muscle cross-section. The algorithm uses the Fast Marching Method to ensure that each new innervation center is placed at the location that maximizes the minimum distance to all previously placed centers.
Results are stored in the innervation_center_positions property after execution.
Notes
This method must be called before generate_muscle_fiber_centers() and assign_mfs2mns(). The resulting distribution approximates the optimal packing problem for circles, leading to realistic motor unit territory arrangements.
- Return type:
None
- generate_muscle_fiber_centers()[source]#
Generate muscle fiber center positions using a pre-computed Voronoi distribution.
This method creates the spatial distribution of muscle fiber centers within the circular muscle cross-section. The distribution is based on a Voronoi tessellation pattern that mimics the natural packing of muscle fibers observed in histological studies.
- Results are stored in the following properties after execution:
mf_centers: Array of shape (n_fibers, 2) with fiber positions [x, y] in mm
number_of_muscle_fibers: Total number of muscle fibers
muscle_border: Array of border points for visualization
Notes
This method should be called after distribute_innervation_centers() and before assign_mfs2mns(). The Voronoi-based distribution provides more realistic fiber spacing compared to regular grids or purely random distributions.
The reference dataset (‘voronoi_pi1e5.csv’) contains 100,000 pre-computed Voronoi cell centers optimized for circular domains, ensuring efficient and consistent fiber distributions across simulations.
- Return type:
None
- assign_mfs2mns(n_neighbours=3, conf=0.999)[source]#
Assign muscle fibers to motor neurons using biologically realistic principles.
This method implements an assignment algorithm that balances multiple biological constraints:
Proximity: Fibers closer to innervation centers are more likely to be assigned
Territory size: Each motor unit has a target number of fibers based on its size
Self-avoidance: Neighboring fibers avoid belonging to the same motor unit
Gaussian territories: Fiber territories follow roughly Gaussian distributions
The assignment uses a probabilistic approach where each fiber is assigned based on the posterior probability computed from prior probabilities (target fiber numbers) and likelihoods (spatial clustering with Gaussian territories).
- Parameters:
n_neighbours (
int
, default3
) – Number of neighboring fibers to consider for self-avoiding phenomena. Higher values increase intermingling between motor units but may slow computation. Typical range: 2-5.conf (
float
, default0.999
) – Confidence interval that defines the relationship between innervation area and Gaussian distribution variance. Higher values create tighter, more compact territories. Should be between 0.9 and 0.999.execution. (Results are stored in the assignment property after)
- Raises:
ValueError – If innervation_center_positions is None. Call distribute_innervation_centers() first, or if muscle fiber centers are not available.
- Return type:
None
Notes
The algorithm compensates for out-of-muscle effects by calculating how much of each motor unit’s Gaussian distribution falls outside the circular muscle boundary and adjusting the in-muscle probabilities accordingly.
The self-avoidance mechanism promotes realistic intermingling by reducing the probability of assigning a fiber to a motor unit if its neighbors are already assigned to that unit.
- resulting_fiber_assignment(mu)[source]#
Get the muscle fiber positions assigned to a specific motor unit.
- Parameters:
mu (
int
) – Motor unit index (0-based). Must be less than the total number of motor units.- Returns:
Array of shape (n_assigned_fibers, 2) containing the [x, y] coordinates (in mm) of all muscle fibers assigned to the specified motor unit. If no fibers are assigned to the motor unit, returns an empty array.
- Return type:
- Raises:
IndexError – If mu is outside the valid range [0, n_motor_units-1].
ValueError – If the muscle fiber assignment has not been completed yet.
Examples
>>> fiber_positions = muscle.resulting_fiber_assignment(0) >>> print(f"Motor unit 0 has {len(fiber_positions)} fibers") >>> print(f"First fiber position: x={fiber_positions[0,0]:.2f}, y={fiber_positions[0,1]:.2f}")
Notes
This method should only be called after assign_mfs2mns() has been executed. The returned coordinates are in the muscle’s coordinate system with the origin at the muscle center.
- property resulting_number_of_innervated_fibers: ndarray#
Calculate the actual number of muscle fibers assigned to each motor unit.
This property returns the final fiber counts after the assignment process, which may differ slightly from the desired counts due to the stochastic assignment algorithm and discrete fiber distribution.
- Returns:
Array of length n_motor_units where each element represents the actual number of muscle fibers assigned to the corresponding motor unit. The sum of all elements equals the total number of muscle fibers.
- Return type:
- Raises:
ValueError – If muscle fiber assignment has not been completed yet.
Examples
>>> actual_counts = muscle.resulting_number_of_innervated_fibers >>> desired_counts = muscle.desired_number_of_innervated_fibers >>> print(f"Motor unit 0: desired {desired_counts[0]}, actual {actual_counts[0]}")
Notes
This property can be used to assess how well the assignment algorithm achieved the target fiber distribution. Large deviations may indicate the need to adjust assignment parameters or increase grid resolution.
- property resulting_innervation_areas__mm2: ndarray#
Calculate the actual innervation areas for each motor unit based on assigned fibers.
The innervation area is computed as the area of a circle that encompasses all muscle fibers assigned to a motor unit, centered on the motor unit’s innervation center. This provides a measure of the spatial extent of each motor unit territory.
- Returns:
Array of length n_motor_units containing the innervation area (in mm²) for each motor unit. Areas are calculated as π × r², where r is the maximum distance from the innervation center to any assigned fiber.
- Return type:
- Raises:
ValueError – If innervation_center_positions is None or assignment has not been completed.
Examples
>>> actual_areas = muscle.resulting_innervation_areas__mm2 >>> desired_areas = muscle.desired_innervation_areas__mm2 >>> for i, (actual, desired) in enumerate(zip(actual_areas, desired_areas)): ... print(f"MU {i}: desired {desired:.2f} mm², actual {actual:.2f} mm²")
Notes
The resulting areas may differ from desired areas due to the discrete nature of fiber assignment and the constraint of the circular muscle boundary. Motor units near the muscle periphery may have smaller actual areas than desired due to boundary effects.
- property innervation_center_positions__mm: ndarray#
Motor unit innervation center positions [x, y] in mm.
- Returns:
Array of shape (n_motor_units, 2) containing [x, y] coordinates in mm.
- Return type:
- Raises:
ValueError – If innervation centers have not been computed yet.
- property muscle_fiber_centers__mm: ndarray#
Muscle fiber center positions [x, y] in mm.
- Returns:
Array of shape (n_fibers, 2) containing [x, y] coordinates in mm.
- Return type:
- Raises:
ValueError – If muscle fiber centers have not been computed yet.
- property muscle_fiber_diameters__mm: ndarray#
Muscle fiber diameters in mm.
- Returns:
Array of muscle fiber diameters in mm.
- Return type:
- Raises:
ValueError – If fiber properties have not been computed yet.
- property muscle_fiber_conduction_velocities__mm_per_s: ndarray#
Muscle fiber conduction velocities in mm/s.
- Returns:
Array of muscle fiber conduction velocities in mm/s.
- Return type:
- Raises:
ValueError – If fiber properties have not been computed yet.
- property assignment: ndarray#
Motor unit assignment for each muscle fiber.
- Returns:
Array where each element indicates the motor unit index (0 to n_motor_units-1) assigned to that fiber.
- Return type:
- Raises:
ValueError – If muscle fiber assignment has not been completed yet.
- property number_of_muscle_fibers: int#
Total number of muscle fibers.
- Returns:
Total number of muscle fibers.
- Return type:
- Raises:
ValueError – If muscle fiber centers have not been computed yet.
- property muscle_border__mm: ndarray#
Muscle boundary points for visualization.
- Returns:
Array of boundary points for the circular muscle cross-section.
- Return type:
- Raises:
ValueError – If muscle fiber centers have not been computed yet.