Skip to content

[Bug] min_radial_dist unit mismatch in MotorUnitSim.calc_sfaps() — µm value used in mm context #9

@veylantis

Description

@veylantis

Description

In motor_unit_sim.py, the default min_radial_dist converts fiber diameter to micrometers, but the result is then compared against radial distances in millimeters:

# motor_unit_sim.py, line ~274:
min_radial_dist = float(
    np.mean(self.muscle_fiber_diameters__mm) * 1000
)  # Convert to micrometers

However, radial_distance (line ~345) is computed from muscle_fiber_centers__mm and electrode_positions, both in mm. The clamp comparison if radial_distance < min_radial_dist then mixes µm with mm.

For a typical muscle model with mean fiber diameter ~0.0525 mm:

  • min_radial_dist = 0.0525 × 1000 = 52.5 mm
  • Muscle radius ≈ 18 mm → max fiber-to-electrode distance ≈ 36 mm
  • All fibers get clamped to r = 52.5 mm

Impact

  • All fibers appear equidistant from the electrode in the XY plane
  • Moving the electrode in X/Y has zero effect on the MUAP waveform for the same motor unit (xcorr = 1.000000)
  • Only Z-axis displacement affects the output (Z is not clamped)
  • MUAP PtP amplitudes are suppressed (~0.15 mV vs ~5.7 mV at the corrected scale)

Suggested Fix

Remove the * 1000 factor so min_radial_dist stays in mm (matching the coordinate system):

 if min_radial_dist is None:
     min_radial_dist = float(
-        np.mean(self.muscle_fiber_diameters__mm) * 1000
-    )  # Convert to micrometers
+        np.mean(self.muscle_fiber_diameters__mm)
+    )  # Mean fiber diameter in mm (prevents 1/r singularity)

Version

MyoGen v0.9.0 (current main)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions