plotemg
Description¶
This module contains all the functions used to visualise the content of the imported EMG file, the MUs properties or to save figures.
showgoodlayout(tight_layout=True, despined=False)
¶
Despine and show plots with a good layout.
This function is called by the various plot functions contained in the library but can also be used by the user to quickly adjust the layout of custom plots.
PARAMETER | DESCRIPTION |
---|---|
tight_layout
|
If true (default), plt.tight_layout() is applied to the figure.
TYPE:
|
despined
|
False: left and bottom is not despined (standard plotting). True: all the sides are despined.
TYPE:
|
plot_emgsig(emgfile, channels, addrefsig=False, timeinseconds=True, figsize=[20, 15], showimmediately=True, tight_layout=True)
¶
Plot the RAW_SIGNAL. Single or multiple channels.
Up to 12 channels (a common matrix row) can be easily observed togheter, but more can be plotted.
PARAMETER | DESCRIPTION |
---|---|
emgfile
|
The dictionary containing the emgfile.
TYPE:
|
channels
|
The channel (int) or channels (list of int) to plot. The list can be passed as a manually-written list or with: channels=[*range(0, 13)]. We need the " * " operator to unpack the results of range into a list. channels is expected to be with base 0 (i.e., the first channel in the file is the number 0).
TYPE:
|
addrefsig
|
If True, the REF_SIGNAL is plotted in front of the signal with a separated y-axes.
TYPE:
|
timeinseconds
|
Whether to show the time on the x-axes in seconds (True) or in samples (False).
TYPE:
|
figsize
|
Size of the figure in centimeters [width, height].
TYPE:
|
showimmediately
|
If True (default), plt.show() is called and the figure showed to the user. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
tight_layout
|
If True (default), the plt.tight_layout() is called and the figure's layout is improved. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
fig
|
TYPE:
|
See also
- plot_differentials : plot the differential derivation of the RAW_SIGNAL by matrix column.
Examples:
Plot channels 0 to 12 and overlay the reference signal.
plot_differentials(emgfile, differential, column='col0', addrefsig=False, timeinseconds=True, figsize=[20, 15], showimmediately=True, tight_layout=True)
¶
Plot the differential derivation of the RAW_SIGNAL by matrix column.
Both the single and the double differencials can be plotted. This function is used to plot also the sorted RAW_SIGNAL.
PARAMETER | DESCRIPTION |
---|---|
emgfile
|
The dictionary containing the original emgfile.
TYPE:
|
differential
|
The dictionary containing the differential derivation of the RAW_SIGNAL.
TYPE:
|
column
|
The matrix column to plot. Options are usyally "col0", "col1", "col2", "col3", "col4". but might change based on the size of the matrix used.
TYPE:
|
addrefsig
|
If True, the REF_SIGNAL is plotted in front of the signal with a separated y-axes.
TYPE:
|
timeinseconds
|
Whether to show the time on the x-axes in seconds (True) or in samples (False).
TYPE:
|
figsize
|
Size of the figure in centimeters [width, height].
TYPE:
|
showimmediately
|
If True (default), plt.show() is called and the figure showed to the user. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
tight_layout
|
If True (default), the plt.tight_layout() is called and the figure's layout is improved. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
fig
|
TYPE:
|
See also
- diff : calculate single differential of RAW_SIGNAL on matrix rows.
- double_diff : calculate double differential of RAW_SIGNAL on matrix rows.
- plot_emgsig : pot the RAW_SIGNAL. Single or multiple channels.
Examples:
Plot the differential derivation of the first matrix column (col0).
>>> 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,
>>> )
>>> sd=emg.diff(sorted_rawemg=sorted_rawemg)
>>> emg.plot_differentials(
... emgfile=emgfile,
... differential=sd,
... column="col0",
... addrefsig=False,
... timeinseconds=True,
... figsize=[20, 15],
... showimmediately=True,
... )
plot_refsig(emgfile, ylabel='MVC', timeinseconds=True, figsize=[20, 15], showimmediately=True, tight_layout=True)
¶
Plot the REF_SIGNAL.
The REF_SIGNAL is usually expressed as % MVC for submaximal contractions or as Kilograms (Kg) or Newtons (N) for maximal contractions, but any value can be plotted.
PARAMETER | DESCRIPTION |
---|---|
emgfile
|
The dictionary containing the emgfile.
TYPE:
|
ylabel
|
The unit of measure to show on the Y axis.
TYPE:
|
timeinseconds
|
Whether to show the time on the x-axes in seconds (True) or in samples (False).
TYPE:
|
figsize
|
Size of the figure in centimeters [width, height].
TYPE:
|
showimmediately
|
If True (default), plt.show() is called and the figure showed to the user. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
tight_layout
|
If True (default), the plt.tight_layout() is called and the figure's layout is improved. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
fig
|
TYPE:
|
Examples:
Plot the reference signal.
>>> import openhdemg.library as emg
>>> emgfile = emg.askopenfile(filesource="OTB", otb_ext_factor=8)
>>> emg.plot_refsig(emgfile=emgfile)
Change Y axis label and show time in samples.
plot_mupulses(emgfile, munumber='all', linewidths=0.5, addrefsig=True, timeinseconds=True, figsize=[20, 15], showimmediately=True, tight_layout=True)
¶
Plot all the MUPULSES (binary representation of the firings time).
PARAMETER | DESCRIPTION |
---|---|
emgfile
|
The dictionary containing the emgfile.
TYPE:
|
munumber
|
Otherwise, a single MU (int) or multiple MUs (list of int) can be specified. The list can be passed as a manually-written list or with: munumber=[*range(0, 12)]. We need the " * " operator to unpack the results of range into a list. munumber is expected to be with base 0 (i.e., the first MU in the file is the number 0).
TYPE:
|
linewidths
|
The width of the vertical lines representing the MU firing.
TYPE:
|
addrefsig
|
If True, the REF_SIGNAL is plotted in front of the MUs pulses with a separated y-axes.
TYPE:
|
timeinseconds
|
Whether to show the time on the x-axes in seconds (True) or in samples (False).
TYPE:
|
figsize
|
Size of the figure in centimeters [width, height].
TYPE:
|
showimmediately
|
If True (default), plt.show() is called and the figure showed to the user. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
tight_layout
|
If True (default), the plt.tight_layout() is called and the figure's layout is improved. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
fig
|
TYPE:
|
See also
- plot_ipts : plot the MUs impulse train per second (IPTS).
- plot_idr : plot the instantaneous discharge rate.
Examples:
Plot MUs pulses based on recruitment order and overlay the reference signal.
plot_ipts(emgfile, munumber='all', addrefsig=False, timeinseconds=True, figsize=[20, 15], showimmediately=True, tight_layout=True)
¶
Plot the IPTS (decomposed source).
IPTS is the non-binary representation of the MUs firing times.
PARAMETER | DESCRIPTION |
---|---|
emgfile
|
The dictionary containing the emgfile.
TYPE:
|
munumber
|
Otherwise, a single MU (int) or multiple MUs (list of int) can be specified. The list can be passed as a manually-written list or with: munumber=[*range(0, 12)]. We need the " * " operator to unpack the results of range into a list. munumber is expected to be with base 0 (i.e., the first MU in the file is the number 0).
TYPE:
|
timeinseconds
|
Whether to show the time on the x-axes in seconds (True) or in samples (False).
TYPE:
|
figsize
|
Size of the figure in centimeters [width, height].
TYPE:
|
showimmediately
|
If True (default), plt.show() is called and the figure showed to the user. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
tight_layout
|
If True (default), the plt.tight_layout() is called and the figure's layout is improved. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
fig
|
TYPE:
|
See also
- plot_mupulses : plot the binary representation of the firings.
- plot_idr : plot the instantaneous discharge rate.
Notes
munumber = "all" corresponds to: munumber = [*range(0, emgfile["NUMBER_OF_MUS"])]
Examples:
Plot IPTS of all the MUs and overlay the reference signal.
>>> import openhdemg.library as emg
>>> emgfile = emg.askopenfile(filesource="OTB", otb_ext_factor=8)
>>> emg.plot_ipts(
... emgfile=emgfile,
... munumber="all",
... addrefsig=True,
... timeinseconds=True,
... figsize=[20, 15],
... showimmediately=True,
... )
Plot IPTS of two MUs.
plot_idr(emgfile, munumber='all', addrefsig=True, timeinseconds=True, figsize=[20, 15], showimmediately=True, tight_layout=True)
¶
Plot the instantaneous discharge rate (IDR).
PARAMETER | DESCRIPTION |
---|---|
emgfile
|
The dictionary containing the emgfile.
TYPE:
|
munumber
|
Otherwise, a single MU (int) or multiple MUs (list of int) can be specified. The list can be passed as a manually-written list or with: munumber=[*range(0, 12)]. We need the " * " operator to unpack the results of range into a list. munumber is expected to be with base 0 (i.e., the first MU in the file is the number 0).
TYPE:
|
addrefsig
|
If True, the REF_SIGNAL is plotted in front of the MUs IDR with a separated y-axes.
TYPE:
|
timeinseconds
|
Whether to show the time on the x-axes in seconds (True) or in samples (False).
TYPE:
|
figsize
|
Size of the figure in centimeters [width, height].
TYPE:
|
showimmediately
|
If True (default), plt.show() is called and the figure showed to the user. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
tight_layout
|
If True (default), the plt.tight_layout() is called and the figure's layout is improved. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
fig
|
TYPE:
|
See also
- plot_mupulses : plot the binary representation of the firings.
- plot_ipts : plot the impulse train per second (IPTS).
Notes
munumber = "all" corresponds to munumber = [*range(0, emgfile["NUMBER_OF_MUS"])]
Examples:
Plot IDR of all the MUs and overlay the reference signal.
>>> import openhdemg.library as emg
>>> emgfile = emg.askopenfile(filesource="OTB", otb_ext_factor=8)
>>> emg.plot_idr(
... emgfile=emgfile,
... munumber="all",
... addrefsig=True,
... timeinseconds=True,
... figsize=[20, 15],
... showimmediately=True,
... )
Plot IDR of two MUs.
plot_smoothed_dr(emgfile, smoothfits, munumber='all', addidr=True, stack=True, addrefsig=True, timeinseconds=True, figsize=[20, 15], showimmediately=True, tight_layout=True)
¶
Plot the smoothed discharge rate.
PARAMETER | DESCRIPTION |
---|---|
emgfile
|
The dictionary containing the emgfile.
TYPE:
|
smoothfits
|
Smoothed discharge rate estimates aligned in time. Columns should contain the smoothed discharge rate for each MU.
TYPE:
|
munumber
|
Otherwise, a single MU (int) or multiple MUs (list of int) can be specified. The list can be passed as a manually-written list or with: munumber=[*range(0, 12)]. We need the " * " operator to unpack the results of range into a list. munumber is expected to be with base 0 (i.e., the first MU in the file is the number 0).
TYPE:
|
addidr
|
Whether to show also the IDR behind the smoothed DR line.
TYPE:
|
stack
|
Whether to stack multiple MUs. If False, all the MUs smoothed DR will be plotted on the same line.
TYPE:
|
addrefsig
|
If True, the REF_SIGNAL is plotted in front of the MUs IDR with a separated y-axes.
TYPE:
|
timeinseconds
|
Whether to show the time on the x-axes in seconds (True) or in samples (False).
TYPE:
|
figsize
|
Size of the figure in centimeters [width, height].
TYPE:
|
showimmediately
|
If True (default), plt.show() is called and the figure showed to the user. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
tight_layout
|
If True (default), the plt.tight_layout() is called and the figure's layout is improved. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
fig
|
TYPE:
|
See also
- compute_svr : Fit MU discharge rates with Support Vector Regression, nonlinear regression.
Notes
munumber = "all" corresponds to: munumber = [*range(0, emgfile["NUMBER_OF_MUS"])]
Examples:
Smooth MUs DR using Support Vector Regression.
>>> import openhdemg.library as emg
>>> import pandas as pd
>>> emgfile = emg.emg_from_samplefile()
>>> emgfile = emg.sort_mus(emgfile=emgfile)
>>> svrfits = emg.compute_svr(emgfile)
Plot the stacked smoothed DR of all the MUs and overlay the IDR and the reference signal.
plot_muaps(sta_dict, title='MUAPs from STA', figsize=[20, 15], showimmediately=True, tight_layout=False)
¶
Plot MUAPs obtained from STA from one or multiple MUs.
PARAMETER | DESCRIPTION |
---|---|
sta_dict
|
dict containing STA of the specified MU or a list of dicts containing STA of specified MUs. If a list is passed, different MUs are overlayed. This is useful for visualisation of MUAPs during tracking or duplicates removal.
TYPE:
|
title
|
Title of the plot.
TYPE:
|
figsize
|
Size of the figure in centimeters [width, height].
TYPE:
|
showimmediately
|
If True (default), plt.show() is called and the figure showed to the user. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
tight_layout
|
If True (default), the plt.tight_layout() is called and the figure's layout is improved. It is useful to set it to False when calling the function from the GUI or if the final layout is not correct.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
fig
|
TYPE:
|
See also
- sta : computes the spike-triggered average (STA) of every MUs.
- plot_muap : for overplotting all the STAs and the average STA of a MU.
- align_by_xcorr : for alignin the STAs of two different MUs.
Notes
There is no limit to the number of MUs and STA files that can be overplotted.
Remember: the different STAs should be matched
with same number of
electrode, processing (i.e., differential) and computed on the same
timewindow.
Examples:
Plot MUAPs of a single MU.
>>> 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,
... )
>>> sta = emg.sta(
... emgfile=emgfile,
... sorted_rawemg=sorted_rawemg,
... firings="all",
... timewindow=50,
... )
>>> emg.plot_muaps(sta_dict=sta[1])
Plot single differential derivation MUAPs of a single MU.
>>> 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 = emg.diff(sorted_rawemg=sorted_rawemg)
>>> sta = emg.sta(
... emgfile=emgfile,
... sorted_rawemg=sorted_rawemg,
... firings="all",
... timewindow=50,
... )
>>> emg.plot_muaps(sta_dict=sta[1])
Plot single differential derivation MUAPs of two MUs from the same file.
>>> 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 = emg.diff(sorted_rawemg=sorted_rawemg)
>>> sta = emg.sta(
... emgfile=emgfile,
... sorted_rawemg=sorted_rawemg,
... firings="all",
... timewindow=50,
... )
>>> emg.plot_muaps(sta_dict=[sta[1], sta[2]])
plot_muap(emgfile, stmuap, munumber, column, channel, channelprog=False, average=True, timeinseconds=True, figsize=[20, 15], showimmediately=True, tight_layout=True)
¶
Plot the MUAPs of a specific matrix channel.
Plot the MUs action potential (MUAPs) shapes with or without average.
PARAMETER | DESCRIPTION |
---|---|
emgfile
|
The dictionary containing the emgfile.
TYPE:
|
stmuap
|
dict containing a dict of ST MUAPs (pd.DataFrame) for every MUs.
TYPE:
|
munumber
|
The number of the MU to plot.
TYPE:
|
column
|
The matrix columns. Options are usyally "col0", "col1", "col2", ..., last column.
TYPE:
|
channel
|
The channel of the matrix to plot. This can be the real channel number if channelprog=False (default), or a progressive number (from 0 to the length of the matrix column) if channelprog=True.
TYPE:
|
channelprog
|
Whether to use the real channel number or a progressive number (see channel).
TYPE:
|
average
|
Whether to plot also the MUAPs average obtained by spike triggered average.
TYPE:
|
timeinseconds
|
Whether to show the time on the x-axes in seconds (True) or in samples (False).
TYPE:
|
figsize
|
Size of the figure in centimeters [width, height].
TYPE:
|
showimmediately
|
If True (default), plt.show() is called and the figure showed to the user. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
tight_layout
|
If True (default), the plt.tight_layout() is called and the figure's layout is improved. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
fig
|
TYPE:
|
See also
- plot_muaps : Plot MUAPs obtained from STA from one or multiple MUs.
- st_muap : Generate spike triggered MUAPs of every MUs (as input to this function).
Examples:
Plot all the consecutive MUAPs of a single MU. In this case we are plotting the matrix channel 45 which is placed in column 4 ("col3" as Python numbering is base 0).
>>> import openhdemg.library as emg
>>> emgfile = emg.askopenfile(filesource="OTB", otb_ext_factor=8)
>>> sorted_rawemg = emg.sort_rawemg(
... emgfile,
... code="GR08MM1305",
... orientation=180,
... dividebycolumn=True,
... )
>>> stmuap = emg.st_muap(
... emgfile=emgfile,
... sorted_rawemg=sorted_rawemg,
... timewindow=50,
... )
>>> emg.plot_muap(
... emgfile=emgfile,
... stmuap=stmuap,
... munumber=1,
... column="col3",
... channel=45,
... channelprog=False,
... average=False,
... timeinseconds=True,
... figsize=[20, 15],
... showimmediately=True,
... )
To avoid the problem of remebering which channel number is present in which matrix column, we can set channelprog=True and locate the channel with a value ranging from 0 to the length of each column.
>>> 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,
... )
>>> stmuap = emg.st_muap(
... emgfile=emgfile,
... sorted_rawemg=sorted_rawemg,
... timewindow=50,
... )
>>> emg.plot_muap(
... emgfile=emgfile,
... stmuap=stmuap,
... munumber=1,
... column="col3",
... channel=5,
... channelprog=True,
... average=False,
... timeinseconds=True,
... figsize=[20, 15],
... showimmediately=True,
... )
It is also possible to visualise the spike triggered average of the MU with average=True. In this example the single differential derivation is used.
>>> 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 = emg.diff(sorted_rawemg=sorted_rawemg)
>>> stmuap = emg.st_muap(
... emgfile=emgfile,
... sorted_rawemg=sorted_rawemg,
... timewindow=50,
... )
>>> emg.plot_muap(
... emgfile=emgfile,
... stmuap=stmuap,
... munumber=1,
... column="col2",
... channel=6,
... channelprog=True,
... average=True,
... timeinseconds=True,
... figsize=[20, 15],
... showimmediately=True,
... )
plot_muaps_for_cv(sta_dict, xcc_sta_dict, title='MUAPs for CV', figsize=[20, 15], showimmediately=True, tight_layout=False)
¶
Visualise MUAPs on which to calculate MUs CV.
Plot MUAPs obtained from the STA of the double differential signal and their paired cross-correlation value.
PARAMETER | DESCRIPTION |
---|---|
sta_dict
|
dict containing the STA of the double-differential derivation of a specific MU.
TYPE:
|
xcc_sta_dict
|
dict containing the normalised cross-correlation coefficient of the double-differential derivation of a specific MU.
TYPE:
|
title
|
Title of the plot.
TYPE:
|
figsize
|
Size of the figure in centimeters [width, height].
TYPE:
|
showimmediately
|
If True (default), plt.show() is called and the figure showed to the user. It is useful to set it to False when calling the function from the GUI.
TYPE:
|
tight_layout
|
If True (default), the plt.tight_layout() is called and the figure's layout is improved. It is useful to set it to False when calling the function from the GUI or if the final layout is not correct.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
fig
|
TYPE:
|
Examples:
Plot the double differential derivation and the XCC of adjacent channels for the first MU (0).
>>> import openhdemg.library as emg
>>> emgfile = emg.askopenfile(filesource="OTB", otb_ext_factor=8)
>>> sorted_rawemg = emg.sort_rawemg(
... emgfile,
... code="GR08MM1305",
... orientation=180,
... dividebycolumn=True
... )
>>> dd = emg.double_diff(sorted_rawemg)
>>> sta = emg.sta(
... emgfile=emgfile,
... sorted_rawemg=dd,
... firings=[0, 50],
... timewindow=50,
... )
>>> xcc_sta = emg.xcc_sta(sta)
>>> fig = emg.plot_muaps_for_cv(
... sta_dict=sta[0],
... xcc_sta_dict=xcc_sta[0],
... showimmediately=True,
... )