rapidtide 3.0.10__py3-none-any.whl → 3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rapidtide/Colortables.py +492 -27
- rapidtide/OrthoImageItem.py +1053 -47
- rapidtide/RapidtideDataset.py +1533 -86
- rapidtide/_version.py +3 -3
- rapidtide/calccoherence.py +196 -29
- rapidtide/calcnullsimfunc.py +191 -40
- rapidtide/calcsimfunc.py +245 -42
- rapidtide/correlate.py +1210 -393
- rapidtide/data/examples/src/testLD +56 -0
- rapidtide/data/examples/src/testalign +1 -1
- rapidtide/data/examples/src/testdelayvar +0 -1
- rapidtide/data/examples/src/testfmri +19 -1
- rapidtide/data/examples/src/testglmfilt +5 -5
- rapidtide/data/examples/src/testhappy +30 -1
- rapidtide/data/examples/src/testppgproc +17 -0
- rapidtide/data/examples/src/testrolloff +11 -0
- rapidtide/data/models/model_cnn_pytorch/best_model.pth +0 -0
- rapidtide/data/models/model_cnn_pytorch/loss.png +0 -0
- rapidtide/data/models/model_cnn_pytorch/loss.txt +1 -0
- rapidtide/data/models/model_cnn_pytorch/model.pth +0 -0
- rapidtide/data/models/model_cnn_pytorch/model_meta.json +68 -0
- rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin2009cAsym_2mm.nii.gz +0 -0
- rapidtide/data/reference/JHU-ArterialTerritoriesNoVent-LVL1_space-MNI152NLin2009cAsym_2mm_mask.nii.gz +0 -0
- rapidtide/decorators.py +91 -0
- rapidtide/dlfilter.py +2225 -108
- rapidtide/dlfiltertorch.py +4843 -0
- rapidtide/externaltools.py +327 -12
- rapidtide/fMRIData_class.py +79 -40
- rapidtide/filter.py +1899 -810
- rapidtide/fit.py +2004 -574
- rapidtide/genericmultiproc.py +93 -18
- rapidtide/happy_supportfuncs.py +2044 -171
- rapidtide/helper_classes.py +584 -43
- rapidtide/io.py +2363 -370
- rapidtide/linfitfiltpass.py +341 -75
- rapidtide/makelaggedtcs.py +211 -20
- rapidtide/maskutil.py +423 -53
- rapidtide/miscmath.py +827 -121
- rapidtide/multiproc.py +210 -22
- rapidtide/patchmatch.py +234 -33
- rapidtide/peakeval.py +32 -30
- rapidtide/ppgproc.py +2203 -0
- rapidtide/qualitycheck.py +352 -39
- rapidtide/refinedelay.py +422 -57
- rapidtide/refineregressor.py +498 -184
- rapidtide/resample.py +671 -185
- rapidtide/scripts/applyppgproc.py +28 -0
- rapidtide/simFuncClasses.py +1052 -77
- rapidtide/simfuncfit.py +260 -46
- rapidtide/stats.py +540 -238
- rapidtide/tests/happycomp +9 -0
- rapidtide/tests/test_dlfiltertorch.py +627 -0
- rapidtide/tests/test_findmaxlag.py +24 -8
- rapidtide/tests/test_fullrunhappy_v1.py +0 -2
- rapidtide/tests/test_fullrunhappy_v2.py +0 -2
- rapidtide/tests/test_fullrunhappy_v3.py +1 -0
- rapidtide/tests/test_fullrunhappy_v4.py +2 -2
- rapidtide/tests/test_fullrunrapidtide_v7.py +1 -1
- rapidtide/tests/test_simroundtrip.py +8 -8
- rapidtide/tests/utils.py +9 -8
- rapidtide/tidepoolTemplate.py +142 -38
- rapidtide/tidepoolTemplate_alt.py +165 -44
- rapidtide/tidepoolTemplate_big.py +189 -52
- rapidtide/util.py +1217 -118
- rapidtide/voxelData.py +684 -37
- rapidtide/wiener.py +19 -12
- rapidtide/wiener2.py +113 -7
- rapidtide/wiener_doc.py +255 -0
- rapidtide/workflows/adjustoffset.py +105 -3
- rapidtide/workflows/aligntcs.py +85 -2
- rapidtide/workflows/applydlfilter.py +87 -10
- rapidtide/workflows/applyppgproc.py +522 -0
- rapidtide/workflows/atlasaverage.py +210 -47
- rapidtide/workflows/atlastool.py +100 -3
- rapidtide/workflows/calcSimFuncMap.py +294 -64
- rapidtide/workflows/calctexticc.py +201 -9
- rapidtide/workflows/ccorrica.py +97 -4
- rapidtide/workflows/cleanregressor.py +168 -29
- rapidtide/workflows/delayvar.py +163 -10
- rapidtide/workflows/diffrois.py +81 -3
- rapidtide/workflows/endtidalproc.py +144 -4
- rapidtide/workflows/fdica.py +195 -15
- rapidtide/workflows/filtnifti.py +70 -3
- rapidtide/workflows/filttc.py +74 -3
- rapidtide/workflows/fitSimFuncMap.py +206 -48
- rapidtide/workflows/fixtr.py +73 -3
- rapidtide/workflows/gmscalc.py +113 -3
- rapidtide/workflows/happy.py +813 -201
- rapidtide/workflows/happy2std.py +144 -12
- rapidtide/workflows/happy_parser.py +149 -8
- rapidtide/workflows/histnifti.py +118 -2
- rapidtide/workflows/histtc.py +84 -3
- rapidtide/workflows/linfitfilt.py +117 -4
- rapidtide/workflows/localflow.py +328 -28
- rapidtide/workflows/mergequality.py +79 -3
- rapidtide/workflows/niftidecomp.py +322 -18
- rapidtide/workflows/niftistats.py +174 -4
- rapidtide/workflows/pairproc.py +88 -2
- rapidtide/workflows/pairwisemergenifti.py +85 -2
- rapidtide/workflows/parser_funcs.py +1421 -40
- rapidtide/workflows/physiofreq.py +137 -11
- rapidtide/workflows/pixelcomp.py +208 -5
- rapidtide/workflows/plethquality.py +103 -21
- rapidtide/workflows/polyfitim.py +151 -11
- rapidtide/workflows/proj2flow.py +75 -2
- rapidtide/workflows/rankimage.py +111 -4
- rapidtide/workflows/rapidtide.py +272 -15
- rapidtide/workflows/rapidtide2std.py +98 -2
- rapidtide/workflows/rapidtide_parser.py +109 -9
- rapidtide/workflows/refineDelayMap.py +143 -33
- rapidtide/workflows/refineRegressor.py +682 -93
- rapidtide/workflows/regressfrommaps.py +152 -31
- rapidtide/workflows/resamplenifti.py +85 -3
- rapidtide/workflows/resampletc.py +91 -3
- rapidtide/workflows/retrolagtcs.py +98 -6
- rapidtide/workflows/retroregress.py +165 -9
- rapidtide/workflows/roisummarize.py +173 -5
- rapidtide/workflows/runqualitycheck.py +71 -3
- rapidtide/workflows/showarbcorr.py +147 -4
- rapidtide/workflows/showhist.py +86 -2
- rapidtide/workflows/showstxcorr.py +160 -3
- rapidtide/workflows/showtc.py +159 -3
- rapidtide/workflows/showxcorrx.py +184 -4
- rapidtide/workflows/showxy.py +185 -15
- rapidtide/workflows/simdata.py +262 -36
- rapidtide/workflows/spatialfit.py +77 -2
- rapidtide/workflows/spatialmi.py +251 -27
- rapidtide/workflows/spectrogram.py +305 -32
- rapidtide/workflows/synthASL.py +154 -3
- rapidtide/workflows/tcfrom2col.py +76 -2
- rapidtide/workflows/tcfrom3col.py +74 -2
- rapidtide/workflows/tidepool.py +2972 -133
- rapidtide/workflows/utils.py +19 -14
- rapidtide/workflows/utils_doc.py +293 -0
- rapidtide/workflows/variabilityizer.py +116 -3
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/METADATA +10 -9
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/RECORD +141 -122
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/entry_points.txt +1 -0
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/WHEEL +0 -0
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/licenses/LICENSE +0 -0
- {rapidtide-3.0.10.dist-info → rapidtide-3.1.dist-info}/top_level.txt +0 -0
|
@@ -18,8 +18,11 @@
|
|
|
18
18
|
#
|
|
19
19
|
import argparse
|
|
20
20
|
import sys
|
|
21
|
+
from argparse import Namespace
|
|
22
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
21
23
|
|
|
22
24
|
import numpy as np
|
|
25
|
+
from numpy.typing import NDArray
|
|
23
26
|
from scipy.stats import pearsonr
|
|
24
27
|
|
|
25
28
|
import rapidtide.correlate as tide_corr
|
|
@@ -29,9 +32,34 @@ import rapidtide.simFuncClasses as tide_simFuncClasses
|
|
|
29
32
|
import rapidtide.workflows.parser_funcs as pf
|
|
30
33
|
|
|
31
34
|
|
|
32
|
-
def _get_parser():
|
|
35
|
+
def _get_parser() -> Any:
|
|
33
36
|
"""
|
|
34
|
-
Argument parser for showarbcorr
|
|
37
|
+
Argument parser for showarbcorr.
|
|
38
|
+
|
|
39
|
+
This function constructs and returns an `argparse.ArgumentParser` object configured
|
|
40
|
+
for the `showarbcorr` command-line tool. It defines required and optional arguments
|
|
41
|
+
for calculating and displaying crosscorrelation between two time series, supporting
|
|
42
|
+
variable lengths and sampling frequencies.
|
|
43
|
+
|
|
44
|
+
Returns
|
|
45
|
+
-------
|
|
46
|
+
argparse.ArgumentParser
|
|
47
|
+
Configured argument parser for `showarbcorr`.
|
|
48
|
+
|
|
49
|
+
Notes
|
|
50
|
+
-----
|
|
51
|
+
The parser includes groups for:
|
|
52
|
+
- Required input files
|
|
53
|
+
- Optional arguments (e.g., sample rates, display control)
|
|
54
|
+
- Preprocessing options (e.g., detrending, correlation weighting)
|
|
55
|
+
- Filtering and windowing options
|
|
56
|
+
- Output configuration (e.g., files for results, plots)
|
|
57
|
+
- Miscellaneous settings (e.g., multiprocessing, progress bar)
|
|
58
|
+
|
|
59
|
+
Examples
|
|
60
|
+
--------
|
|
61
|
+
>>> parser = _get_parser()
|
|
62
|
+
>>> args = parser.parse_args()
|
|
35
63
|
"""
|
|
36
64
|
parser = argparse.ArgumentParser(
|
|
37
65
|
prog="showarbcorr",
|
|
@@ -240,13 +268,128 @@ def _get_parser():
|
|
|
240
268
|
return parser
|
|
241
269
|
|
|
242
270
|
|
|
243
|
-
def printthresholds(pcts, thepercentiles, labeltext):
|
|
271
|
+
def printthresholds(pcts: Any, thepercentiles: Any, labeltext: Any) -> None:
|
|
272
|
+
"""
|
|
273
|
+
Print thresholds with corresponding percentile labels.
|
|
274
|
+
|
|
275
|
+
This function prints a formatted list of thresholds along with their
|
|
276
|
+
corresponding percentile labels for statistical analysis output.
|
|
277
|
+
|
|
278
|
+
Parameters
|
|
279
|
+
----------
|
|
280
|
+
pcts : Any
|
|
281
|
+
Array or list of threshold values to be printed.
|
|
282
|
+
thepercentiles : Any
|
|
283
|
+
Array or list of percentile values corresponding to the thresholds.
|
|
284
|
+
labeltext : Any
|
|
285
|
+
Text label to be printed before the threshold list.
|
|
286
|
+
|
|
287
|
+
Returns
|
|
288
|
+
-------
|
|
289
|
+
None
|
|
290
|
+
This function prints to standard output and does not return any value.
|
|
291
|
+
|
|
292
|
+
Notes
|
|
293
|
+
-----
|
|
294
|
+
The function formats the percentile values as "1.0 - thepercentiles[i]"
|
|
295
|
+
to show the alpha level (significance threshold) for each percentile.
|
|
296
|
+
|
|
297
|
+
Examples
|
|
298
|
+
--------
|
|
299
|
+
>>> pcts = [0.05, 0.01, 0.001]
|
|
300
|
+
>>> thepercentiles = [0.95, 0.99, 0.999]
|
|
301
|
+
>>> labeltext = "Critical Values:"
|
|
302
|
+
>>> printthresholds(pcts, thepercentiles, labeltext)
|
|
303
|
+
Critical Values:
|
|
304
|
+
p < 0.050 : 0.05
|
|
305
|
+
p < 0.010 : 0.01
|
|
306
|
+
p < 0.001 : 0.001
|
|
307
|
+
"""
|
|
244
308
|
print(labeltext)
|
|
245
309
|
for i in range(0, len(pcts)):
|
|
246
310
|
print("\tp <", "{:.3f}".format(1.0 - thepercentiles[i]), ": ", pcts[i])
|
|
247
311
|
|
|
248
312
|
|
|
249
|
-
def showarbcorr(args):
|
|
313
|
+
def showarbcorr(args: Any) -> None:
|
|
314
|
+
"""
|
|
315
|
+
Compute and display cross-correlation between two time series with optional filtering and plotting.
|
|
316
|
+
|
|
317
|
+
This function reads two time series from text files, matches their sampling rates, applies
|
|
318
|
+
optional filtering, and computes the cross-correlation. It supports various options for
|
|
319
|
+
data trimming, inversion, and output formatting, including optional visualization and
|
|
320
|
+
correlation fitting.
|
|
321
|
+
|
|
322
|
+
Parameters
|
|
323
|
+
----------
|
|
324
|
+
args : Any
|
|
325
|
+
An object containing command-line arguments and configuration options. Expected
|
|
326
|
+
attributes include:
|
|
327
|
+
- infilename1, infilename2 : str
|
|
328
|
+
Paths to input text files containing the two time series.
|
|
329
|
+
- samplerate1, samplerate2 : float, optional
|
|
330
|
+
Sampling rates for the two time series. If not provided, they are inferred
|
|
331
|
+
from the input files.
|
|
332
|
+
- start1, start2 : float, optional
|
|
333
|
+
Start times for the two time series.
|
|
334
|
+
- trimdata : bool
|
|
335
|
+
If True, trim the data to the shorter of the two time series.
|
|
336
|
+
- invert : bool
|
|
337
|
+
If True, invert the second time series before correlation.
|
|
338
|
+
- windowfunc : str, optional
|
|
339
|
+
Window function to apply during correlation normalization.
|
|
340
|
+
- detrendorder : int, optional
|
|
341
|
+
Order of detrending to apply before correlation.
|
|
342
|
+
- display : bool
|
|
343
|
+
If True, display the cross-correlation plot.
|
|
344
|
+
- graphfile : str, optional
|
|
345
|
+
Output filename for saving the plot.
|
|
346
|
+
- label : str, optional
|
|
347
|
+
Label to use in output.
|
|
348
|
+
- lagmin, lagmax : float
|
|
349
|
+
Minimum and maximum lags (in seconds) to consider in the correlation.
|
|
350
|
+
- debug : bool
|
|
351
|
+
If True, enable debug output.
|
|
352
|
+
- bipolar : bool
|
|
353
|
+
If True, fit the peak using bipolar symmetry.
|
|
354
|
+
- summarymode : bool
|
|
355
|
+
If True, output results in a tab-separated summary format.
|
|
356
|
+
- outputfile : str, optional
|
|
357
|
+
File to write summary output.
|
|
358
|
+
- corroutputfile : str, optional
|
|
359
|
+
File to write full cross-correlation data.
|
|
360
|
+
- verbose : bool
|
|
361
|
+
If True, print verbose messages.
|
|
362
|
+
|
|
363
|
+
Returns
|
|
364
|
+
-------
|
|
365
|
+
None
|
|
366
|
+
This function does not return a value but may produce plots, print outputs,
|
|
367
|
+
and write files depending on the provided arguments.
|
|
368
|
+
|
|
369
|
+
Notes
|
|
370
|
+
-----
|
|
371
|
+
- The function uses `tide_io.readvectorsfromtextfile` to read input data.
|
|
372
|
+
- Filtering is applied via `tide_math.corrnormalize` and `theprefilter.apply`.
|
|
373
|
+
- Cross-correlation is computed using `tide_corr.arbcorr`.
|
|
374
|
+
- A peak-fitting procedure is used to refine the maximum correlation lag.
|
|
375
|
+
- If `summarymode` is True, output is written in tab-separated format to stdout or a file.
|
|
376
|
+
|
|
377
|
+
Examples
|
|
378
|
+
--------
|
|
379
|
+
>>> import argparse
|
|
380
|
+
>>> args = argparse.Namespace(
|
|
381
|
+
... infilename1="data1.txt",
|
|
382
|
+
... infilename2="data2.txt",
|
|
383
|
+
... samplerate1=10.0,
|
|
384
|
+
... samplerate2=10.0,
|
|
385
|
+
... display=True,
|
|
386
|
+
... lagmin=-5.0,
|
|
387
|
+
... lagmax=5.0,
|
|
388
|
+
... windowfunc="hanning",
|
|
389
|
+
... debug=False
|
|
390
|
+
... )
|
|
391
|
+
>>> showarbcorr(args)
|
|
392
|
+
"""
|
|
250
393
|
# set some default values
|
|
251
394
|
absmaxsigma = 1000.0
|
|
252
395
|
absminsigma = 0.25
|
rapidtide/workflows/showhist.py
CHANGED
|
@@ -17,15 +17,44 @@
|
|
|
17
17
|
#
|
|
18
18
|
#
|
|
19
19
|
import argparse
|
|
20
|
+
from argparse import Namespace
|
|
21
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
20
22
|
|
|
21
23
|
import numpy as np
|
|
22
24
|
from matplotlib.pyplot import bar, legend, plot, savefig, show, title, xlabel, ylabel
|
|
25
|
+
from numpy.typing import NDArray
|
|
23
26
|
|
|
24
27
|
import rapidtide.io as tide_io
|
|
25
28
|
import rapidtide.stats as tide_stats
|
|
26
29
|
|
|
27
30
|
|
|
28
|
-
def _get_parser():
|
|
31
|
+
def _get_parser() -> Any:
|
|
32
|
+
"""
|
|
33
|
+
Create and configure an argument parser for the showhist command-line tool.
|
|
34
|
+
|
|
35
|
+
This function sets up an `argparse.ArgumentParser` with specific arguments
|
|
36
|
+
to control the behavior of the histogram plotting script. It defines
|
|
37
|
+
required and optional parameters for input file, axis labels, title,
|
|
38
|
+
output file, plot style, and debugging options.
|
|
39
|
+
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
argparse.ArgumentParser
|
|
43
|
+
Configured argument parser object with defined arguments for
|
|
44
|
+
controlling histogram plotting behavior.
|
|
45
|
+
|
|
46
|
+
Notes
|
|
47
|
+
-----
|
|
48
|
+
The parser is configured with `allow_abbrev=False` to prevent
|
|
49
|
+
abbreviated argument names from being accepted.
|
|
50
|
+
|
|
51
|
+
Examples
|
|
52
|
+
--------
|
|
53
|
+
>>> parser = _get_parser()
|
|
54
|
+
>>> args = parser.parse_args(['data.txt'])
|
|
55
|
+
>>> print(args.infilename)
|
|
56
|
+
'data.txt'
|
|
57
|
+
"""
|
|
29
58
|
# get the command line parameters
|
|
30
59
|
parser = argparse.ArgumentParser(
|
|
31
60
|
prog="showhist",
|
|
@@ -90,7 +119,62 @@ def _get_parser():
|
|
|
90
119
|
return parser
|
|
91
120
|
|
|
92
121
|
|
|
93
|
-
def showhist(args):
|
|
122
|
+
def showhist(args: Any) -> None:
|
|
123
|
+
"""
|
|
124
|
+
Display or save a histogram or line plot based on input data and arguments.
|
|
125
|
+
|
|
126
|
+
This function reads data from a specified input file, computes a histogram if
|
|
127
|
+
requested, and visualizes the results using matplotlib. The plot can be displayed
|
|
128
|
+
on screen or saved to a file depending on the provided arguments.
|
|
129
|
+
|
|
130
|
+
Parameters
|
|
131
|
+
----------
|
|
132
|
+
args : Any
|
|
133
|
+
An object containing the following attributes:
|
|
134
|
+
- infilename : str
|
|
135
|
+
Path to the input file containing data to be plotted.
|
|
136
|
+
- debug : bool
|
|
137
|
+
If True, prints the args object for debugging purposes.
|
|
138
|
+
- calcdist : bool
|
|
139
|
+
If True, computes a histogram from the input data.
|
|
140
|
+
- dobars : bool
|
|
141
|
+
If True, displays the histogram as bars; otherwise, as a line plot.
|
|
142
|
+
- thetitle : str, optional
|
|
143
|
+
Title for the plot.
|
|
144
|
+
- thexlabel : str, optional
|
|
145
|
+
Label for the x-axis.
|
|
146
|
+
- theylabel : str, optional
|
|
147
|
+
Label for the y-axis.
|
|
148
|
+
- outputfile : str, optional
|
|
149
|
+
Path to save the plot. If None, the plot is displayed on screen.
|
|
150
|
+
|
|
151
|
+
Returns
|
|
152
|
+
-------
|
|
153
|
+
None
|
|
154
|
+
This function does not return any value. It either displays the plot
|
|
155
|
+
or saves it to a file.
|
|
156
|
+
|
|
157
|
+
Notes
|
|
158
|
+
-----
|
|
159
|
+
- The function uses `tide_io.readvecs` to read input data.
|
|
160
|
+
- If `calcdist` is True, `tide_stats.makehistogram` is used to compute the histogram.
|
|
161
|
+
- The histogram is displayed as either bars or a line, depending on the `dobars` flag.
|
|
162
|
+
- If `outputfile` is provided, the plot is saved using `savefig`; otherwise, `show()` is called.
|
|
163
|
+
|
|
164
|
+
Examples
|
|
165
|
+
--------
|
|
166
|
+
>>> args = type('Args', (), {
|
|
167
|
+
... 'infilename': 'data.txt',
|
|
168
|
+
... 'debug': False,
|
|
169
|
+
... 'calcdist': True,
|
|
170
|
+
... 'dobars': True,
|
|
171
|
+
... 'thetitle': 'Sample Histogram',
|
|
172
|
+
... 'thexlabel': 'Values',
|
|
173
|
+
... 'theylabel': 'Frequency',
|
|
174
|
+
... 'outputfile': 'output.png'
|
|
175
|
+
... })()
|
|
176
|
+
>>> showhist(args)
|
|
177
|
+
"""
|
|
94
178
|
if args.debug:
|
|
95
179
|
print(args)
|
|
96
180
|
if args.calcdist:
|
|
@@ -18,11 +18,14 @@
|
|
|
18
18
|
#
|
|
19
19
|
import argparse
|
|
20
20
|
import sys
|
|
21
|
+
from argparse import Namespace
|
|
22
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
21
23
|
|
|
22
24
|
import nibabel as nib
|
|
23
25
|
import numpy as np
|
|
24
26
|
import pandas as pd
|
|
25
27
|
from numpy.polynomial import Polynomial
|
|
28
|
+
from numpy.typing import NDArray
|
|
26
29
|
|
|
27
30
|
import rapidtide.correlate as tide_corr
|
|
28
31
|
import rapidtide.fit as tide_fit
|
|
@@ -32,7 +35,36 @@ import rapidtide.resample as tide_resamp
|
|
|
32
35
|
import rapidtide.workflows.parser_funcs as pf
|
|
33
36
|
|
|
34
37
|
|
|
35
|
-
def _get_parser():
|
|
38
|
+
def _get_parser() -> Any:
|
|
39
|
+
"""
|
|
40
|
+
Create and configure an argument parser for the showstxcorr tool.
|
|
41
|
+
|
|
42
|
+
This function sets up an `argparse.ArgumentParser` with various required and
|
|
43
|
+
optional arguments to control the behavior of the cross-correlation plotting
|
|
44
|
+
tool. It includes options for input files, sampling parameters, correlation
|
|
45
|
+
settings, display control, and preprocessing steps.
|
|
46
|
+
|
|
47
|
+
Returns
|
|
48
|
+
-------
|
|
49
|
+
argparse.ArgumentParser
|
|
50
|
+
Configured argument parser object with all necessary arguments added.
|
|
51
|
+
|
|
52
|
+
Notes
|
|
53
|
+
-----
|
|
54
|
+
The parser is configured with:
|
|
55
|
+
- Two required input text files (`infilename1`, `infilename2`)
|
|
56
|
+
- Output filename root
|
|
57
|
+
- Sampling rate or time step options (mutually exclusive)
|
|
58
|
+
- Correlation threshold and window parameters
|
|
59
|
+
- Time range and display options
|
|
60
|
+
- Preprocessing options like detrending and correlation weighting
|
|
61
|
+
- Filtering and windowing options
|
|
62
|
+
|
|
63
|
+
Examples
|
|
64
|
+
--------
|
|
65
|
+
>>> parser = _get_parser()
|
|
66
|
+
>>> args = parser.parse_args()
|
|
67
|
+
"""
|
|
36
68
|
parser = argparse.ArgumentParser(
|
|
37
69
|
prog="showstxcorr",
|
|
38
70
|
description="Plots the data in text files.",
|
|
@@ -187,13 +219,138 @@ def _get_parser():
|
|
|
187
219
|
return parser
|
|
188
220
|
|
|
189
221
|
|
|
190
|
-
def printthresholds(pcts, thepercentiles, labeltext):
|
|
222
|
+
def printthresholds(pcts: Any, thepercentiles: Any, labeltext: Any) -> None:
|
|
223
|
+
"""
|
|
224
|
+
Print thresholds with corresponding percentile values.
|
|
225
|
+
|
|
226
|
+
This function prints a formatted list of thresholds where each threshold
|
|
227
|
+
corresponds to a specific percentile. The output shows the probability
|
|
228
|
+
threshold for which the percentile is less than the given value.
|
|
229
|
+
|
|
230
|
+
Parameters
|
|
231
|
+
----------
|
|
232
|
+
pcts : Any
|
|
233
|
+
Array-like object containing the percentile values to be printed.
|
|
234
|
+
thepercentiles : Any
|
|
235
|
+
Array-like object containing the corresponding percentile thresholds.
|
|
236
|
+
labeltext : Any
|
|
237
|
+
Text label to be printed before the threshold values.
|
|
238
|
+
|
|
239
|
+
Returns
|
|
240
|
+
-------
|
|
241
|
+
None
|
|
242
|
+
This function prints to stdout and does not return any value.
|
|
243
|
+
|
|
244
|
+
Notes
|
|
245
|
+
-----
|
|
246
|
+
The function assumes that both `pcts` and `thepercentiles` have the same length
|
|
247
|
+
and that the percentiles are ordered in ascending order.
|
|
248
|
+
|
|
249
|
+
Examples
|
|
250
|
+
--------
|
|
251
|
+
>>> pcts = [0.05, 0.01, 0.001]
|
|
252
|
+
>>> thepercentiles = [0.95, 0.99, 0.999]
|
|
253
|
+
>>> labeltext = "Significance thresholds:"
|
|
254
|
+
>>> printthresholds(pcts, thepercentiles, labeltext)
|
|
255
|
+
Significance thresholds:
|
|
256
|
+
p < 0.05 : 0.05
|
|
257
|
+
p < 0.01 : 0.01
|
|
258
|
+
p < 0.001 : 0.001
|
|
259
|
+
"""
|
|
191
260
|
print(labeltext)
|
|
192
261
|
for i in range(0, len(pcts)):
|
|
193
262
|
print("\tp <", 1.0 - thepercentiles[i], ": ", pcts[i])
|
|
194
263
|
|
|
195
264
|
|
|
196
|
-
def showstxcorr(args):
|
|
265
|
+
def showstxcorr(args: Any) -> None:
|
|
266
|
+
"""
|
|
267
|
+
Compute and display short-term cross-correlations between two time series.
|
|
268
|
+
|
|
269
|
+
This function performs short-term cross-correlation analysis on two input time series,
|
|
270
|
+
applying optional filtering, detrending, and time-warping. It supports both single
|
|
271
|
+
correlation output and matrix output modes, and can generate plots and save results
|
|
272
|
+
to files.
|
|
273
|
+
|
|
274
|
+
Parameters
|
|
275
|
+
----------
|
|
276
|
+
args : argparse.Namespace
|
|
277
|
+
Command-line arguments containing the following attributes:
|
|
278
|
+
- infilename1 : str
|
|
279
|
+
Path to the first input file.
|
|
280
|
+
- infilename2 : str
|
|
281
|
+
Path to the second input file.
|
|
282
|
+
- samplerate : float or str
|
|
283
|
+
Sampling rate of the data. Must be set if 'auto'.
|
|
284
|
+
- starttime : float
|
|
285
|
+
Start time for data trimming.
|
|
286
|
+
- duration : float
|
|
287
|
+
Duration of the data to process.
|
|
288
|
+
- stepsize : float
|
|
289
|
+
Step size for correlation computation.
|
|
290
|
+
- windowwidth : float
|
|
291
|
+
Width of the analysis window in seconds.
|
|
292
|
+
- lagmin : float
|
|
293
|
+
Minimum lag for correlation search.
|
|
294
|
+
- lagmax : float
|
|
295
|
+
Maximum lag for correlation search.
|
|
296
|
+
- corrweighting : str
|
|
297
|
+
Type of weighting for correlation.
|
|
298
|
+
- windowfunc : str
|
|
299
|
+
Window function to apply.
|
|
300
|
+
- detrendorder : int
|
|
301
|
+
Order of detrending to apply.
|
|
302
|
+
- invert : bool
|
|
303
|
+
Whether to invert the second signal.
|
|
304
|
+
- display : bool
|
|
305
|
+
Whether to display plots.
|
|
306
|
+
- debug : bool
|
|
307
|
+
Whether to enable debug output.
|
|
308
|
+
- outfilename : str
|
|
309
|
+
Base name for output files.
|
|
310
|
+
- corrthresh : float
|
|
311
|
+
Threshold for correlation significance.
|
|
312
|
+
- filter : dict
|
|
313
|
+
Filter parameters.
|
|
314
|
+
|
|
315
|
+
Returns
|
|
316
|
+
-------
|
|
317
|
+
None
|
|
318
|
+
This function does not return a value but saves output files and displays plots
|
|
319
|
+
if requested.
|
|
320
|
+
|
|
321
|
+
Notes
|
|
322
|
+
-----
|
|
323
|
+
The function applies a prefilter to the data and trims the input time series to
|
|
324
|
+
the specified duration. It supports both single correlation and matrix correlation
|
|
325
|
+
modes. In matrix mode, all components are correlated against each other and
|
|
326
|
+
results are saved to NIfTI files and CSV tables. In single mode, correlations are
|
|
327
|
+
computed between two time series and results are saved to text files.
|
|
328
|
+
|
|
329
|
+
Examples
|
|
330
|
+
--------
|
|
331
|
+
>>> import argparse
|
|
332
|
+
>>> args = argparse.Namespace(
|
|
333
|
+
... infilename1='data1.txt',
|
|
334
|
+
... infilename2='data2.txt',
|
|
335
|
+
... samplerate=100,
|
|
336
|
+
... starttime=0,
|
|
337
|
+
... duration=1000,
|
|
338
|
+
... stepsize=10,
|
|
339
|
+
... windowwidth=20,
|
|
340
|
+
... lagmin=-5,
|
|
341
|
+
... lagmax=5,
|
|
342
|
+
... corrweighting='uniform',
|
|
343
|
+
... windowfunc='hanning',
|
|
344
|
+
... detrendorder=1,
|
|
345
|
+
... invert=False,
|
|
346
|
+
... display=False,
|
|
347
|
+
... debug=False,
|
|
348
|
+
... outfilename='output',
|
|
349
|
+
... corrthresh=0.3,
|
|
350
|
+
... filter={}
|
|
351
|
+
... )
|
|
352
|
+
>>> showstxcorr(args)
|
|
353
|
+
"""
|
|
197
354
|
# get the command line parameters
|
|
198
355
|
verbose = True
|
|
199
356
|
matrixoutput = False
|
rapidtide/workflows/showtc.py
CHANGED
|
@@ -21,10 +21,12 @@ import warnings
|
|
|
21
21
|
warnings.simplefilter(action="ignore", category=FutureWarning)
|
|
22
22
|
import argparse
|
|
23
23
|
import sys
|
|
24
|
+
from argparse import Namespace
|
|
24
25
|
|
|
25
26
|
import matplotlib.cm as cm
|
|
26
27
|
import numpy as np
|
|
27
28
|
from matplotlib.pyplot import figure, savefig, setp, show
|
|
29
|
+
from numpy.typing import NDArray
|
|
28
30
|
|
|
29
31
|
import rapidtide.filter as tide_filt
|
|
30
32
|
import rapidtide.fit as tide_fit
|
|
@@ -41,11 +43,79 @@ except ImportError:
|
|
|
41
43
|
haveseaborn = False
|
|
42
44
|
|
|
43
45
|
|
|
44
|
-
def phase(mcv):
|
|
46
|
+
def phase(mcv: NDArray[np.complex128]) -> NDArray[np.float64]:
|
|
47
|
+
"""
|
|
48
|
+
Compute the phase angle of complex numbers.
|
|
49
|
+
|
|
50
|
+
This function calculates the phase angle (also known as the argument) of complex numbers
|
|
51
|
+
using the arctan2 function, which correctly handles all quadrants and avoids division
|
|
52
|
+
by zero errors that could occur with the standard arctan function.
|
|
53
|
+
|
|
54
|
+
Parameters
|
|
55
|
+
----------
|
|
56
|
+
mcv : ndarray of complex128
|
|
57
|
+
Input array of complex numbers for which to compute the phase angles.
|
|
58
|
+
|
|
59
|
+
Returns
|
|
60
|
+
-------
|
|
61
|
+
ndarray of float64
|
|
62
|
+
Array of phase angles in radians, with values in the range [-π, π].
|
|
63
|
+
The phase angle is computed as atan2(imaginary_part, real_part).
|
|
64
|
+
|
|
65
|
+
Notes
|
|
66
|
+
-----
|
|
67
|
+
The phase angle is computed using `np.arctan2(mcv.imag, mcv.real)` which correctly
|
|
68
|
+
handles the quadrant determination and avoids ambiguity that would occur with
|
|
69
|
+
`np.arctan(mcv.imag / mcv.real)`.
|
|
70
|
+
|
|
71
|
+
Examples
|
|
72
|
+
--------
|
|
73
|
+
>>> import numpy as np
|
|
74
|
+
>>> z = np.array([1+0j, 0+1j, -1+0j, 0-1j])
|
|
75
|
+
>>> phase(z)
|
|
76
|
+
array([ 0. , 1.57079633, 3.14159265, -1.57079633])
|
|
77
|
+
|
|
78
|
+
>>> z = np.array([1+1j, -1+1j, -1-1j, 1-1j])
|
|
79
|
+
>>> phase(z)
|
|
80
|
+
array([ 0.78539816, 2.35619449, -2.35619449, -0.78539816])
|
|
81
|
+
"""
|
|
45
82
|
return np.arctan2(mcv.imag, mcv.real)
|
|
46
83
|
|
|
47
84
|
|
|
48
|
-
def _get_parser():
|
|
85
|
+
def _get_parser() -> argparse.ArgumentParser:
|
|
86
|
+
"""
|
|
87
|
+
Create and configure an argument parser for the showtc command-line tool.
|
|
88
|
+
|
|
89
|
+
This function constructs an `argparse.ArgumentParser` object with a set of
|
|
90
|
+
predefined arguments for plotting data from text files. It supports various
|
|
91
|
+
display modes, sampling options, and plotting configurations.
|
|
92
|
+
|
|
93
|
+
Returns
|
|
94
|
+
-------
|
|
95
|
+
argparse.ArgumentParser
|
|
96
|
+
Configured argument parser for the showtc tool.
|
|
97
|
+
|
|
98
|
+
Notes
|
|
99
|
+
-----
|
|
100
|
+
The parser includes support for:
|
|
101
|
+
|
|
102
|
+
- Input file specification with optional column selections
|
|
103
|
+
- Sampling rate or sample time configuration
|
|
104
|
+
- Display mode options: time series, power spectrum, or phase spectrum
|
|
105
|
+
- Plot format options: overlaid, separate, or separately linked
|
|
106
|
+
- Waterfall plotting for multiple timecourses
|
|
107
|
+
- Data normalization and transposition
|
|
108
|
+
- Plot appearance customization via `pf.addplotopts`
|
|
109
|
+
- Time range selection and header skipping
|
|
110
|
+
- Debugging and version information
|
|
111
|
+
|
|
112
|
+
Examples
|
|
113
|
+
--------
|
|
114
|
+
>>> parser = _get_parser()
|
|
115
|
+
>>> args = parser.parse_args(['file1.txt', 'file2.txt'])
|
|
116
|
+
>>> print(args.textfilenames)
|
|
117
|
+
['file1.txt', 'file2.txt']
|
|
118
|
+
"""
|
|
49
119
|
parser = argparse.ArgumentParser(
|
|
50
120
|
prog="showtc",
|
|
51
121
|
description="Plots the data in text files.",
|
|
@@ -186,7 +256,93 @@ def _get_parser():
|
|
|
186
256
|
return parser
|
|
187
257
|
|
|
188
258
|
|
|
189
|
-
def showtc(args):
|
|
259
|
+
def showtc(args: Namespace) -> None:
|
|
260
|
+
"""
|
|
261
|
+
Display time series or spectral data from text files with customizable plotting options.
|
|
262
|
+
|
|
263
|
+
This function reads time series data from one or more text files and plots it
|
|
264
|
+
in either time domain or frequency domain (power or phase). It supports various
|
|
265
|
+
display modes, plot formatting options, and customization of colors, legends,
|
|
266
|
+
and axis labels.
|
|
267
|
+
|
|
268
|
+
Parameters
|
|
269
|
+
----------
|
|
270
|
+
args : argparse.Namespace
|
|
271
|
+
A namespace object containing the following attributes:
|
|
272
|
+
- samplerate : float or str
|
|
273
|
+
Sampling rate of the data. If "auto", defaults to 1.0.
|
|
274
|
+
- displaymode : str
|
|
275
|
+
Display mode: "time", "power", or "phase".
|
|
276
|
+
- plotformat : str
|
|
277
|
+
Plot formatting: "overlaid", "separate", or "separatelinked".
|
|
278
|
+
- colors : str, optional
|
|
279
|
+
Comma-separated list of color names for the lines.
|
|
280
|
+
- legends : str, optional
|
|
281
|
+
Comma-separated list of legend labels.
|
|
282
|
+
- dolegend : bool
|
|
283
|
+
Whether to display legends.
|
|
284
|
+
- linewidths : str, optional
|
|
285
|
+
Comma-separated list of line widths.
|
|
286
|
+
- legendloc : int
|
|
287
|
+
Legend location (0-10).
|
|
288
|
+
- thestarttime : float, optional
|
|
289
|
+
Start time for data selection.
|
|
290
|
+
- theendtime : float, optional
|
|
291
|
+
End time for data selection.
|
|
292
|
+
- textfilenames : list of str
|
|
293
|
+
List of text file names to read data from.
|
|
294
|
+
- dotranspose : bool
|
|
295
|
+
Whether to transpose the input data.
|
|
296
|
+
- normall : bool
|
|
297
|
+
Whether to normalize all data.
|
|
298
|
+
- fullxrange : bool
|
|
299
|
+
Whether to use full x-axis range.
|
|
300
|
+
- voffset : float
|
|
301
|
+
Vertical offset for overlaid plots.
|
|
302
|
+
- dowaterfall : bool
|
|
303
|
+
Whether to create a waterfall plot.
|
|
304
|
+
- fontscalefac : float
|
|
305
|
+
Font scaling factor.
|
|
306
|
+
- thetitle : str, optional
|
|
307
|
+
Title for the plot.
|
|
308
|
+
- xlabel : str, optional
|
|
309
|
+
X-axis label.
|
|
310
|
+
- ylabel : str, optional
|
|
311
|
+
Y-axis label.
|
|
312
|
+
- showxax : bool
|
|
313
|
+
Whether to show x-axis labels.
|
|
314
|
+
- showyax : bool
|
|
315
|
+
Whether to show y-axis labels.
|
|
316
|
+
- outputfile : str, optional
|
|
317
|
+
Output file name for saving the plot.
|
|
318
|
+
- saveres : int
|
|
319
|
+
Resolution for saved plots.
|
|
320
|
+
- debug : bool
|
|
321
|
+
Whether to print debug information.
|
|
322
|
+
|
|
323
|
+
Returns
|
|
324
|
+
-------
|
|
325
|
+
None
|
|
326
|
+
This function does not return a value but displays or saves the plot.
|
|
327
|
+
|
|
328
|
+
Notes
|
|
329
|
+
-----
|
|
330
|
+
- The function handles multiple input files and concatenates data.
|
|
331
|
+
- Spectral data is computed using Hamming windowing by default.
|
|
332
|
+
- Time series data is plotted with time on x-axis and values on y-axis.
|
|
333
|
+
- Spectral data is plotted with frequency on x-axis and either power or phase on y-axis.
|
|
334
|
+
- The function supports automatic detection of file types and column specifications.
|
|
335
|
+
|
|
336
|
+
Examples
|
|
337
|
+
--------
|
|
338
|
+
>>> import argparse
|
|
339
|
+
>>> args = argparse.Namespace()
|
|
340
|
+
>>> args.samplerate = 1.0
|
|
341
|
+
>>> args.displaymode = "time"
|
|
342
|
+
>>> args.plotformat = "separate"
|
|
343
|
+
>>> args.textfilenames = ["data1.txt", "data2.txt"]
|
|
344
|
+
>>> showtc(args)
|
|
345
|
+
"""
|
|
190
346
|
# set the sample rate
|
|
191
347
|
if args.samplerate == "auto":
|
|
192
348
|
samplerate = 1.0
|