API Reference
tmgtoolkit
plotting
plot_time_series(ax, y, t=None, **kwargs)
Generic function for plotting time series.
Plots the inputted time series signal(s) y on the inputted Matplotlib
axis ax. This function modifies ax directly and does not return a new
axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axis object on which to plot |
required |
y
|
ndarray
|
Numpy array holding the time series signal(s) to plot; |
required |
t
|
ndarray
|
1D Numpy array holding the time (or other independent variable) values
on which |
None
|
Keyword Arguments
xlabel : str
Label for x axis
ylabel : str
Label for y axis
title : str
Axis title
color : str or list
Color for the lines of plotted time series signal(s). If a list,
color should contain one exactly string color for every time series
in y.
linewidth : str or list
Width for the lines of plotted time series signal(s); str/list behavior
as for color.
marker : str or list
Marker for the lines of plotted time series signal(s); str/list behavior
as for color.
label : str or list
Human-readable label for the plotted time series signal(s); str/list
behavior as for color.
Source code in src/tmgtoolkit/plotting.py
8 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 38 39 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 | |
plot_spm_t_statistic(ax, t_statistic, alpha, threshold, clusters, t=None, **kwargs)
Plots an SPM t-statistic and accompanying inference results.
Plots the inputted SPM t-statistic curve t_statistic and a summary of the
accompanying inference results spm_ti on the inputted Matplotlib axes
object ax. This function modifies ax directly and does not return a new
axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axis object on which to plot |
required |
t_statistic
|
ndarray
|
1D Numpy array holding the SPM t-test statistic curve to be plotted |
required |
alpha
|
float
|
Alpha value used for SPM inference |
required |
threshold
|
float
|
Significance threshold value from SPM inference |
required |
clusters
|
list
|
|
required |
t
|
ndarray
|
1D Numpy array holding the time (or other independent variable) values
on which the SPM t-statistic curve |
None
|
Keyword Arguments
xlabel : str Label for x axis ylabel : str Label for y axis title : str Axis title color : str Color of the plotted t-statistic curve. color : str Color of the plotted t-statistic curve. marker : str Marker for the t-statistic curve. cluster_fillcolor : str Background color of suprathreshold significance clusters. threshold_color : str Color of the significance threshold line. threshold_linestyle : str Style of the significance threshold line.
Source code in src/tmgtoolkit/plotting.py
69 70 71 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 160 161 162 163 164 165 | |
plot_spm_input_data_lazy(ax, group1, group2, t=None, **kwargs)
Plots the data used to compute an SPM t-statistic.
Wrapper around plot_spm_input_data that takes care of computing mean and standard deviation for the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axis object on which to plot |
required |
group1
|
ndarray
|
2D Numpy array holding at least two time series, as documented in
|
required |
group2
|
ndarray
|
2D Numpy array holding at least two time series, as documented in
|
required |
t
|
ndarray
|
1D Numpy array holding the time (or other independent variable) values
on which the time series in |
None
|
Keyword Arguments
See plot_spm_input_data.
Source code in src/tmgtoolkit/plotting.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
plot_spm_input_data(ax, mean1, mean2, std1, std2, t=None, **kwargs)
Plots the data used to compute an SPM t-statistic.
Plots the mean value curve and standard deviation clouds of the data that
would be used as input to a function like spm.get_spm_t_statistic() to
compute an SPM t-statistic.
This function modifies ax directly and does not return a new axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axis object on which to plot |
required |
mean1
|
ndarray
|
1D Numpy array mean value curve of group 1 SPM input data.
See |
required |
mean2
|
ndarray
|
1D Numpy array mean value curve of group 2 SPM input data.
See |
required |
std1
|
ndarray
|
1D Numpy array standard deviation curve of group 1 SPM input data.
See |
required |
std2
|
ndarray
|
1D Numpy array standard deviation curve of group 2 SPM input data.
See |
required |
t
|
ndarray
|
1D Numpy array holding the time (or other independent variable) values
on which the time series in |
None
|
Keyword Arguments
xlabel : str
Label for x axis
ylabel : str
Label for y axis
title : str
Axis title
color1 : str
Color of the mean value line of the data in group1.
color2 : str
Color of the mean value line of the data in group2.
linewidth1 : str
Width of the mean value line of the data in group1.
linewidth2 : str
Width of the mean value line of the data in group2.
fillcolor1 : str
Fill color of the standard deviation cloud of the data in group1.
fillcolor2 : str
Fill color of the standard deviation cloud of the data in group2.
alpha1 : str
Alpha of the standard deviation cloud of the data in group1.
alpha2 : str
Alpha of the standard deviation cloud of the data in group2.
label1 : str
Human-readable label for the group1 data.
label2 : str
Human-readable label for the group2 data.
Source code in src/tmgtoolkit/plotting.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
spm
get_spm_t_statistic(group1, group2, mitigate_iir_filter_artefact=True, swap_groups=False)
Computes SPM t-test statistic for the inputted data.
Returns a dict containing the 1D SPM t-test statistic resulting from a
paired SPM t-test comparing the time series data in the inputted arrays
group1 and group2. The returned SPM t-statistic is implicitly defined
on the same time (or other independent variable) grid as the time series in
group1 and group2, but it is up to the calling code to keep track of
these time values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group1
|
ndarray
|
2D Numpy array holding at least two time series. Each of the time
series in |
required |
group2
|
ndarray
|
2D Numpy array holding at least two time series, to be compared to the
set of time series in |
required |
mitigate_iir_filter_artefact
|
bool
|
If True, passes data through |
True
|
swap_groups
|
bool
|
Controls the order in which |
False
|
Pre-Conditions
group1andgroup2must have the same shape—this is a requirement for further analysis by spm1d.- No row in
group1or ingroup2can have all equal values—this is to ensure there are no rows in the inputted data with zero variance, which would cause a divide by zero error when computing the SPM t-statistic. This is again a requirement for further analysis by spm1d.
Note on time values: although the time (or other independent variable)
values on which group1 and group2 are defined are not needed to compute
the SPM t-statistic, group1 and group2 should conceptually be defined
on the same time grid; this becomes relevant when performing inference on
the t-statistic returned by this function.
Returns:
| Name | Type | Description |
|---|---|---|
spm_ts |
dict
|
A dict dict holding the SPM t-test statistic curve produced by
comparing the time series data in the inputted arrays |
Source code in src/tmgtoolkit/spm.py
7 8 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 38 39 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
get_spm_t_inference(spm_ts, t=None, alpha=0.05, two_tailed=True)
Performs SPM inference on the inputted SPM t-statistic data.
Returns a dict holding the results of performing inference on the inputted
spm_ts dict at the Type I error level alpha.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spm_ts
|
dict
|
A dict of t-statistic results as returned by |
required |
t
|
ndarray
|
1D Numpy array holding the time (or other independent variable) values
on which the SPM t-statistic curve |
None
|
alpha
|
float
|
Type I error rate (probability of rejecting the null hypothesis given that it is true) when performing inference. |
0.05
|
two_tailed
|
bool
|
Whether to perform two-sided or one-sided inference. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
spm_t_inference |
dict
|
A dict produced by performing statistical inference on the SPM
t-statistic results in |
Source code in src/tmgtoolkit/spm.py
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 | |
time_series
get_tmg_parameters_of_time_series(y, t=None, ignore_maxima_with_idx_less_than=None, ignore_maxima_less_than=None, use_first_max_as_dm=False, interpolate_dm=False)
Returns TMG parameters for a time series.
Returns a dict holding the TMG parameters Dm, Td, Tc, Ts, and Tr for the
inputted time series y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
1D Numpy array holding the values of a time series signal. Typically this will be a TMG signal of muscle displacement measured with respect to time. |
required |
t
|
ndarray
|
1D Numpy array holding the time (or other independent variable) values
on which If provided, Suggestion: If you are computing the TMG parameters of a standard TMG
signal sampled at 1 kHz, you can leave |
None
|
ignore_maxima_with_idx_less_than
|
int
|
Ignore data points with index less than
|
None
|
ignore_maxima_less_than
|
float
|
Ignore data points with values less than |
None
|
use_first_max_as_dm
|
bool
|
If True, uses the first maximum meeting the criteria imposed by
|
False
|
interpolate_dm
|
bool
|
If True, uses interpolation to fine-tune the value of Dm beyond the
granularity of |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
params |
dict
|
A dict holding the computed TMG parameter values. The dict has the
following keys:
- |
Source code in src/tmgtoolkit/time_series.py
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 38 39 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 70 71 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 | |
get_derivative_of_time_series(y, t=None)
Returns the derivative of a time series.
Returns the derivative with respect to time of the inputted time series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
1D Numpy array holding the values of a time series signal, as for
|
required |
t
|
ndarray
|
1D Numpy array holding the time (or other independent variable) values
on which If provided, |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dydt |
ndarray
|
1D Numpy array holding the derivative of the inputted time series |
Source code in src/tmgtoolkit/time_series.py
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 | |
get_extremum_parameters_of_time_series(y, t=None)
Returns extremum parameters of a time series.
Returns a dict holding the maximum value, time of maximum value, minimum
value, and time of minimum value of the inputted time series y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
1D Numpy array holding the values of a time series signal, as for
|
required |
t
|
ndarray
|
1D Numpy array holding the time (or other independent variable) values
on which If provided, |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
params |
dict
|
A dict holding the computed parameter values. The dict has the
following keys:
- Note: the extremum values and their times are computed by interpolating
|
Source code in src/tmgtoolkit/time_series.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
tmgio
Functions for reading data from and writing data to measurement files, and for preprocessing of data read from measurement files in preparation for passing the data to analysis functions.
tmg_excel_to_ndarray(fname, skiprows=None, nrows=None, skipcols=None, ncols=None)
Extracts information in a TMG measurement Excel file.
Returns a TmgExcel dict holding the information in a standard-format TMG measurement Excel file, as produced by the official TMG measurement software distributed with the TMG S1 and S2 measurement systems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
string
|
Path to a TMG measurement Excel file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
data |
ndarray
|
2D Numpy array holding the TMG signals in the
inputted Excel file. Measurements are stored in columns, so that
|
Source code in src/tmgtoolkit/tmgio.py
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 38 39 40 41 42 | |
split_data_for_spm(data, numsets, n1, n2, split_mode, skiprows=0, nrows=None, equalize_columns=True)
Splits structured input data into groups for analysis with SPM.
Splits the time series in the inputted 2D array data into groups that can
then be compared to each other with SPM analysis. The function assumes
data has a well-defined structure, namely that the time series in data
are divided into numsets sets, where each set consists of n1
consecutive time series in Group 1 followed by n2 consecutive time series
in Group 2.
For conventional split modes splits data into an array of tuples
(group1, group2) tuples, with one tuple for each measurement set in
data.
For "all"-type split modes, splits data into two 2D arrays stored in a
single tuple (group1, group2).
For documentation of split modes see
constants.IoConstants.SPM_SPLIT_MODES.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
2D Numpy array holding time series data. The time series should be
stored in columns, so that |
required |
numsets
|
int
|
Number of sets in |
required |
n1
|
int
|
Number of Group 1 time series in each set. |
required |
n2
|
int
|
Number of Group 2 time series in each set. |
required |
skiprows
|
int
|
Skips the first |
0
|
split_mode
|
int
|
An symbolic constant from |
required |
nrows
|
int
|
If provided, return only the first |
None
|
equalize_columns
|
boolean
|
If True, all returned |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
data_tuples |
list
|
Array holding a |
data_tuple |
tuple
|
Tuple |
Source code in src/tmgtoolkit/tmgio.py
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 70 71 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 | |