rapidtide 3.0.11__py3-none-any.whl → 3.1.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 +1049 -46
- rapidtide/RapidtideDataset.py +1533 -86
- rapidtide/_version.py +3 -3
- rapidtide/calccoherence.py +196 -29
- rapidtide/calcnullsimfunc.py +188 -40
- rapidtide/calcsimfunc.py +242 -42
- rapidtide/correlate.py +1203 -383
- 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 +53 -3
- rapidtide/data/examples/src/testglmfilt +5 -5
- rapidtide/data/examples/src/testhappy +29 -7
- 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/decorators.py +91 -0
- rapidtide/dlfilter.py +2226 -110
- rapidtide/dlfiltertorch.py +4842 -0
- rapidtide/externaltools.py +327 -12
- rapidtide/fMRIData_class.py +79 -40
- rapidtide/filter.py +1899 -810
- rapidtide/fit.py +2011 -581
- rapidtide/genericmultiproc.py +93 -18
- rapidtide/happy_supportfuncs.py +2047 -172
- rapidtide/helper_classes.py +584 -43
- rapidtide/io.py +2370 -372
- rapidtide/linfitfiltpass.py +346 -99
- rapidtide/makelaggedtcs.py +210 -24
- rapidtide/maskutil.py +448 -62
- rapidtide/miscmath.py +827 -121
- rapidtide/multiproc.py +210 -22
- rapidtide/patchmatch.py +242 -42
- rapidtide/peakeval.py +31 -31
- rapidtide/ppgproc.py +2203 -0
- rapidtide/qualitycheck.py +352 -39
- rapidtide/refinedelay.py +431 -57
- rapidtide/refineregressor.py +494 -189
- rapidtide/resample.py +671 -185
- rapidtide/scripts/applyppgproc.py +28 -0
- rapidtide/scripts/showxcorr_legacy.py +7 -7
- rapidtide/scripts/stupidramtricks.py +15 -17
- rapidtide/simFuncClasses.py +1052 -77
- rapidtide/simfuncfit.py +269 -69
- rapidtide/stats.py +540 -238
- rapidtide/tests/happycomp +9 -0
- rapidtide/tests/test_cleanregressor.py +1 -2
- 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 +11 -4
- rapidtide/tests/test_fullrunhappy_v4.py +10 -2
- rapidtide/tests/test_fullrunrapidtide_v7.py +1 -1
- rapidtide/tests/test_getparsers.py +11 -3
- rapidtide/tests/test_refinedelay.py +0 -1
- rapidtide/tests/test_simroundtrip.py +16 -8
- rapidtide/tests/test_stcorrelate.py +3 -1
- 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 +136 -23
- rapidtide/wiener2.py +113 -7
- rapidtide/workflows/adjustoffset.py +105 -3
- rapidtide/workflows/aligntcs.py +85 -2
- rapidtide/workflows/applydlfilter.py +87 -10
- rapidtide/workflows/applyppgproc.py +540 -0
- rapidtide/workflows/atlasaverage.py +210 -47
- rapidtide/workflows/atlastool.py +100 -3
- rapidtide/workflows/calcSimFuncMap.py +288 -69
- rapidtide/workflows/calctexticc.py +201 -9
- rapidtide/workflows/ccorrica.py +101 -6
- rapidtide/workflows/cleanregressor.py +165 -31
- rapidtide/workflows/delayvar.py +171 -23
- 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 +202 -51
- rapidtide/workflows/fixtr.py +73 -3
- rapidtide/workflows/gmscalc.py +113 -3
- rapidtide/workflows/happy.py +801 -199
- rapidtide/workflows/happy2std.py +144 -12
- rapidtide/workflows/happy_parser.py +163 -23
- 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 +98 -4
- rapidtide/workflows/pairwisemergenifti.py +85 -2
- rapidtide/workflows/parser_funcs.py +1421 -40
- rapidtide/workflows/physiofreq.py +137 -11
- rapidtide/workflows/pixelcomp.py +207 -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 +368 -76
- rapidtide/workflows/rapidtide2std.py +98 -2
- rapidtide/workflows/rapidtide_parser.py +109 -9
- rapidtide/workflows/refineDelayMap.py +144 -33
- rapidtide/workflows/refineRegressor.py +675 -96
- rapidtide/workflows/regressfrommaps.py +161 -37
- rapidtide/workflows/resamplenifti.py +85 -3
- rapidtide/workflows/resampletc.py +91 -3
- rapidtide/workflows/retrolagtcs.py +99 -9
- rapidtide/workflows/retroregress.py +176 -26
- rapidtide/workflows/roisummarize.py +174 -5
- rapidtide/workflows/runqualitycheck.py +71 -3
- rapidtide/workflows/showarbcorr.py +149 -6
- rapidtide/workflows/showhist.py +86 -2
- rapidtide/workflows/showstxcorr.py +160 -3
- rapidtide/workflows/showtc.py +159 -3
- rapidtide/workflows/showxcorrx.py +190 -10
- rapidtide/workflows/showxy.py +185 -15
- rapidtide/workflows/simdata.py +264 -38
- rapidtide/workflows/spatialfit.py +77 -2
- rapidtide/workflows/spatialmi.py +250 -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 +2971 -130
- rapidtide/workflows/utils.py +19 -14
- rapidtide/workflows/utils_doc.py +293 -0
- rapidtide/workflows/variabilityizer.py +116 -3
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/METADATA +10 -8
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/RECORD +144 -128
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/entry_points.txt +1 -0
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/WHEEL +0 -0
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/licenses/LICENSE +0 -0
- {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/top_level.txt +0 -0
rapidtide/workflows/simdata.py
CHANGED
|
@@ -17,8 +17,11 @@
|
|
|
17
17
|
#
|
|
18
18
|
#
|
|
19
19
|
import argparse
|
|
20
|
+
import sys
|
|
21
|
+
from typing import Any, Optional, Tuple
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
import numpy as np
|
|
24
|
+
from numpy.typing import NDArray
|
|
22
25
|
|
|
23
26
|
import rapidtide.filter as tide_filt
|
|
24
27
|
import rapidtide.io as tide_io
|
|
@@ -28,9 +31,34 @@ import rapidtide.voxelData as tide_voxelData
|
|
|
28
31
|
import rapidtide.workflows.parser_funcs as pf
|
|
29
32
|
|
|
30
33
|
|
|
31
|
-
def _get_parser():
|
|
34
|
+
def _get_parser() -> Any:
|
|
32
35
|
"""
|
|
33
|
-
Argument parser for simdata
|
|
36
|
+
Argument parser for simdata.
|
|
37
|
+
|
|
38
|
+
This function constructs and returns an `argparse.ArgumentParser` object
|
|
39
|
+
configured for parsing command-line arguments used by the `simdata` tool.
|
|
40
|
+
The parser supports both required and optional arguments for generating
|
|
41
|
+
simulated fMRI data with known correlation parameters.
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
argparse.ArgumentParser
|
|
46
|
+
Configured argument parser for simdata command-line interface.
|
|
47
|
+
|
|
48
|
+
Notes
|
|
49
|
+
-----
|
|
50
|
+
The function sets up argument groups for LFO, respiratory, and cardiac
|
|
51
|
+
bands, each with mutually exclusive options for specifying signal strength
|
|
52
|
+
(either as a percentage of mean or as a fraction of inband variance).
|
|
53
|
+
Each band group also accepts optional files for specifying lag, regressor,
|
|
54
|
+
sample rate, and start time.
|
|
55
|
+
|
|
56
|
+
Examples
|
|
57
|
+
--------
|
|
58
|
+
>>> parser = _get_parser()
|
|
59
|
+
>>> args = parser.parse_args(['--lfo pctfile', 'lfo.nii', 'output'])
|
|
60
|
+
>>> print(args.lfo_pctfile)
|
|
61
|
+
'lfo.nii'
|
|
34
62
|
"""
|
|
35
63
|
parser = argparse.ArgumentParser(
|
|
36
64
|
prog="simdata",
|
|
@@ -177,17 +205,83 @@ def _get_parser():
|
|
|
177
205
|
|
|
178
206
|
|
|
179
207
|
def prepareband(
|
|
180
|
-
simdatadims,
|
|
181
|
-
pctfile,
|
|
182
|
-
sigfracfile,
|
|
183
|
-
lagfile,
|
|
184
|
-
regressorfile,
|
|
185
|
-
samprate,
|
|
186
|
-
starttime,
|
|
187
|
-
regressorname,
|
|
188
|
-
padtime=30.0,
|
|
189
|
-
debug=False,
|
|
190
|
-
):
|
|
208
|
+
simdatadims: Any,
|
|
209
|
+
pctfile: str,
|
|
210
|
+
sigfracfile: Any,
|
|
211
|
+
lagfile: Any,
|
|
212
|
+
regressorfile: Any,
|
|
213
|
+
samprate: Any,
|
|
214
|
+
starttime: Any,
|
|
215
|
+
regressorname: Any,
|
|
216
|
+
padtime: float = 30.0,
|
|
217
|
+
debug: bool = False,
|
|
218
|
+
) -> Tuple[NDArray, bool, NDArray, object]:
|
|
219
|
+
"""
|
|
220
|
+
Prepare band-specific regressor data for time series analysis.
|
|
221
|
+
|
|
222
|
+
This function reads in a regressor timecourse from a text file and resamples it
|
|
223
|
+
to match the dimensions of fMRI data. It also loads percentile and lag data
|
|
224
|
+
from NIfTI files, performing necessary checks for spatial dimension matching.
|
|
225
|
+
A FastResampler is initialized for later use in resampling the regressor.
|
|
226
|
+
|
|
227
|
+
Parameters
|
|
228
|
+
----------
|
|
229
|
+
simdatadims : Any
|
|
230
|
+
Spatial dimensions of the fMRI data.
|
|
231
|
+
pctfile : str
|
|
232
|
+
Path to the NIfTI file containing percentile data. If None, `sigfracfile` is used.
|
|
233
|
+
sigfracfile : Any
|
|
234
|
+
Path to the NIfTI file containing signal fraction data. Used if `pctfile` is None.
|
|
235
|
+
lagfile : Any
|
|
236
|
+
Path to the NIfTI file containing lag data.
|
|
237
|
+
regressorfile : Any
|
|
238
|
+
Path to the text file containing the regressor timecourse.
|
|
239
|
+
samprate : Any
|
|
240
|
+
Sampling rate of the regressor. If None, uses the value from `regressorfile`.
|
|
241
|
+
starttime : Any
|
|
242
|
+
Start time of the regressor. If None, uses the value from `regressorfile`.
|
|
243
|
+
regressorname : Any
|
|
244
|
+
Name of the regressor, used for logging and debugging.
|
|
245
|
+
padtime : float, optional
|
|
246
|
+
Padding time (in seconds) for the resampler. Default is 30.0.
|
|
247
|
+
debug : bool, optional
|
|
248
|
+
If True, prints debug information. Default is False.
|
|
249
|
+
|
|
250
|
+
Returns
|
|
251
|
+
-------
|
|
252
|
+
tuple
|
|
253
|
+
A tuple containing:
|
|
254
|
+
- pctdata : ndarray
|
|
255
|
+
The loaded and possibly scaled percentile or signal fraction data.
|
|
256
|
+
- pctscale : bool
|
|
257
|
+
Indicates whether the data was scaled from a percentile file.
|
|
258
|
+
- lagdata : ndarray
|
|
259
|
+
The loaded lag data from the NIfTI file.
|
|
260
|
+
- generator : FastResampler
|
|
261
|
+
An initialized FastResampler object for resampling the regressor.
|
|
262
|
+
|
|
263
|
+
Notes
|
|
264
|
+
-----
|
|
265
|
+
- The function checks that the spatial dimensions of the NIfTI files match
|
|
266
|
+
those of the fMRI data.
|
|
267
|
+
- If `pctfile` is None, the function uses `sigfracfile` and scales the data by 100.
|
|
268
|
+
- The regressor is normalized using standard normalization.
|
|
269
|
+
|
|
270
|
+
Examples
|
|
271
|
+
--------
|
|
272
|
+
>>> prepareband(
|
|
273
|
+
... simdatadims=[64, 64, 32],
|
|
274
|
+
... pctfile='pct.nii.gz',
|
|
275
|
+
... sigfracfile=None,
|
|
276
|
+
... lagfile='lag.nii.gz',
|
|
277
|
+
... regressorfile='regressor.txt',
|
|
278
|
+
... samprate=2.0,
|
|
279
|
+
... starttime=0.0,
|
|
280
|
+
... regressorname='band1',
|
|
281
|
+
... padtime=30.0,
|
|
282
|
+
... debug=False
|
|
283
|
+
... )
|
|
284
|
+
"""
|
|
191
285
|
if debug:
|
|
192
286
|
print("simdatadims:", simdatadims)
|
|
193
287
|
print("pctfile:", pctfile)
|
|
@@ -261,28 +355,102 @@ def prepareband(
|
|
|
261
355
|
|
|
262
356
|
|
|
263
357
|
def fmrisignal(
|
|
264
|
-
Fs,
|
|
265
|
-
times,
|
|
266
|
-
meanvalue,
|
|
267
|
-
dolfo=False,
|
|
268
|
-
lfowave=None,
|
|
269
|
-
lfomag=None,
|
|
270
|
-
lfodelay=None,
|
|
271
|
-
lfonoise=0.0,
|
|
272
|
-
lfofilter=None,
|
|
273
|
-
doresp=False,
|
|
274
|
-
respwave=None,
|
|
275
|
-
respmag=None,
|
|
276
|
-
respdelay=None,
|
|
277
|
-
respnoise=0.0,
|
|
278
|
-
respfilter=None,
|
|
279
|
-
docardiac=False,
|
|
280
|
-
cardiacwave=None,
|
|
281
|
-
cardiacmag=None,
|
|
282
|
-
cardiacdelay=None,
|
|
283
|
-
cardiacnoise=0.0,
|
|
284
|
-
cardiacfilter=None,
|
|
285
|
-
):
|
|
358
|
+
Fs: float,
|
|
359
|
+
times: NDArray,
|
|
360
|
+
meanvalue: float,
|
|
361
|
+
dolfo: bool = False,
|
|
362
|
+
lfowave: Optional[object] = None,
|
|
363
|
+
lfomag: Optional[NDArray] = None,
|
|
364
|
+
lfodelay: Optional[Any] = None,
|
|
365
|
+
lfonoise: float = 0.0,
|
|
366
|
+
lfofilter: Optional[object] = None,
|
|
367
|
+
doresp: bool = False,
|
|
368
|
+
respwave: Optional[object] = None,
|
|
369
|
+
respmag: Optional[NDArray] = None,
|
|
370
|
+
respdelay: Optional[NDArray] = None,
|
|
371
|
+
respnoise: float = 0.0,
|
|
372
|
+
respfilter: Optional[object] = None,
|
|
373
|
+
docardiac: bool = False,
|
|
374
|
+
cardiacwave: Optional[object] = None,
|
|
375
|
+
cardiacmag: Optional[NDArray] = None,
|
|
376
|
+
cardiacdelay: Optional[NDArray] = None,
|
|
377
|
+
cardiacnoise: float = 0.0,
|
|
378
|
+
cardiacfilter: Optional[object] = None,
|
|
379
|
+
) -> NDArray:
|
|
380
|
+
"""
|
|
381
|
+
Generate an fMRI signal by combining multiple physiological waveforms.
|
|
382
|
+
|
|
383
|
+
This function constructs an fMRI signal by summing a base mean signal with
|
|
384
|
+
contributions from low-frequency oscillations (LFO), respiratory signals,
|
|
385
|
+
and cardiac signals, each optionally modulated by amplitude, delay, noise,
|
|
386
|
+
and filtering.
|
|
387
|
+
|
|
388
|
+
Parameters
|
|
389
|
+
----------
|
|
390
|
+
Fs : float
|
|
391
|
+
Sampling frequency of the signal.
|
|
392
|
+
times : NDArray
|
|
393
|
+
Time vector for the signal.
|
|
394
|
+
meanvalue : float
|
|
395
|
+
Base mean signal value.
|
|
396
|
+
dolfo : bool, optional
|
|
397
|
+
Whether to include low-frequency oscillation (LFO) component. Default is False.
|
|
398
|
+
lfowave : Optional[object], optional
|
|
399
|
+
Waveform object for LFO signal. Default is None.
|
|
400
|
+
lfomag : Optional[Any], optional
|
|
401
|
+
Magnitude of LFO signal. Default is None.
|
|
402
|
+
lfodelay : Optional[Any], optional
|
|
403
|
+
Delay for LFO signal. Default is None.
|
|
404
|
+
lfonoise : float, optional
|
|
405
|
+
Noise level for LFO signal. Default is 0.0.
|
|
406
|
+
lfofilter : Optional[object], optional
|
|
407
|
+
Filter object for LFO noise. Default is None.
|
|
408
|
+
doresp : bool, optional
|
|
409
|
+
Whether to include respiratory signal component. Default is False.
|
|
410
|
+
respwave : Optional[object], optional
|
|
411
|
+
Waveform object for respiratory signal. Default is None.
|
|
412
|
+
respmag : Optional[Any], optional
|
|
413
|
+
Magnitude of respiratory signal. Default is None.
|
|
414
|
+
respdelay : Optional[Any], optional
|
|
415
|
+
Delay for respiratory signal. Default is None.
|
|
416
|
+
respnoise : float, optional
|
|
417
|
+
Noise level for respiratory signal. Default is 0.0.
|
|
418
|
+
respfilter : Optional[object], optional
|
|
419
|
+
Filter object for respiratory noise. Default is None.
|
|
420
|
+
docardiac : bool, optional
|
|
421
|
+
Whether to include cardiac signal component. Default is False.
|
|
422
|
+
cardiacwave : Optional[object], optional
|
|
423
|
+
Waveform object for cardiac signal. Default is None.
|
|
424
|
+
cardiacmag : Optional[Any], optional
|
|
425
|
+
Magnitude of cardiac signal. Default is None.
|
|
426
|
+
cardiacdelay : Optional[Any], optional
|
|
427
|
+
Delay for cardiac signal. Default is None.
|
|
428
|
+
cardiacnoise : float, optional
|
|
429
|
+
Noise level for cardiac signal. Default is 0.0.
|
|
430
|
+
cardiacfilter : Optional[object], optional
|
|
431
|
+
Filter object for cardiac noise. Default is None.
|
|
432
|
+
|
|
433
|
+
Returns
|
|
434
|
+
-------
|
|
435
|
+
None
|
|
436
|
+
The function currently returns None. The actual signal is computed and returned
|
|
437
|
+
by the function body, but the return statement is not correctly implemented.
|
|
438
|
+
|
|
439
|
+
Notes
|
|
440
|
+
-----
|
|
441
|
+
The function modifies the signal in-place and returns a signal array that includes
|
|
442
|
+
contributions from all enabled physiological components. Each component is scaled
|
|
443
|
+
by `meanvalue` and optionally processed with delay, magnitude, noise, and filtering.
|
|
444
|
+
|
|
445
|
+
Examples
|
|
446
|
+
--------
|
|
447
|
+
>>> Fs = 100
|
|
448
|
+
>>> times = np.linspace(0, 10, 1000)
|
|
449
|
+
>>> meanvalue = 1.0
|
|
450
|
+
>>> signal = fmrisignal(Fs, times, meanvalue)
|
|
451
|
+
>>> # With LFO component enabled
|
|
452
|
+
>>> signal = fmrisignal(Fs, times, meanvalue, dolfo=True, lfowave=wave, lfomag=0.5)
|
|
453
|
+
"""
|
|
286
454
|
thesignal = np.zeros((len(times)), dtype=float)
|
|
287
455
|
if dolfo:
|
|
288
456
|
thesignal += meanvalue * (
|
|
@@ -299,10 +467,68 @@ def fmrisignal(
|
|
|
299
467
|
cardiacmag * cardiacwave.yfromx(times - cardiacdelay)
|
|
300
468
|
+ cardiacnoise * cardiacfilter.apply(Fs, np.random.standard_normal(len(times)))
|
|
301
469
|
)
|
|
302
|
-
|
|
470
|
+
thesignal += meanvalue
|
|
471
|
+
return thesignal
|
|
303
472
|
|
|
304
473
|
|
|
305
|
-
def simdata(args):
|
|
474
|
+
def simdata(args: Any) -> None:
|
|
475
|
+
"""
|
|
476
|
+
Generate simulated fMRI data based on physiological signal regressors.
|
|
477
|
+
|
|
478
|
+
This function simulates fMRI time series data by incorporating physiological
|
|
479
|
+
signals such as low-frequency oscillations (LFO), respiratory, and cardiac
|
|
480
|
+
signals. It reads in regressor files, applies filtering, and generates
|
|
481
|
+
voxel-wise time series using a signal simulation function.
|
|
482
|
+
|
|
483
|
+
Parameters
|
|
484
|
+
----------
|
|
485
|
+
args : Any
|
|
486
|
+
An object containing command-line arguments specifying input and output
|
|
487
|
+
parameters. Expected attributes include:
|
|
488
|
+
- lfopctfile, lfosigfracfile, lfolagfile, lforegressor, lfosamprate,
|
|
489
|
+
lfostarttime: LFO-related input files and parameters.
|
|
490
|
+
- resppctfile, respsigfracfile, resplagfile, respregressor, respsamprate,
|
|
491
|
+
respstarttime: Respiratory-related input files and parameters.
|
|
492
|
+
- cardiacpctfile, cardiacsigfracfile, cardiaclagfile, cardiacregressor,
|
|
493
|
+
cardiacsamprate, cardiacstarttime: Cardiac-related input files and parameters.
|
|
494
|
+
- immeanfilename: Path to the mean image file.
|
|
495
|
+
- numtrs, numskip, fmritr: fMRI time series parameters.
|
|
496
|
+
- slicetimefile: Optional path to slice timing file.
|
|
497
|
+
- outputroot: Root name for output NIfTI files.
|
|
498
|
+
- globalnoiselevel, voxelnoiselevel: Noise parameters.
|
|
499
|
+
- debug: Boolean flag for debug output.
|
|
500
|
+
|
|
501
|
+
Returns
|
|
502
|
+
-------
|
|
503
|
+
None
|
|
504
|
+
This function does not return a value but saves the simulated fMRI data
|
|
505
|
+
to NIfTI files.
|
|
506
|
+
|
|
507
|
+
Notes
|
|
508
|
+
-----
|
|
509
|
+
The function requires at least one of LFO, respiratory, or cardiac signal
|
|
510
|
+
parameters to be specified. If none are provided, the function will print
|
|
511
|
+
help and exit.
|
|
512
|
+
|
|
513
|
+
Examples
|
|
514
|
+
--------
|
|
515
|
+
>>> import argparse
|
|
516
|
+
>>> args = argparse.Namespace(
|
|
517
|
+
... lfopctfile='lfo_pct.nii.gz',
|
|
518
|
+
... lfolagfile='lfo_lag.nii.gz',
|
|
519
|
+
... lforegressor='lfo_regressor.txt',
|
|
520
|
+
... lfosamprate=10.0,
|
|
521
|
+
... immeanfilename='mean_func.nii.gz',
|
|
522
|
+
... numtrs=200,
|
|
523
|
+
... numskip=10,
|
|
524
|
+
... fmritr=2.0,
|
|
525
|
+
... outputroot='simulated_data',
|
|
526
|
+
... globalnoiselevel=0.1,
|
|
527
|
+
... voxelnoiselevel=0.05,
|
|
528
|
+
... debug=False
|
|
529
|
+
... )
|
|
530
|
+
>>> simdata(args)
|
|
531
|
+
"""
|
|
306
532
|
# set default variable values
|
|
307
533
|
lfopctdata = None
|
|
308
534
|
lfolagdata = None
|
|
@@ -17,6 +17,8 @@
|
|
|
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
|
from matplotlib.pyplot import *
|
|
22
24
|
from tqdm import tqdm
|
|
@@ -26,7 +28,32 @@ import rapidtide.io as tide_io
|
|
|
26
28
|
import rapidtide.workflows.parser_funcs as pf
|
|
27
29
|
|
|
28
30
|
|
|
29
|
-
def _get_parser():
|
|
31
|
+
def _get_parser() -> Any:
|
|
32
|
+
"""
|
|
33
|
+
Create and configure an argument parser for the spatialfit command-line tool.
|
|
34
|
+
|
|
35
|
+
This function sets up an `argparse.ArgumentParser` with specific arguments
|
|
36
|
+
required for fitting a 3D or 4D NIFTI file to a spatial template. It includes
|
|
37
|
+
validation for file inputs and supports optional masking and fitting parameters.
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
argparse.ArgumentParser
|
|
42
|
+
Configured argument parser with defined command-line arguments.
|
|
43
|
+
|
|
44
|
+
Notes
|
|
45
|
+
-----
|
|
46
|
+
The parser is configured with:
|
|
47
|
+
- Required positional arguments: `datafile`, `templatefile`, and `outputroot`.
|
|
48
|
+
- Optional arguments: `--datamask`, `--templatemask`, `--order`, and `--debug`.
|
|
49
|
+
|
|
50
|
+
Examples
|
|
51
|
+
--------
|
|
52
|
+
>>> parser = _get_parser()
|
|
53
|
+
>>> args = parser.parse_args(['data.nii', 'template.nii', 'output_root'])
|
|
54
|
+
>>> print(args.datafile)
|
|
55
|
+
'data.nii'
|
|
56
|
+
"""
|
|
30
57
|
# get the command line parameters
|
|
31
58
|
parser = argparse.ArgumentParser(
|
|
32
59
|
prog="spatialfit",
|
|
@@ -80,7 +107,55 @@ def _get_parser():
|
|
|
80
107
|
return parser
|
|
81
108
|
|
|
82
109
|
|
|
83
|
-
def spatialfit(args):
|
|
110
|
+
def spatialfit(args: Any) -> None:
|
|
111
|
+
"""
|
|
112
|
+
Perform spatial fitting of fMRI data using a template-based linear regression model.
|
|
113
|
+
|
|
114
|
+
This function reads input data and template files, performs masking, and fits a
|
|
115
|
+
linear model at each spatial location to estimate spatially varying linear coefficients,
|
|
116
|
+
offsets, and R² values. It outputs time series of these parameters along with fitted,
|
|
117
|
+
residual, and normalized data volumes.
|
|
118
|
+
|
|
119
|
+
Parameters
|
|
120
|
+
----------
|
|
121
|
+
args : Any
|
|
122
|
+
Parsed command-line arguments. Expected to contain the following attributes:
|
|
123
|
+
- datafile : str
|
|
124
|
+
Path to the input NIfTI data file.
|
|
125
|
+
- templatefile : str
|
|
126
|
+
Path to the template NIfTI file.
|
|
127
|
+
- dmask : str, optional
|
|
128
|
+
Path to the data mask NIfTI file.
|
|
129
|
+
- tmask : str, optional
|
|
130
|
+
Path to the template mask NIfTI file.
|
|
131
|
+
- outputroot : str
|
|
132
|
+
Root name for output files.
|
|
133
|
+
- debug : bool, optional
|
|
134
|
+
Enable debug printing.
|
|
135
|
+
|
|
136
|
+
Returns
|
|
137
|
+
-------
|
|
138
|
+
None
|
|
139
|
+
This function does not return a value but writes multiple NIfTI and text files
|
|
140
|
+
to disk.
|
|
141
|
+
|
|
142
|
+
Notes
|
|
143
|
+
-----
|
|
144
|
+
The function assumes that the input data and template files have compatible
|
|
145
|
+
spatial dimensions. It performs a linear regression for each timepoint and
|
|
146
|
+
stores the resulting coefficients, offsets, and R² values.
|
|
147
|
+
|
|
148
|
+
Examples
|
|
149
|
+
--------
|
|
150
|
+
>>> import argparse
|
|
151
|
+
>>> args = argparse.Namespace(
|
|
152
|
+
... datafile='data.nii.gz',
|
|
153
|
+
... templatefile='template.nii.gz',
|
|
154
|
+
... outputroot='output',
|
|
155
|
+
... debug=False
|
|
156
|
+
... )
|
|
157
|
+
>>> spatialfit(args)
|
|
158
|
+
"""
|
|
84
159
|
# get the command line parameters
|
|
85
160
|
try:
|
|
86
161
|
args = _get_parser().parse_args()
|