def test_fatigue(): motor_unit_count = 120 f = Fibers(motor_unit_count) # With zero inputs fatigue shouldn't change f = Fibers(motor_unit_count) ctf_before = copy(f.current_peak_forces) for i in range(100): f.step(np.zeros(motor_unit_count), 1.0) ctf_after = f.current_peak_forces assert np.equal(ctf_before, ctf_after).all() # With max input all ctfs should decrease f = Fibers(motor_unit_count) ctf_before = copy(f.current_peak_forces) max_input = 67.0 for i in range(100): f.step(np.full(motor_unit_count, max_input), 1.0) ctf_after = f.current_peak_forces assert np.greater(ctf_before, ctf_after).all() # With fatigue off no ctfs should change f = Fibers(motor_unit_count, apply_fatigue=False) max_input = 67.0 for i in range(100): f.step(np.full(motor_unit_count, max_input), 1.0) ctf_after = f.current_peak_forces assert np.equal(ctf_before, ctf_after).all()
def test_init(): # Missing arguments with pytest.raises(TypeError): f = Fibers() motor_unit_count = 120 f = Fibers(motor_unit_count) assert f.motor_unit_count == motor_unit_count
def test_init(): motor_unit_count = 120 f = Fibers(120) # Check calculated number of motor units assert f.motor_unit_count == 120 assert np.equal(f.current_forces, np.zeros(motor_unit_count)).all()
def test_step(): motor_unit_count = 120 f = Fibers(motor_unit_count) # Missing arguments with pytest.raises(TypeError): f.step() with pytest.raises(TypeError): f.step(33.0) # Bad type with pytest.raises(TypeError): f.step(33.0, 1) # Wrong shape with pytest.raises(AssertionError): f.step(np.ones(3), 1) # No excitation output = f.step(np.zeros(motor_unit_count), 1.0) assert output == pytest.approx(0.0) # Moderate f = Fibers(motor_unit_count) moderate_input = 40.0 moderate_output = 2586.7530897 output = f.step(np.full(motor_unit_count, moderate_input), 1.0) output_sum = np.sum(output) assert output_sum == pytest.approx(moderate_output) # Max f = Fibers(motor_unit_count) max_input = 67.0 max_output = 2609.0308816 output = f.step(np.full(motor_unit_count, max_input), 1.0) output_sum = np.sum(output) assert output_sum == pytest.approx(max_output) # Above f = Fibers(motor_unit_count) output = f.step(np.full(motor_unit_count, max_input + 40), 1.0) output_sum = np.sum(output) assert output_sum == pytest.approx(max_output)
import plotly.graph_objs as go from plotly.offline import plot from copy import copy sys.path.insert(0, os.path.abspath('..')) from pymuscle import Potvin2017MuscleFibers as Fibers from pymuscle import Potvin2017MotorNeuronPool as Pool motor_unit_count = 120 motor_unit_indices = np.arange(1, motor_unit_count + 1) # Motor Neuron Pool pool = Pool(motor_unit_count) # Fibers fibers = Fibers(motor_unit_count) if False: all_firing_rates = [] all_excitation_levels = [] all_norm_forces = [] all_norm_firing = [] for i in np.arange(1.0, 67.0, 0.1): excitations = np.full(motor_unit_count, i) firing_rates = pool._calc_firing_rates(excitations) normalized_firing_rates = fibers._normalize_firing_rates(firing_rates) normalized_forces = fibers._calc_normalized_forces( normalized_firing_rates) current_forces = fibers._calc_current_forces(normalized_forces) total_force = fibers._calc_total_inst_force(current_forces) all_excitation_levels.append(i)
from copy import copy sys.path.insert(0, os.path.abspath('..')) # from pymuscle import PotvinFuglevand2017MuscleFibers as Fibers from pymuscle import PyMuscleFibers as Fibers from pymuscle import PotvinFuglevand2017MotorNeuronPool as Pool motor_unit_count = 120 motor_unit_indices = np.arange(1, motor_unit_count + 1) # Motor Neuron Pool apply_fatigue = True pool = Pool(motor_unit_count, apply_fatigue=False) # Fibers fibers = Fibers(motor_unit_count) # Disable fatigue below if desired def get_force(excitations, step_size): firing_rates = pool.step(excitations, step_size) normalized_firing_rates = fibers._normalize_firing_rates(firing_rates) normalized_forces = fibers._calc_normalized_forces(normalized_firing_rates) current_forces = fibers._calc_current_forces(normalized_forces) total_force = np.sum(current_forces) return firing_rates, normalized_forces, current_forces, total_force # Target Force - 20% MVC max_force = 2216.0 max_excitation = 67.0 target_percent = 100