IntramuscularElectrodeArray#
- class IntramuscularElectrodeArray(
- num_electrodes,
- inter_electrode_distance__mm=0.5,
- position__mm=(0.0, 0.0, 0.0),
- orientation__rad=(0.0, 0.0, 0.0),
- differentiation_mode='consecutive',
- trajectory_distance__mm=0.0,
- trajectory_steps=1,
Bases:
object
Intramuscular electrode array for EMG recording.
Represents a linear array of intramuscular electrodes (needle electrodes) with configurable spacing and differentiation modes.
- Parameters:
num_electrodes (
int
) – Number of electrodes in the arrayinter_electrode_distance__mm (
float
, default0.5
) – Inter-electrode distance in mmposition__mm (
tuple[float
,float
,float]
, default(0.0
,0.0
,0.0)
) – Position of the electrode array center in mm (x, y, z coordinates)orientation__rad (
tuple[float
,float
,float]
, default(0.0
,0.0
,0.0)
) – Orientation of the electrode array in radians (roll, pitch, yaw)differentiation_mode (
Literal[``
”consecutive”, ``"reference"
]
, default"consecutive"
) – Differentiation mode for recordingtrajectory_distance__mm (
float
, default0.0
) – Distance for trajectory movement in mmtrajectory_steps (
int
, default1
) – Number of steps in the trajectory
- electrode_positions#
Current electrode positions in 3D space, shape (n_nodes * num_electrodes, 3). Available after set_linear_trajectory() execution.
- Type:
- differential_matrix#
Differential matrix for signal processing based on differentiation mode. Available after class initialization.
- Type:
- trajectory_transforms#
Transformation matrices for trajectory movement, shape (n_nodes, 6). Available after set_linear_trajectory() execution.
- Type:
- initial_positions#
Initial electrode positions after position/orientation setup, shape (num_electrodes, 3). Available after set_position() execution.
- Type:
- num_channels#
Number of recording channels based on differentiation mode. Available after class initialization.
- Type:
Methods
Apply Rodrigues rotation to vectors around an arbitrary axis.
Configure linear trajectory movement for the electrode array.
Set the position and orientation of the intramuscular electrode array.
Compute mixing weight for a specific trajectory node at given time.
Generate mixing matrix for trajectory interpolation during EMG simulation.
Attributes
Differential matrix for signal processing based on differentiation mode.
Current electrode positions in 3D space (mm).
Initial electrode positions after position/orientation setup.
Number of recording channels based on differentiation mode.
Transformation matrices for trajectory movement.
- set_position(position__mm, orientation__rad)[source]#
Set the position and orientation of the intramuscular electrode array.
This method defines the spatial placement and angular orientation of the electrode array within the muscle volume. The array is first oriented according to the specified rotations and then translated to the target position.
Coordinate System: - x-axis: radial direction (outward from muscle center) - y-axis: circumferential direction (around muscle) - z-axis: longitudinal direction (along muscle fibers)
Rotation Order: Applied as: Roll (x) → Pitch (y) → Yaw (z) using Rodrigues rotation
- Parameters:
position__mm (
tuple[float
,float
,float]
) – Center position of the electrode array in mm (x, y, z coordinates). This defines where the array center is placed within the muscle.orientation__rad (
tuple[float
,float
,float]
) – Orientation angles in radians (roll, pitch, yaw). - Roll: rotation around x-axis (radial tilt) - Pitch: rotation around y-axis (circumferential tilt) - Yaw: rotation around z-axis (longitudinal rotation)
- Return type:
None
Notes
Position and orientation changes affect all subsequent trajectory calculations. The electrode positions are recalculated based on the new transformation.
Examples
>>> # Place array at muscle center with 45° yaw rotation >>> array.set_position( ... position__mm=(0.0, 0.0, 10.0), ... orientation__rad=(0.0, 0.0, np.pi/4) ... )
See also
set_linear_trajectory
Define trajectory movement parameters
rodrigues_rot
Rodrigues rotation implementation
- rodrigues_rot(v, k, theta)[source]#
Apply Rodrigues rotation to vectors around an arbitrary axis.
This method implements 3D rotation of points or vectors around an arbitrary axis using the Rodrigues rotation formula. It is used internally for electrode array positioning and trajectory calculations.
Mathematical Foundation: Based on Rodrigues’ rotation formula for rotating a vector v around axis k by angle theta: v_rot = v*cos(θ) + (k×v)*sin(θ) + k*(k·v)*(1-cos(θ))
- Parameters:
v (array_like) – Vector(s) to rotate. Can be single vector (3,) or array of vectors (N, 3).
k (array_like) – Rotation axis vector (3,). Will be normalized internally.
theta (
float
) – Rotation angle in radians. Positive angles follow right-hand rule.
- Returns:
Rotated vector(s) with same shape as input v.
- Return type:
Notes
Uses scipy.spatial.transform.Rotation for numerical stability and efficiency. The rotation axis k is automatically normalized to unit length.
Examples
>>> # Rotate point 90° around z-axis >>> point = np.array([1.0, 0.0, 0.0]) >>> rotated = array.rodrigues_rot(point, [0, 0, 1], np.pi/2) >>> # Result: approximately [0, 1, 0]
- set_linear_trajectory(distance__mm, n_nodes=None)[source]#
Configure linear trajectory movement for the electrode array.
This method sets up a linear movement path for the electrode array, simulating needle insertion or withdrawal. The trajectory is discretized into nodes for temporal interpolation during EMG simulation.
Trajectory Properties: - Direction: Along the array’s longitudinal axis (z-direction in local coordinates) - Movement: Linear progression from start to end position - Discretization: Evenly spaced nodes for smooth interpolation - Default step size: 0.5mm if n_nodes not specified
- Parameters:
- Return type:
None
Notes
The trajectory is applied after position and orientation transformations. All trajectory transforms are calculated in the array’s oriented coordinate system.
Examples
>>> # Set up 10mm insertion with default step size (~0.5mm) >>> array.set_linear_trajectory(distance__mm=10.0)
>>> # Set up 5mm trajectory with specific number of nodes >>> array.set_linear_trajectory(distance__mm=5.0, n_nodes=20)
See also
calc_observation_points
Calculate electrode positions along trajectory
traj_mixing_mat
Generate mixing matrices for trajectory interpolation
- traj_mixing_fun(t, n_nodes, node)[source]#
Compute mixing weight for a specific trajectory node at given time.
This function calculates the interpolation weight for a trajectory node based on the current time/position along the trajectory. Uses triangular weighting where nodes closer to the current time get higher weights.
- Parameters:
t (
float
) – Current normalized time or position in trajectory (0.0 to 1.0).n_nodes (
int
) – Total number of nodes in the trajectory.node (
int
or array_like) – Node index(es) for which to calculate mixing weights. Can be scalar or array of node indices.
- Returns:
Mixing weight(s) for the specified node(s) at time t. Returns 0 for distant nodes, max weight 1 for closest node.
- Return type:
- traj_mixing_mat(t, n_nodes, n_channels)[source]#
Generate mixing matrix for trajectory interpolation during EMG simulation.
This method creates a diagonal mixing matrix that weights the contribution of different trajectory nodes during temporal interpolation. The matrix enables smooth transitions between electrode positions as the array moves along its trajectory during needle insertion or withdrawal.
Interpolation Strategy: - Linear interpolation between adjacent trajectory nodes - Weights based on distance from current time/position to node positions - Diagonal matrix structure for efficient computation - Smooth transitions avoid discontinuities in EMG signals
- Parameters:
t (
float
) – Current normalized time or position in trajectory (0.0 to 1.0). 0.0 corresponds to trajectory start, 1.0 to trajectory end.n_nodes (
int
) – Total number of trajectory nodes for interpolation.n_channels (
int
) – Number of recording channels in the electrode array. Depends on differentiation mode and electrode count.
- Returns:
Diagonal mixing matrix with shape (n_nodes * n_channels, n_nodes * n_channels). Diagonal elements contain repeated mixing weights for each trajectory node, with each node’s weight repeated n_channels times.
- Return type:
Notes
The mixing matrix enables temporal interpolation of EMG signals recorded at different trajectory positions. Higher weights are given to nodes closer to the current time/position parameter.
Examples
>>> # Get mixing weights for mid-trajectory position >>> mix_mat = array.traj_mixing_mat(t=0.5, n_nodes=10, n_channels=4) >>> # Matrix will weight middle nodes more heavily
See also
traj_mixing_fun
Individual node mixing function
set_linear_trajectory
Configure trajectory parameters
- property electrode_positions: ndarray#
Current electrode positions in 3D space (mm).
- Returns:
Array of shape (n_nodes * num_electrodes, 3) containing x, y, z coordinates of each electrode position for all trajectory nodes.
- Return type:
- Raises:
AttributeError – If trajectory has not been calculated. Run set_linear_trajectory() first.
- property differential_matrix: ndarray#
Differential matrix for signal processing based on differentiation mode.
- Returns:
Differential matrix for applying spatial differentiation to recorded signals. Shape depends on differentiation mode and number of trajectory nodes.
- Return type:
- Raises:
AttributeError – If differential matrix has not been created. Run constructor first.
- property trajectory_transforms: ndarray#
Transformation matrices for trajectory movement.
- Returns:
Array of shape (n_nodes, 6) containing translation and rotation parameters for each trajectory node. First 3 columns are translations (x, y, z), last 3 columns are rotations (roll, pitch, yaw).
- Return type:
- Raises:
AttributeError – If trajectory has not been set. Run set_linear_trajectory() first.
- property initial_positions: ndarray#
Initial electrode positions after position/orientation setup.
- Returns:
Array of shape (num_electrodes, 3) containing initial x, y, z coordinates of electrodes before trajectory movement is applied.
- Return type:
- Raises:
AttributeError – If initial positions have not been set. Run set_position() first.
- property num_channels: int#
Number of recording channels based on differentiation mode.
- Returns:
Number of differential recording channels available from this electrode array.
- Return type:
- Raises:
AttributeError – If channel count has not been calculated. Run constructor first.