tools ¶
Rearrange EMG channels on an electrode grid and replace bad channels.
arrange_data_spatially ¶
arrange_data_spatially(data: ndarray, ch_map: ndarray) -> np.ndarray
Arrange (samples, chs) data on the electrode grid given by the channel map.
Grid positions with a negative or out-of-range channel index are filled with zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data with shape (samples, chs). |
required |
ch_map
|
ndarray
|
Channel map with shape (rows, cols) holding the 0-based channel index of each electrode, and -1 for empty positions. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Spatially arranged data with shape (rows, cols, samples). |
Source code in emg_tools/tools.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
flatten_data_spatially ¶
flatten_data_spatially(data: ndarray, ch_map: ndarray) -> np.ndarray
Flatten (rows, cols, samples) grid data back to (samples, chs).
Inverse of arrange_data_spatially. Channels missing from the map are filled with zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data with shape (rows, cols, samples). |
required |
ch_map
|
ndarray
|
Channel map with shape (rows, cols) holding the 0-based channel index of each electrode, and -1 for empty positions. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Flattened data with shape (samples, chs), where chs is
|
Source code in emg_tools/tools.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
replace_bad_ch ¶
replace_bad_ch(data: ndarray, bad_ch: Union[list, ndarray], ch_map: ndarray) -> np.ndarray
Replace bad channels with the mean of their good neighbouring channels.
Neighbours are the up to 8 surrounding electrodes on the grid. Bad channels are replaced in the given order, so a replaced channel can serve as a neighbour for the next ones. Bad channels without good neighbours are set to zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data with shape (samples, chs) or (rows, cols, samples). |
required |
bad_ch
|
Union[list, ndarray]
|
0-based indices of the bad channels. |
required |
ch_map
|
ndarray
|
Channel map with shape (rows, cols) holding the 0-based channel index of each electrode, and -1 for empty positions. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Copy of the data, same shape as the input, with the bad channels replaced. |
Source code in emg_tools/tools.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |