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
rapidtide/workflows/rapidtide.py
CHANGED
|
@@ -23,8 +23,10 @@ import platform
|
|
|
23
23
|
import sys
|
|
24
24
|
import warnings
|
|
25
25
|
from pathlib import Path
|
|
26
|
+
from typing import Any, Tuple
|
|
26
27
|
|
|
27
28
|
import numpy as np
|
|
29
|
+
from numpy.typing import NDArray
|
|
28
30
|
from scipy.stats import rankdata
|
|
29
31
|
|
|
30
32
|
import rapidtide.calccoherence as tide_calccoherence
|
|
@@ -66,7 +68,36 @@ ErrorLGR = logging.getLogger("ERROR")
|
|
|
66
68
|
TimingLGR = logging.getLogger("TIMING")
|
|
67
69
|
|
|
68
70
|
|
|
69
|
-
def checkforzeromean(thedataset):
|
|
71
|
+
def checkforzeromean(thedataset: Any) -> bool:
|
|
72
|
+
"""
|
|
73
|
+
Check if the mean of dataset is zero.
|
|
74
|
+
|
|
75
|
+
Parameters
|
|
76
|
+
----------
|
|
77
|
+
thedataset : array-like
|
|
78
|
+
Input dataset to check for zero mean. Should be array-like structure
|
|
79
|
+
that can be processed by numpy mean and std functions.
|
|
80
|
+
|
|
81
|
+
Returns
|
|
82
|
+
-------
|
|
83
|
+
bool
|
|
84
|
+
True if the mean of standard deviations is greater than the mean of means,
|
|
85
|
+
False otherwise.
|
|
86
|
+
|
|
87
|
+
Notes
|
|
88
|
+
-----
|
|
89
|
+
This function calculates the mean and standard deviation along axis 1,
|
|
90
|
+
then compares the means of these two arrays. The function name suggests
|
|
91
|
+
checking for zero mean, but the implementation actually compares means
|
|
92
|
+
and standard deviations rather than directly checking if mean equals zero.
|
|
93
|
+
|
|
94
|
+
Examples
|
|
95
|
+
--------
|
|
96
|
+
>>> import numpy as np
|
|
97
|
+
>>> data = np.array([[1, 2, 3], [4, 5, 6]])
|
|
98
|
+
>>> checkforzeromean(data)
|
|
99
|
+
False
|
|
100
|
+
"""
|
|
70
101
|
themean = np.mean(thedataset, axis=1)
|
|
71
102
|
thestd = np.std(thedataset, axis=1)
|
|
72
103
|
if np.mean(thestd) > np.mean(themean):
|
|
@@ -75,7 +106,59 @@ def checkforzeromean(thedataset):
|
|
|
75
106
|
return False
|
|
76
107
|
|
|
77
108
|
|
|
78
|
-
def echocancel(
|
|
109
|
+
def echocancel(
|
|
110
|
+
thetimecourse: Any, echooffset: Any, thetimestep: Any, outputname: Any, padtimepoints: Any
|
|
111
|
+
) -> Tuple[NDArray, NDArray, float]:
|
|
112
|
+
"""
|
|
113
|
+
Perform echo cancellation on a timecourse using linear regression.
|
|
114
|
+
|
|
115
|
+
This function applies echo cancellation to a given timecourse by modeling the echo signal
|
|
116
|
+
and subtracting its contribution from the original signal. The echo is shifted in time
|
|
117
|
+
according to `echooffset` and then fitted using maximum likelihood regression. The
|
|
118
|
+
resulting filtered timecourse is saved along with the original and echo components.
|
|
119
|
+
|
|
120
|
+
Parameters
|
|
121
|
+
----------
|
|
122
|
+
thetimecourse : array-like
|
|
123
|
+
The input timecourse data to be processed.
|
|
124
|
+
echooffset : float
|
|
125
|
+
The time offset (in seconds) of the echo signal relative to the input timecourse.
|
|
126
|
+
thetimestep : float
|
|
127
|
+
The time step (in seconds) of the input timecourse.
|
|
128
|
+
outputname : str
|
|
129
|
+
Base name for output files; used to construct filenames for saved results.
|
|
130
|
+
padtimepoints : int
|
|
131
|
+
Number of timepoints to pad during resampling of the echo signal.
|
|
132
|
+
|
|
133
|
+
Returns
|
|
134
|
+
-------
|
|
135
|
+
tuple
|
|
136
|
+
A tuple containing:
|
|
137
|
+
- `outputtimecourse`: The timecourse after echo cancellation.
|
|
138
|
+
- `echofit`: The regression coefficients from fitting the echo signal.
|
|
139
|
+
- `echoR2`: The R-squared value of the echo fit.
|
|
140
|
+
|
|
141
|
+
Notes
|
|
142
|
+
-----
|
|
143
|
+
- The function writes three separate TSV files:
|
|
144
|
+
1. Original timecourse.
|
|
145
|
+
2. Echo signal.
|
|
146
|
+
3. Filtered (echo-cancelled) timecourse.
|
|
147
|
+
- The echo signal is shifted in time using `tide_resample.timeshift`.
|
|
148
|
+
- The echo is zeroed out at the beginning up to the computed shift.
|
|
149
|
+
- The function uses `tide_fit.mlregress` for linear regression fitting.
|
|
150
|
+
|
|
151
|
+
Examples
|
|
152
|
+
--------
|
|
153
|
+
>>> import numpy as np
|
|
154
|
+
>>> timecourse = np.random.rand(100)
|
|
155
|
+
>>> echo_offset = 2.0
|
|
156
|
+
>>> time_step = 1.0
|
|
157
|
+
>>> output_name = "test_output"
|
|
158
|
+
>>> pad_points = 10
|
|
159
|
+
>>> result = echocancel(timecourse, echo_offset, time_step, output_name, pad_points)
|
|
160
|
+
>>> filtered_tc, fit_coeffs, r2 = result
|
|
161
|
+
"""
|
|
79
162
|
tide_io.writebidstsv(
|
|
80
163
|
f"{outputname}_desc-echocancellation_timeseries",
|
|
81
164
|
thetimecourse,
|
|
@@ -114,12 +197,84 @@ def echocancel(thetimecourse, echooffset, thetimestep, outputname, padtimepoints
|
|
|
114
197
|
)
|
|
115
198
|
return outputtimecourse, echofit, echoR2
|
|
116
199
|
|
|
117
|
-
|
|
200
|
+
|
|
201
|
+
def setpassoptions(passdict: Any, optiondict: Any) -> None:
|
|
202
|
+
"""
|
|
203
|
+
Copy key-value pairs from passdict to optiondict.
|
|
204
|
+
|
|
205
|
+
This function updates the optiondict with key-value pairs from passdict,
|
|
206
|
+
effectively passing options from one dictionary to another.
|
|
207
|
+
|
|
208
|
+
Parameters
|
|
209
|
+
----------
|
|
210
|
+
passdict : Any
|
|
211
|
+
Dictionary containing options to be passed
|
|
212
|
+
optiondict : Any
|
|
213
|
+
Dictionary that will receive the options from passdict
|
|
214
|
+
|
|
215
|
+
Returns
|
|
216
|
+
-------
|
|
217
|
+
None
|
|
218
|
+
This function modifies optiondict in-place and returns None
|
|
219
|
+
|
|
220
|
+
Notes
|
|
221
|
+
-----
|
|
222
|
+
This function performs an in-place update of optiondict. Any existing keys
|
|
223
|
+
in optiondict that are also present in passdict will be overwritten with
|
|
224
|
+
the values from passdict.
|
|
225
|
+
|
|
226
|
+
Examples
|
|
227
|
+
--------
|
|
228
|
+
>>> options = {'verbose': True, 'timeout': 30}
|
|
229
|
+
>>> new_options = {'debug': False}
|
|
230
|
+
>>> setpassoptions(options, new_options)
|
|
231
|
+
>>> print(new_options)
|
|
232
|
+
{'debug': False, 'verbose': True, 'timeout': 30}
|
|
233
|
+
"""
|
|
118
234
|
for key, value in passdict.items():
|
|
119
235
|
optiondict[key] = value
|
|
120
236
|
|
|
121
237
|
|
|
122
|
-
def rapidtide_main(argparsingfunc):
|
|
238
|
+
def rapidtide_main(argparsingfunc: Any) -> None:
|
|
239
|
+
"""
|
|
240
|
+
Process fMRI data to perform spatially localized signal-to-noise ratio (sLFO) analysis.
|
|
241
|
+
|
|
242
|
+
This function performs a comprehensive analysis of fMRI data including correlation
|
|
243
|
+
analysis, signal filtering, and various statistical computations to identify and
|
|
244
|
+
remove spatially localized noise components.
|
|
245
|
+
|
|
246
|
+
Parameters
|
|
247
|
+
----------
|
|
248
|
+
None
|
|
249
|
+
|
|
250
|
+
Returns
|
|
251
|
+
-------
|
|
252
|
+
None
|
|
253
|
+
The function performs in-place processing and saves results to files.
|
|
254
|
+
|
|
255
|
+
Notes
|
|
256
|
+
-----
|
|
257
|
+
This function is designed to be called as part of a larger pipeline for fMRI
|
|
258
|
+
preprocessing and analysis. It handles multiple stages including:
|
|
259
|
+
|
|
260
|
+
1. Data initialization and validation
|
|
261
|
+
2. Correlation analysis across spatial locations
|
|
262
|
+
3. Signal filtering and noise removal
|
|
263
|
+
4. Statistical computations and result saving
|
|
264
|
+
5. Timing and logging management
|
|
265
|
+
|
|
266
|
+
Examples
|
|
267
|
+
--------
|
|
268
|
+
>>> process_fmri_data()
|
|
269
|
+
# Processes fMRI data and saves results to output files
|
|
270
|
+
|
|
271
|
+
See Also
|
|
272
|
+
--------
|
|
273
|
+
tide_regressfrommaps : Performs regression analysis on fMRI data
|
|
274
|
+
tide_io : Handles input/output operations for fMRI data
|
|
275
|
+
tide_util : Utility functions for processing fMRI data
|
|
276
|
+
|
|
277
|
+
"""
|
|
123
278
|
optiondict, theprefilter = argparsingfunc
|
|
124
279
|
optiondict["threaddebug"] = False
|
|
125
280
|
|
|
@@ -179,7 +334,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
179
334
|
logger_filename=f"{outputname}_log.txt",
|
|
180
335
|
timing_filename=f"{outputname}_runtimings.tsv",
|
|
181
336
|
memory_filename=f"{outputname}_memusage.tsv",
|
|
182
|
-
|
|
337
|
+
isverbose=optiondict["verbose"],
|
|
183
338
|
debug=optiondict["debug"],
|
|
184
339
|
)
|
|
185
340
|
TimingLGR.info("Start")
|
|
@@ -306,6 +461,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
306
461
|
if optiondict["oversampfactor"] < 0:
|
|
307
462
|
optiondict["oversampfactor"] = int(np.max([np.ceil(fmritr / 0.5), 1]))
|
|
308
463
|
LGR.debug(f"oversample factor set to {optiondict['oversampfactor']}")
|
|
464
|
+
# optiondict["prewhitenlags"] *= optiondict["oversampfactor"]
|
|
309
465
|
|
|
310
466
|
oversamptr = fmritr / optiondict["oversampfactor"]
|
|
311
467
|
LGR.verbose(f"fmri data: {timepoints} timepoints, tr = {fmritr}, oversamptr = {oversamptr}")
|
|
@@ -350,6 +506,13 @@ def rapidtide_main(argparsingfunc):
|
|
|
350
506
|
optiondict["osvalidsimcalcend"] = osvalidsimcalcend
|
|
351
507
|
optiondict["simcalcoffset"] = -validsimcalcstart * fmritr
|
|
352
508
|
|
|
509
|
+
####################################################
|
|
510
|
+
# Calculate initial stats
|
|
511
|
+
####################################################
|
|
512
|
+
init_min, init_max, init_mean, init_std, init_median, init_MAD, init_skew, init_kurtosis = (
|
|
513
|
+
tide_stats.fmristats(theinputdata.byvoxel())
|
|
514
|
+
)
|
|
515
|
+
|
|
353
516
|
####################################################
|
|
354
517
|
# Prepare data
|
|
355
518
|
####################################################
|
|
@@ -372,7 +535,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
372
535
|
valslist=optiondict[thisanatomic[1]],
|
|
373
536
|
maskname=thisanatomic[2],
|
|
374
537
|
tolerance=optiondict["spatialtolerance"],
|
|
375
|
-
debug=optiondict["
|
|
538
|
+
debug=optiondict["debug"],
|
|
376
539
|
)
|
|
377
540
|
)
|
|
378
541
|
anatomicmasks[-1] = np.uint16(np.where(anatomicmasks[-1] > 0.1, 1, 0))
|
|
@@ -443,7 +606,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
443
606
|
numspatiallocs,
|
|
444
607
|
istext=(theinputdata.filetype == "text"),
|
|
445
608
|
tolerance=optiondict["spatialtolerance"],
|
|
446
|
-
debug=optiondict["
|
|
609
|
+
debug=optiondict["debug"],
|
|
447
610
|
)
|
|
448
611
|
)
|
|
449
612
|
if internalinvbrainmask is not None:
|
|
@@ -462,7 +625,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
462
625
|
numspatiallocs,
|
|
463
626
|
istext=(theinputdata.filetype == "text"),
|
|
464
627
|
tolerance=optiondict["spatialtolerance"],
|
|
465
|
-
debug=optiondict["
|
|
628
|
+
debug=optiondict["debug"],
|
|
466
629
|
)
|
|
467
630
|
if internalinvbrainmask is not None:
|
|
468
631
|
if internalrefineexcludemask is not None:
|
|
@@ -480,7 +643,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
480
643
|
numspatiallocs,
|
|
481
644
|
istext=(theinputdata.filetype == "text"),
|
|
482
645
|
tolerance=optiondict["spatialtolerance"],
|
|
483
|
-
debug=optiondict["
|
|
646
|
+
debug=optiondict["debug"],
|
|
484
647
|
)
|
|
485
648
|
if internalinvbrainmask is not None:
|
|
486
649
|
if internaloffsetexcludemask is not None:
|
|
@@ -502,7 +665,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
502
665
|
valslist=optiondict["corrmaskincludevals"],
|
|
503
666
|
maskname="correlation",
|
|
504
667
|
tolerance=optiondict["spatialtolerance"],
|
|
505
|
-
debug=optiondict["
|
|
668
|
+
debug=optiondict["debug"],
|
|
506
669
|
)
|
|
507
670
|
|
|
508
671
|
corrmask = np.uint16(np.where(thecorrmask > 0, 1, 0).reshape(numspatiallocs))
|
|
@@ -1260,7 +1423,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
1260
1423
|
corrpadding=optiondict["corrpadding"],
|
|
1261
1424
|
debug=optiondict["debug"],
|
|
1262
1425
|
)
|
|
1263
|
-
if optiondict["
|
|
1426
|
+
if optiondict["debug"]:
|
|
1264
1427
|
print(
|
|
1265
1428
|
f"calling setreftc during initialization with length {optiondict['oversampfactor'] * validtimepoints}"
|
|
1266
1429
|
)
|
|
@@ -1613,7 +1776,9 @@ def rapidtide_main(argparsingfunc):
|
|
|
1613
1776
|
tmask_y=tmask_y,
|
|
1614
1777
|
tmaskos_y=tmaskos_y,
|
|
1615
1778
|
fastresamplerpadtime=optiondict["fastresamplerpadtime"],
|
|
1616
|
-
|
|
1779
|
+
prewhitenregressor=False,
|
|
1780
|
+
prewhitenlags=optiondict["prewhitenlags"],
|
|
1781
|
+
debug=optiondict["focaldebug"],
|
|
1617
1782
|
)
|
|
1618
1783
|
|
|
1619
1784
|
# cycle over all voxels
|
|
@@ -1713,6 +1878,32 @@ def rapidtide_main(argparsingfunc):
|
|
|
1713
1878
|
"message3": "voxels",
|
|
1714
1879
|
},
|
|
1715
1880
|
)
|
|
1881
|
+
tide_io.writebidstsv(
|
|
1882
|
+
f"{outputname}_desc-oversampledmovingregressor_timeseries",
|
|
1883
|
+
tide_math.stdnormalize(resampref_y),
|
|
1884
|
+
oversampfreq,
|
|
1885
|
+
columns=["pass1_echocancel"],
|
|
1886
|
+
extraheaderinfo={
|
|
1887
|
+
"Description": "The probe regressor used in each pass, at the time resolution used for calculating the similarity function"
|
|
1888
|
+
},
|
|
1889
|
+
append=True,
|
|
1890
|
+
)
|
|
1891
|
+
|
|
1892
|
+
# Preprocessing - prewhitening
|
|
1893
|
+
if optiondict["prewhitenregressor"]:
|
|
1894
|
+
resampref_y = tide_fit.prewhiten(
|
|
1895
|
+
resampref_y, optiondict["prewhitenlags"], debug=optiondict["focaldebug"]
|
|
1896
|
+
)
|
|
1897
|
+
tide_io.writebidstsv(
|
|
1898
|
+
f"{outputname}_desc-oversampledmovingregressor_timeseries",
|
|
1899
|
+
tide_math.stdnormalize(resampref_y),
|
|
1900
|
+
oversampfreq,
|
|
1901
|
+
columns=["pass1_prewhiten"],
|
|
1902
|
+
extraheaderinfo={
|
|
1903
|
+
"Description": "The probe regressor used in each pass, at the time resolution used for calculating the similarity function"
|
|
1904
|
+
},
|
|
1905
|
+
append=True,
|
|
1906
|
+
)
|
|
1716
1907
|
|
|
1717
1908
|
# --------------------- Main pass loop ---------------------
|
|
1718
1909
|
# loop over all passes
|
|
@@ -1803,7 +1994,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
1803
1994
|
rt_floattype=rt_floattype,
|
|
1804
1995
|
rt_floatset=rt_floatset,
|
|
1805
1996
|
)
|
|
1806
|
-
if optiondict["
|
|
1997
|
+
if optiondict["debug"]:
|
|
1807
1998
|
print(
|
|
1808
1999
|
f"after cleanregressor: {len(referencetc)=}, {len(cleaned_referencetc)=}, {osvalidsimcalcstart=}, {osvalidsimcalcend=}, {lagmininpts=}, {lagmaxinpts=}"
|
|
1809
2000
|
)
|
|
@@ -1827,7 +2018,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
1827
2018
|
f"{outputname}_options_pregetnull_pass" + str(thepass) + ".json",
|
|
1828
2019
|
)
|
|
1829
2020
|
theCorrelator.setlimits(lagmininpts, lagmaxinpts)
|
|
1830
|
-
if optiondict["
|
|
2021
|
+
if optiondict["debug"]:
|
|
1831
2022
|
print(
|
|
1832
2023
|
f"calling setreftc prior to significance estimation with length {len(cleaned_resampref_y)}"
|
|
1833
2024
|
)
|
|
@@ -2002,7 +2193,7 @@ def rapidtide_main(argparsingfunc):
|
|
|
2002
2193
|
rt_floatset=rt_floatset,
|
|
2003
2194
|
rt_floattype=rt_floattype,
|
|
2004
2195
|
threaddebug=optiondict["threaddebug"],
|
|
2005
|
-
debug=optiondict["
|
|
2196
|
+
debug=optiondict["debug"],
|
|
2006
2197
|
)
|
|
2007
2198
|
if optiondict["similaritymetric"] == "riptide":
|
|
2008
2199
|
optiondict["despeckle_passes"] = 0
|
|
@@ -2669,6 +2860,12 @@ def rapidtide_main(argparsingfunc):
|
|
|
2669
2860
|
varchange = initialvariance * 0.0
|
|
2670
2861
|
varchange[divlocs] = 100.0 * (finalvariance[divlocs] / initialvariance[divlocs] - 1.0)
|
|
2671
2862
|
|
|
2863
|
+
# calculate the voxelwise mean of the filtered data
|
|
2864
|
+
lfofilteredmeanvalue = np.mean(
|
|
2865
|
+
filtereddata,
|
|
2866
|
+
axis=1,
|
|
2867
|
+
)
|
|
2868
|
+
|
|
2672
2869
|
LGR.info("End filtering operation")
|
|
2673
2870
|
TimingLGR.info(
|
|
2674
2871
|
"sLFO filtering end",
|
|
@@ -2978,6 +3175,13 @@ def rapidtide_main(argparsingfunc):
|
|
|
2978
3175
|
"percent",
|
|
2979
3176
|
"Change in inband variance after filtering, in percent",
|
|
2980
3177
|
),
|
|
3178
|
+
# (
|
|
3179
|
+
# lfofilteredmeanvalue,
|
|
3180
|
+
# "lfofilterMean",
|
|
3181
|
+
# "map",
|
|
3182
|
+
# None,
|
|
3183
|
+
# "Voxelwise mean of the sLFO filtered data",
|
|
3184
|
+
# ),
|
|
2981
3185
|
]
|
|
2982
3186
|
if optiondict["saveminimumsLFOfiltfiles"]:
|
|
2983
3187
|
maplist += [
|
|
@@ -3039,6 +3243,59 @@ def rapidtide_main(argparsingfunc):
|
|
|
3039
3243
|
"Normalized fit coefficient",
|
|
3040
3244
|
),
|
|
3041
3245
|
]
|
|
3246
|
+
init_std_valid = init_std[validvoxels] + 0.0
|
|
3247
|
+
init_skew_valid = init_skew[validvoxels] + 0.0
|
|
3248
|
+
init_kurtosis_valid = init_kurtosis[validvoxels] + 0.0
|
|
3249
|
+
maplist += [
|
|
3250
|
+
(init_std_valid, "initialStd", "map", None, "Std of the raw input data"),
|
|
3251
|
+
(
|
|
3252
|
+
init_skew_valid,
|
|
3253
|
+
"initialSkewness",
|
|
3254
|
+
"map",
|
|
3255
|
+
None,
|
|
3256
|
+
"Skewness of the raw input data",
|
|
3257
|
+
),
|
|
3258
|
+
(
|
|
3259
|
+
init_kurtosis_valid,
|
|
3260
|
+
"initialKurtosis",
|
|
3261
|
+
"map",
|
|
3262
|
+
None,
|
|
3263
|
+
"Kurtosis of the raw input data",
|
|
3264
|
+
),
|
|
3265
|
+
]
|
|
3266
|
+
(
|
|
3267
|
+
final_min_valid,
|
|
3268
|
+
final_max_valid,
|
|
3269
|
+
final_mean_valid,
|
|
3270
|
+
final_std_valid,
|
|
3271
|
+
final_median_valid,
|
|
3272
|
+
final_MAD_valid,
|
|
3273
|
+
final_skew_valid,
|
|
3274
|
+
final_kurtosis_valid,
|
|
3275
|
+
) = tide_stats.fmristats(filtereddata)
|
|
3276
|
+
maplist += [
|
|
3277
|
+
(
|
|
3278
|
+
final_std_valid,
|
|
3279
|
+
"lfofilterCleanedStd",
|
|
3280
|
+
"map",
|
|
3281
|
+
None,
|
|
3282
|
+
"Std of the sLFO cleaned data",
|
|
3283
|
+
),
|
|
3284
|
+
(
|
|
3285
|
+
final_skew_valid,
|
|
3286
|
+
"lfofilterCleanedSkewness",
|
|
3287
|
+
"map",
|
|
3288
|
+
None,
|
|
3289
|
+
"Skewness of the sLFO cleaned data",
|
|
3290
|
+
),
|
|
3291
|
+
(
|
|
3292
|
+
final_kurtosis_valid,
|
|
3293
|
+
"lfofilterCleanedKurtosis",
|
|
3294
|
+
"map",
|
|
3295
|
+
None,
|
|
3296
|
+
"Kurtosis of the sLFO cleaned data",
|
|
3297
|
+
),
|
|
3298
|
+
]
|
|
3042
3299
|
else:
|
|
3043
3300
|
maplist = [
|
|
3044
3301
|
(
|
|
@@ -20,12 +20,39 @@ import argparse
|
|
|
20
20
|
import glob
|
|
21
21
|
import os
|
|
22
22
|
import sys
|
|
23
|
+
from argparse import Namespace
|
|
24
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
23
25
|
|
|
24
26
|
import rapidtide.externaltools as tide_exttools
|
|
25
27
|
import rapidtide.io as tide_io
|
|
26
28
|
|
|
27
29
|
|
|
28
|
-
def _get_parser():
|
|
30
|
+
def _get_parser() -> Any:
|
|
31
|
+
"""
|
|
32
|
+
Create and configure an argument parser for the rapidtide2std command-line tool.
|
|
33
|
+
|
|
34
|
+
This function sets up an `argparse.ArgumentParser` with specific arguments
|
|
35
|
+
required for registering rapidtide output maps to standard space. It supports
|
|
36
|
+
various options for controlling the transformation process, including linear
|
|
37
|
+
vs. nonlinear registration, file selection, and debugging output.
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
argparse.ArgumentParser
|
|
42
|
+
Configured argument parser with all required and optional arguments.
|
|
43
|
+
|
|
44
|
+
Notes
|
|
45
|
+
-----
|
|
46
|
+
The parser is designed for use with the `rapidtide2std` command-line tool.
|
|
47
|
+
It expects three mandatory positional arguments: `inputfileroot`, `outputdir`,
|
|
48
|
+
and `featdirectory`. Additional optional arguments control the behavior of the
|
|
49
|
+
registration process.
|
|
50
|
+
|
|
51
|
+
Examples
|
|
52
|
+
--------
|
|
53
|
+
>>> parser = _get_parser()
|
|
54
|
+
>>> args = parser.parse_args()
|
|
55
|
+
"""
|
|
29
56
|
# get the command line parameters
|
|
30
57
|
parser = argparse.ArgumentParser(
|
|
31
58
|
prog="rapidtide2std",
|
|
@@ -111,7 +138,76 @@ def _get_parser():
|
|
|
111
138
|
return parser
|
|
112
139
|
|
|
113
140
|
|
|
114
|
-
def rapidtide2std(args):
|
|
141
|
+
def rapidtide2std(args: Any) -> None:
|
|
142
|
+
"""
|
|
143
|
+
Transform RapidTide output maps and timecourses to standard (MNI) or high-resolution (T1) space.
|
|
144
|
+
|
|
145
|
+
This function performs spatial normalization of RapidTide-derived functional and anatomical
|
|
146
|
+
maps using FSL's FLIRT and FNIRT tools. It supports both linear and nonlinear transformations
|
|
147
|
+
depending on the presence of warp files and user-specified options. The function processes
|
|
148
|
+
all relevant output files from a RapidTide analysis and applies the appropriate transformation
|
|
149
|
+
to align them with either the standard MNI152 template or the high-resolution T1-weighted image.
|
|
150
|
+
|
|
151
|
+
Parameters
|
|
152
|
+
----------
|
|
153
|
+
args : Any
|
|
154
|
+
An object containing command-line arguments. Expected attributes include:
|
|
155
|
+
- debug : bool, optional
|
|
156
|
+
Enable debug output.
|
|
157
|
+
- featdirectory : str
|
|
158
|
+
Path to the FEAT directory containing registration files.
|
|
159
|
+
- aligntohires : bool, optional
|
|
160
|
+
Align to high-resolution space instead of standard space.
|
|
161
|
+
- forcelinear : bool, optional
|
|
162
|
+
Force linear transformation even if warp file is present.
|
|
163
|
+
- onefilename : str, optional
|
|
164
|
+
Process a single input file instead of all files in the dataset.
|
|
165
|
+
- outputdir : str
|
|
166
|
+
Output directory for transformed files.
|
|
167
|
+
- inputfileroot : str
|
|
168
|
+
Root name for input files.
|
|
169
|
+
- corrout : bool, optional
|
|
170
|
+
Include corrout_info map in output.
|
|
171
|
+
- clean : bool, optional
|
|
172
|
+
Include lfofilterCleaned_bold map in output.
|
|
173
|
+
- confound : bool, optional
|
|
174
|
+
Include confoundfilterR2_map in output.
|
|
175
|
+
- sequential : bool, optional
|
|
176
|
+
Run commands sequentially instead of in parallel.
|
|
177
|
+
- preponly : bool, optional
|
|
178
|
+
Only print commands without executing them.
|
|
179
|
+
|
|
180
|
+
Returns
|
|
181
|
+
-------
|
|
182
|
+
None
|
|
183
|
+
This function does not return any value. It performs file I/O and system calls
|
|
184
|
+
to transform and copy files to the specified output directory.
|
|
185
|
+
|
|
186
|
+
Notes
|
|
187
|
+
-----
|
|
188
|
+
The function expects the FSL environment variable FSLDIR to be set. It uses the
|
|
189
|
+
example_func2highres.mat or example_func2standard.mat transformation matrix and
|
|
190
|
+
the corresponding warp file (if present) to perform the spatial normalization.
|
|
191
|
+
|
|
192
|
+
Examples
|
|
193
|
+
--------
|
|
194
|
+
>>> import argparse
|
|
195
|
+
>>> args = argparse.Namespace(
|
|
196
|
+
... debug=False,
|
|
197
|
+
... featdirectory='/path/to/feat',
|
|
198
|
+
... aligntohires=False,
|
|
199
|
+
... forcelinear=False,
|
|
200
|
+
... onefilename=None,
|
|
201
|
+
... outputdir='output',
|
|
202
|
+
... inputfileroot='sub-01_task-rest',
|
|
203
|
+
... corrout=True,
|
|
204
|
+
... clean=False,
|
|
205
|
+
... confound=False,
|
|
206
|
+
... sequential=False,
|
|
207
|
+
... preponly=False
|
|
208
|
+
... )
|
|
209
|
+
>>> rapidtide2std(args)
|
|
210
|
+
"""
|
|
115
211
|
if args.debug:
|
|
116
212
|
print(args)
|
|
117
213
|
|