Sort RAW_SIGNAL based on matrix type and orientation.
To date, built-in sorting functions have been implemented for the matrices:
Code (Orientation)
GR08MM1305 (0, 180)
GR04MM1305 (0, 180)
GR10MM0808 (0, 180)
Trigno Galileo Sensor (na)
Custom order (any)
PARAMETER |
DESCRIPTION |
emgfile |
The dictionary containing the emgfile.
TYPE:
dict
|
code |
The code of the matrix used. It can be one of:
GR08MM1305
GR04MM1305
GR10MM0808
Trigno Galileo Sensor
Custom order
None
If "None", the electodes are not sorted but n_rows and n_cols must be
specified when dividebycolumn == True.
If "Custom order", the electrodes are sorted based on
custom_sorting_order.
TYPE:
str
DEFAULT:
"GR08MM1305"
|
orientation |
Orientation in degree of the matrix.
E.g. 180 corresponds to the matrix connection toward the researcher or
the ground (depending on the limb).
Ignore if using the "Trigno Galileo Sensor". In this case, channels
will be oriented as in the Delsys Neuromap Explorer software.
This Parameter is ignored if code=="Custom order" or code=="None".
TYPE:
int {0, 180}
DEFAULT:
180
|
dividebycolumn |
Whether to return the sorted channels classified by matrix column.
DEFAULT:
True
|
n_rows |
The number of rows of the matrix. This parameter is used to divide the
channels based on the matrix shape. These are inferred by the matrix
code and must be specified only if code==None.
TYPE:
None or int
DEFAULT:
None
|
n_cols |
The number of columns of the matrix. This parameter is used to divide
the channels based on the matrix shape. These are inferred by the
matrix code and must be specified only if code==None.
TYPE:
None or int
DEFAULT:
None
|
custom_sorting_order |
If code=="Custom order", custom_sorting_order will be used for
channels sorting. In this case, custom_sorting_order must be a list of
lists containing the order of the matrix channels.
Specifically, the number of columns are defined by
len(custom_sorting_order) while the number of rows by
len(custom_sorting_order[0]). np.nan can be used to specify empty
channels. Please refer to the Notes and Examples section for the
structure of the custom sorting order.
TYPE:
None or list
DEFAULT:
None
|
RETURNS |
DESCRIPTION |
sorted_rawemg
|
If dividebycolumn == True, a dict containing the sorted electrodes is
returned. Every key of the dictionary represents a different column of
the matrix. Rows are stored in the dict as a pd.DataFrame.
If dividebycolumn == False a pd.DataFrame containing the sorted
electrodes is returned. The matrix channels are stored in the
pd.DataFrame columns.
TYPE:
dict or DataFrame
|
Notes
The returned file is called sorted_rawemg
for convention.
Additional info on how to create the custom sorting order is available at:
https://www.giacomovalli.com/openhdemg/gui_settings/#electrodes
Examples:
Sort emgfile RAW_SIGNAL and divide it by columns with built-in sorting
orders.
>>> import openhdemg.library as emg
>>> emgfile = emg.askopenfile(filesource="OTB", otb_ext_factor=8)
>>> sorted_rawemg = emg.sort_rawemg(
... emgfile=emgfile,
... code="GR08MM1305",
... orientation=180,
... dividebycolumn=True,
... )
>>> sorted_rawemg["col0"]
0 1 2 ... 10 11 12
0 NaN -11.189778 3.560384 ... -2.034505 -3.051758 -0.508626
1 NaN -12.715657 4.577637 ... 2.034505 -7.120768 -0.508626
2 NaN 0.508626 21.870932 ... 17.801920 8.646647 16.276041
3 NaN 6.103516 26.957193 ... 26.448568 19.327799 19.836426
4 NaN -5.594889 13.224284 ... 10.681152 2.034505 3.560384
... .. ... ... ... ... ... ...
63483 NaN -15.767415 -22.379557 ...-12.207031 -12.207031 -15.767415
63484 NaN -9.155273 -19.327799 ... -7.629395 -8.138021 -8.138021
63485 NaN -6.103516 -12.207031 ... -6.103516 -5.086263 -3.051758
63486 NaN -6.103516 -15.767415 ... -3.560384 -0.508626 2.543132
63487 NaN -8.138021 -18.819174 ... -2.034505 -1.525879 3.560384
Sort emgfile RAW_SIGNAL without dividing it by columns.
>>> emgfile = emg.askopenfile(filesource="OTB", otb_ext_factor=8)
>>> sorted_rawemg = emg.sort_rawemg(
... emgfile,
... code="GR08MM1305",
... orientation=180,
... dividebycolumn=False,
... )
>>> sorted_rawemg
0 1 2 ... 62 63 64
0 NaN -11.189778 3.560384 ... -5.086263 -9.663899 2.034505
1 NaN -12.715657 4.577637 ... -3.560384 -8.646647 1.017253
2 NaN 0.508626 21.870932 ... 11.189778 6.612142 17.293295
3 NaN 6.103516 26.957193 ... 22.888184 14.750163 21.362305
4 NaN -5.594889 13.224284 ... 9.663899 1.525879 6.612142
... .. ... ... ... ... ... ...
63483 NaN -15.767415 -22.379557 ... -8.646647 -20.345053 -15.258789
63484 NaN -9.155273 -19.327799 ... -7.120768 -19.327799 -13.732910
63485 NaN -6.103516 -12.207031 ... -3.051758 -10.681152 -6.103516
63486 NaN -6.103516 -15.767415 ... 2.543132 -7.120768 -4.069010
63487 NaN -8.138021 -18.819174 ... 2.034505 -3.051758 -0.508626
Avoid RAW_SIGNAL sorting but divide it by columns.
>>> emgfile = emg.askopenfile(filesource="CUSTOM")
>>> sorted_rawemg = emg.sort_rawemg(
... emgfile, code="None", n_cols=5, n_rows=13,
... )
>>> sorted_rawemg["col0"]
0 1 2 ... 10 11 12
0 0.008138 0.001017 0.002035 ... 0.005595 0.008647 NaN
1 -0.005595 -0.011190 -0.014750 ... 0.000000 0.005086 NaN
2 -0.017293 -0.020854 -0.021871 ... 0.009664 -0.004578 NaN
3 -0.003560 -0.012716 -0.009155 ... 0.004578 0.007121 NaN
4 0.001526 -0.005595 -0.005595 ... 0.007121 0.010173 NaN
... ... ... ... ... ... ... ..
62459 0.011698 0.015259 0.004069 ... 0.000000 0.031026 NaN
62460 0.007629 0.011698 0.002543 ... 0.002035 0.026449 NaN
62461 0.001526 0.009664 0.000000 ... 0.001526 0.025940 NaN
62462 0.033061 0.037130 0.027974 ... 0.022380 0.049845 NaN
62463 0.020854 0.028992 0.017802 ... 0.013733 0.037638 NaN
Sort RAW_SIGNAL based on a custom order and divide it by columns.
The custom_sorting_order refers to a grid of 13 rows and 5 columns with the
empty channel in last position.
Additional info on how to create the custom sorting order is available at:
https://www.giacomovalli.com/openhdemg/gui_settings/#electrodes
>>> import openhdemg.library as emg
>>> emgfile = emg.askopenfile(filesource="OTB", otb_ext_factor=8)
>>> custom_sorting_order = [
... [63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51,],
... [38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,],
... [37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25,],
... [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,],
... [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, np.nan,],
... ] # 13 rows and 5 columns
>>> sorted_rawemg = emg.sort_rawemg(
... emgfile=emgfile,
... code="Custom order",
... dividebycolumn=True,
... custom_sorting_order=custom_sorting_order,
... )
>>> sorted_rawemg["col0"]
0 1 2 ... 10 11 12
0 2.034505 -9.663899 -5.086263 ... -26.957193 -8.138021 -2.034505
1 1.017253 -8.646647 -3.560384 ... -26.957193 -8.138021 -9.663899
2 17.293295 6.612142 11.189778 ... -13.224284 9.663899 6.612142
3 21.362305 14.750163 22.888184 ... -9.155273 17.293295 12.715657
... ... ... ... ... ... ... ...
63483 -15.258789 -20.345053 -8.646647 ... -20.853678 -15.767415 -10.681152
63484 -13.732910 -19.327799 -7.120768 ... -21.362305 -17.801920 -14.241536