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.
Files changed (144) hide show
  1. rapidtide/Colortables.py +492 -27
  2. rapidtide/OrthoImageItem.py +1049 -46
  3. rapidtide/RapidtideDataset.py +1533 -86
  4. rapidtide/_version.py +3 -3
  5. rapidtide/calccoherence.py +196 -29
  6. rapidtide/calcnullsimfunc.py +188 -40
  7. rapidtide/calcsimfunc.py +242 -42
  8. rapidtide/correlate.py +1203 -383
  9. rapidtide/data/examples/src/testLD +56 -0
  10. rapidtide/data/examples/src/testalign +1 -1
  11. rapidtide/data/examples/src/testdelayvar +0 -1
  12. rapidtide/data/examples/src/testfmri +53 -3
  13. rapidtide/data/examples/src/testglmfilt +5 -5
  14. rapidtide/data/examples/src/testhappy +29 -7
  15. rapidtide/data/examples/src/testppgproc +17 -0
  16. rapidtide/data/examples/src/testrolloff +11 -0
  17. rapidtide/data/models/model_cnn_pytorch/best_model.pth +0 -0
  18. rapidtide/data/models/model_cnn_pytorch/loss.png +0 -0
  19. rapidtide/data/models/model_cnn_pytorch/loss.txt +1 -0
  20. rapidtide/data/models/model_cnn_pytorch/model.pth +0 -0
  21. rapidtide/data/models/model_cnn_pytorch/model_meta.json +68 -0
  22. rapidtide/decorators.py +91 -0
  23. rapidtide/dlfilter.py +2226 -110
  24. rapidtide/dlfiltertorch.py +4842 -0
  25. rapidtide/externaltools.py +327 -12
  26. rapidtide/fMRIData_class.py +79 -40
  27. rapidtide/filter.py +1899 -810
  28. rapidtide/fit.py +2011 -581
  29. rapidtide/genericmultiproc.py +93 -18
  30. rapidtide/happy_supportfuncs.py +2047 -172
  31. rapidtide/helper_classes.py +584 -43
  32. rapidtide/io.py +2370 -372
  33. rapidtide/linfitfiltpass.py +346 -99
  34. rapidtide/makelaggedtcs.py +210 -24
  35. rapidtide/maskutil.py +448 -62
  36. rapidtide/miscmath.py +827 -121
  37. rapidtide/multiproc.py +210 -22
  38. rapidtide/patchmatch.py +242 -42
  39. rapidtide/peakeval.py +31 -31
  40. rapidtide/ppgproc.py +2203 -0
  41. rapidtide/qualitycheck.py +352 -39
  42. rapidtide/refinedelay.py +431 -57
  43. rapidtide/refineregressor.py +494 -189
  44. rapidtide/resample.py +671 -185
  45. rapidtide/scripts/applyppgproc.py +28 -0
  46. rapidtide/scripts/showxcorr_legacy.py +7 -7
  47. rapidtide/scripts/stupidramtricks.py +15 -17
  48. rapidtide/simFuncClasses.py +1052 -77
  49. rapidtide/simfuncfit.py +269 -69
  50. rapidtide/stats.py +540 -238
  51. rapidtide/tests/happycomp +9 -0
  52. rapidtide/tests/test_cleanregressor.py +1 -2
  53. rapidtide/tests/test_dlfiltertorch.py +627 -0
  54. rapidtide/tests/test_findmaxlag.py +24 -8
  55. rapidtide/tests/test_fullrunhappy_v1.py +0 -2
  56. rapidtide/tests/test_fullrunhappy_v2.py +0 -2
  57. rapidtide/tests/test_fullrunhappy_v3.py +11 -4
  58. rapidtide/tests/test_fullrunhappy_v4.py +10 -2
  59. rapidtide/tests/test_fullrunrapidtide_v7.py +1 -1
  60. rapidtide/tests/test_getparsers.py +11 -3
  61. rapidtide/tests/test_refinedelay.py +0 -1
  62. rapidtide/tests/test_simroundtrip.py +16 -8
  63. rapidtide/tests/test_stcorrelate.py +3 -1
  64. rapidtide/tests/utils.py +9 -8
  65. rapidtide/tidepoolTemplate.py +142 -38
  66. rapidtide/tidepoolTemplate_alt.py +165 -44
  67. rapidtide/tidepoolTemplate_big.py +189 -52
  68. rapidtide/util.py +1217 -118
  69. rapidtide/voxelData.py +684 -37
  70. rapidtide/wiener.py +136 -23
  71. rapidtide/wiener2.py +113 -7
  72. rapidtide/workflows/adjustoffset.py +105 -3
  73. rapidtide/workflows/aligntcs.py +85 -2
  74. rapidtide/workflows/applydlfilter.py +87 -10
  75. rapidtide/workflows/applyppgproc.py +540 -0
  76. rapidtide/workflows/atlasaverage.py +210 -47
  77. rapidtide/workflows/atlastool.py +100 -3
  78. rapidtide/workflows/calcSimFuncMap.py +288 -69
  79. rapidtide/workflows/calctexticc.py +201 -9
  80. rapidtide/workflows/ccorrica.py +101 -6
  81. rapidtide/workflows/cleanregressor.py +165 -31
  82. rapidtide/workflows/delayvar.py +171 -23
  83. rapidtide/workflows/diffrois.py +81 -3
  84. rapidtide/workflows/endtidalproc.py +144 -4
  85. rapidtide/workflows/fdica.py +195 -15
  86. rapidtide/workflows/filtnifti.py +70 -3
  87. rapidtide/workflows/filttc.py +74 -3
  88. rapidtide/workflows/fitSimFuncMap.py +202 -51
  89. rapidtide/workflows/fixtr.py +73 -3
  90. rapidtide/workflows/gmscalc.py +113 -3
  91. rapidtide/workflows/happy.py +801 -199
  92. rapidtide/workflows/happy2std.py +144 -12
  93. rapidtide/workflows/happy_parser.py +163 -23
  94. rapidtide/workflows/histnifti.py +118 -2
  95. rapidtide/workflows/histtc.py +84 -3
  96. rapidtide/workflows/linfitfilt.py +117 -4
  97. rapidtide/workflows/localflow.py +328 -28
  98. rapidtide/workflows/mergequality.py +79 -3
  99. rapidtide/workflows/niftidecomp.py +322 -18
  100. rapidtide/workflows/niftistats.py +174 -4
  101. rapidtide/workflows/pairproc.py +98 -4
  102. rapidtide/workflows/pairwisemergenifti.py +85 -2
  103. rapidtide/workflows/parser_funcs.py +1421 -40
  104. rapidtide/workflows/physiofreq.py +137 -11
  105. rapidtide/workflows/pixelcomp.py +207 -5
  106. rapidtide/workflows/plethquality.py +103 -21
  107. rapidtide/workflows/polyfitim.py +151 -11
  108. rapidtide/workflows/proj2flow.py +75 -2
  109. rapidtide/workflows/rankimage.py +111 -4
  110. rapidtide/workflows/rapidtide.py +368 -76
  111. rapidtide/workflows/rapidtide2std.py +98 -2
  112. rapidtide/workflows/rapidtide_parser.py +109 -9
  113. rapidtide/workflows/refineDelayMap.py +144 -33
  114. rapidtide/workflows/refineRegressor.py +675 -96
  115. rapidtide/workflows/regressfrommaps.py +161 -37
  116. rapidtide/workflows/resamplenifti.py +85 -3
  117. rapidtide/workflows/resampletc.py +91 -3
  118. rapidtide/workflows/retrolagtcs.py +99 -9
  119. rapidtide/workflows/retroregress.py +176 -26
  120. rapidtide/workflows/roisummarize.py +174 -5
  121. rapidtide/workflows/runqualitycheck.py +71 -3
  122. rapidtide/workflows/showarbcorr.py +149 -6
  123. rapidtide/workflows/showhist.py +86 -2
  124. rapidtide/workflows/showstxcorr.py +160 -3
  125. rapidtide/workflows/showtc.py +159 -3
  126. rapidtide/workflows/showxcorrx.py +190 -10
  127. rapidtide/workflows/showxy.py +185 -15
  128. rapidtide/workflows/simdata.py +264 -38
  129. rapidtide/workflows/spatialfit.py +77 -2
  130. rapidtide/workflows/spatialmi.py +250 -27
  131. rapidtide/workflows/spectrogram.py +305 -32
  132. rapidtide/workflows/synthASL.py +154 -3
  133. rapidtide/workflows/tcfrom2col.py +76 -2
  134. rapidtide/workflows/tcfrom3col.py +74 -2
  135. rapidtide/workflows/tidepool.py +2971 -130
  136. rapidtide/workflows/utils.py +19 -14
  137. rapidtide/workflows/utils_doc.py +293 -0
  138. rapidtide/workflows/variabilityizer.py +116 -3
  139. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/METADATA +10 -8
  140. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/RECORD +144 -128
  141. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/entry_points.txt +1 -0
  142. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/WHEEL +0 -0
  143. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/licenses/LICENSE +0 -0
  144. {rapidtide-3.0.11.dist-info → rapidtide-3.1.1.dist-info}/top_level.txt +0 -0
@@ -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
- from matplotlib.pyplot import *
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
- return thesignal + meanvalue
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()