Skip to content

Commit cb4acf9

Browse files
committed
docs: standardize docstrings
1 parent 5724a6d commit cb4acf9

1 file changed

Lines changed: 58 additions & 42 deletions

File tree

src/emgdecompy/viz.py

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@
2121

2222
def RMSE(arr1, arr2):
2323
"""
24-
Evaluates Root Square Error for two series
24+
Evaluates root mean square error for two series.
2525
2626
Parameters
2727
----------
28-
arr1: iterative object
29-
First source, likely target.
30-
arr2: iterative object
31-
Second source, likely actual values.
28+
arr1: array
29+
First series.
30+
arr2: array
31+
Second series.
3232
3333
Returns
3434
-------
3535
float
36-
Root Mean Square Error of arr1 vs arr2.
36+
Root mean square error of arr1 vs arr2.
3737
3838
Examples
3939
--------
@@ -52,7 +52,8 @@ def RMSE(arr1, arr2):
5252
def mismatch_score(mu_data, peak_data, mu_index, method="RMSE", channel=-1):
5353
"""
5454
Evaluates how well a given peak contributes to a given MUAP.
55-
This is called by muap_plot() function and is used to include error in the title of the muap plot.
55+
This is called by the muap_plot() function and is used to
56+
include error in the title of the muap plot.
5657
5758
Parameters
5859
----------
@@ -61,13 +62,13 @@ def mismatch_score(mu_data, peak_data, mu_index, method="RMSE", channel=-1):
6162
peak_data: dict
6263
Dictionary containing shapes for a given peak per channel.
6364
mu_index: int
64-
Index of motor unit to examine
65+
Index of motor unit to examine.
6566
method: str
6667
Metric to use for evaluating discrepency between mu_data and peak_data.
6768
Default: "RMSE"
6869
channel: int
6970
Channel to run evaluation on.
70-
Default: -1 and it means average of all channels.
71+
Default: -1 which means average of all channels.
7172
7273
Returns
7374
-------
@@ -110,7 +111,9 @@ def muap_dict(raw, pt, l=31):
110111
Multi-dimensional array containing indices of firing times
111112
for each motor unit.
112113
l: int
113-
One half of action potential discharge time in samples.
114+
One half of the action potential discharge time in samples.
115+
Default value of 31 corresponds to approximately 15 ms at a
116+
sampling rate of 2048 Hz.
114117
115118
Returns
116119
-------
@@ -178,7 +181,9 @@ def muap_dict_by_peak(raw, peak, mu_index=0, l=31):
178181
mu_index: int
179182
Motor Unit the peak belongs to, to keep dict format consistent.
180183
l: int
181-
One half of action potential discharge time in samples.
184+
One half of the action potential discharge time in samples.
185+
Default value of 31 corresponds to approximately 15 ms at a
186+
sampling rate of 2048 Hz.
182187
183188
Returns
184189
-------
@@ -198,7 +203,8 @@ def muap_dict_by_peak(raw, peak, mu_index=0, l=31):
198203
# Make dictionary from this data
199204

200205
# Create channel index of each peak
201-
channel_index = np.repeat(np.arange(channels), l * 2 + 1) # 64 zeros,
206+
channel_index = np.repeat(np.arange(channels), l * 2 + 1)
207+
# 64 zeros,
202208
# 64 ones,
203209
# 64 twos,
204210
# [...],
@@ -226,23 +232,21 @@ def muap_dict_by_peak(raw, peak, mu_index=0, l=31):
226232

227233
def channel_preset(preset="standard"):
228234
"""
229-
Returns a dictionary with two keys:
230-
'sort_order' with the list to order channels,
231-
and 'cols' with the number of columns for a given channel arrangement.
232-
Called by muap_plot() function to determine the order of channels to plot shapes.
235+
Called by muap_plot() function to determine the order of channels when plotting MUAP shapes.
233236
234237
Parameters
235238
----------
236239
preset: str
237-
Name of the preset to use
240+
Name of the preset to use.
238241
239242
Returns
240243
-------
241-
dict with two keys
242-
cols: int
243-
Number of columns
244-
sort_order: list
245-
Sort order of all the channels
244+
dict
245+
Dictionary containing
246+
cols: int
247+
Number of columns for a given channel arrangement.
248+
sort_order: list
249+
Sort order of all the channels.
246250
247251
Examples
248252
--------
@@ -349,14 +353,16 @@ def muap_plot(
349353
mu_data: dict
350354
Dictionary containing MUAP shapes for each motor unit.
351355
mu_index: int
352-
Index of motor unit to examine
356+
Index of motor unit to examine.
353357
peak_data: dict
354358
Dictionary containing shapes for a given peak per channel.
355-
Specifying it creates the overlay of peak contribution
359+
Specifying it creates the overlay of peak contribution.
356360
l: int
357361
One half of action potential discharge time in samples.
358-
peak: int:
359-
Index of the peak, used for the Title of the plot.
362+
Default value of 31 corresponds to approximately 15 ms at a
363+
sampling rate of 2048 Hz.
364+
peak: float:
365+
Time of the peak, used for the title of the plot.
360366
method: str
361367
Metric to use to calculate mean (over all channels) mismatch score
362368
between averaged shape and given peak.
@@ -435,23 +441,24 @@ def muap_plot(
435441

436442
def pulse_plot(pt, c_sq_mean, mu_index, sel_type="single"):
437443
"""
438-
Plot firings for a given motor unit.
444+
Plot firings and firing rate for a given motor unit.
439445
440446
Parameters
441447
----------
442448
pulse_train: np.array
443-
Pulse train.
449+
Motor unit pulse train.
444450
c_sq_mean: np.array
445451
Centered, squared and averaged firings over the duration of the trial.
446452
mu_index: int
447-
Motor Unit of interest to plot firings for.
448-
Default is None and means return all pulses.
453+
Motor unit of interest to plot firings for.
449454
sel_type: str
450455
Whether to select single points or intervals.
451456
452457
Returns
453458
-------
454-
altair plot object
459+
altair.vegalite.v4.api.VConcatChart
460+
Plots containing instantaneous firing rate plot,
461+
signal strength plots, and overlay between the two.
455462
"""
456463

457464
color_pulse = "#35d3da"
@@ -603,10 +610,10 @@ def select_peak(
603610
604611
Parameters
605612
----------
606-
selection: selection object
613+
selection: array
607614
Selection object to dig into and retrieve peak index to plot.
608615
mu_index: int
609-
Currently plotted Motor Unit.
616+
Currently plotted motor unit.
610617
raw: numpy.ndarray
611618
Raw EMG signal array.
612619
shape_dict: dict
@@ -622,7 +629,10 @@ def select_peak(
622629
623630
Returns
624631
-------
625-
altair plot object
632+
panel.layout.base.Column
633+
Panel column containing facetted altair plot
634+
overlaying MU shapes per channel
635+
and peak shapes per channel.
626636
627637
"""
628638
global selected_peak
@@ -661,16 +671,16 @@ def dashboard(decomp_results, raw, mu_index=0, preset="standard", method="RMSE")
661671
"""
662672
Parent function for creating interactive visual component of decomposition.
663673
Dashboard consists of four plots:
664-
1. Plot of firings and signal, primarily for zooming and navigating.
665-
2. Plot of signal strength, which allows for peak selection.
666-
3. Plot of firings, which allows for peak selection.
667-
4. MUAP plot of individual motor unit shapes by channel, with selected peak overlay
674+
1. Plot of instantaneous firing rate and signal, primarily for zooming and navigating.
675+
2. Plot of instantaneous firing rate, which allows for peak selection.
676+
3. Plot of signal strength, which allows for peak selection.
677+
4. MUAP plot of individual motor unit shapes by channel, with selected peak overlay.
668678
669679
Parameters
670680
----------
671681
decomp_results: dict
672682
Decomposition results.
673-
Must contain [MUPulses] key with the pulses array.
683+
Must contain MUPulses key with the motor unit firing indices.
674684
675685
raw: numpy.ndarray
676686
Raw EMG data.
@@ -680,7 +690,8 @@ def dashboard(decomp_results, raw, mu_index=0, preset="standard", method="RMSE")
680690
681691
Returns
682692
-------
683-
panel object containing interactive altair plots
693+
panel.layout.base.Column
694+
Panel object containing interactive altair plots.
684695
"""
685696

686697
signal = flatten_signal(raw)
@@ -734,12 +745,17 @@ def visualize_decomp(decomp_results, raw):
734745
----------
735746
decomp_results: dict
736747
Decomposition results.
737-
Must contain [MUPulses] key with the pulses array.
748+
Must contain MUPulses key with the motor unit firing indices.
738749
raw: numpy.ndarray
739750
Raw EMG data.
740751
Returns
741752
-------
742-
panel object containing interactive altair plots
753+
panel.layout.base.Column
754+
Panel object containing four interactive altair plots.
755+
1. Plot of instantaneous firing rate and signal, primarily for zooming and navigating.
756+
2. Plot of instantaneous firing rate, which allows for peak selection.
757+
3. Plot of signal strength, which allows for peak selection.
758+
4. MUAP plot of individual motor unit shapes by channel, with selected peak overlay.
743759
"""
744760

745761
# Create widgets

0 commit comments

Comments
 (0)