rapidtide 3.0.2__py3-none-any.whl → 3.0.4__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.
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright 2016-2025 Blaise Frederick
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ #
19
+ import numpy as np
20
+
21
+ from rapidtide.workflows.adjustoffset import _get_parser as adjustoffset_getparser
22
+ from rapidtide.workflows.aligntcs import _get_parser as aligntcs_getparser
23
+ from rapidtide.workflows.applydlfilter import _get_parser as applydlfilter_getparser
24
+ from rapidtide.workflows.atlasaverage import _get_parser as atlasaverage_getparser
25
+ from rapidtide.workflows.atlastool import _get_parser as atlastool_getparser
26
+ from rapidtide.workflows.calctexticc import _get_parser as calctexticc_getparser
27
+ from rapidtide.workflows.ccorrica import _get_parser as ccorrica_getparser
28
+ from rapidtide.workflows.delayvar import _get_parser as delayvar_getparser
29
+ from rapidtide.workflows.diffrois import _get_parser as diffrois_getparser
30
+ from rapidtide.workflows.endtidalproc import _get_parser as endtidalproc_getparser
31
+ from rapidtide.workflows.fdica import _get_parser as fdica_getparser
32
+ from rapidtide.workflows.filtnifti import _get_parser as filtnifti_getparser
33
+ from rapidtide.workflows.filttc import _get_parser as filttc_getparser
34
+ from rapidtide.workflows.fixtr import _get_parser as fixtr_getparser
35
+ from rapidtide.workflows.gmscalc import _get_parser as gmscalc_getparser
36
+ from rapidtide.workflows.happy_parser import _get_parser as happy_parser_getparser
37
+ from rapidtide.workflows.happy2std import _get_parser as happy2std_getparser
38
+ from rapidtide.workflows.histnifti import _get_parser as histnifti_getparser
39
+ from rapidtide.workflows.histtc import _get_parser as histtc_getparser
40
+ from rapidtide.workflows.linfitfilt import _get_parser as linfitfilt_getparser
41
+ from rapidtide.workflows.localflow import _get_parser as localflow_getparser
42
+ from rapidtide.workflows.mergequality import _get_parser as mergequality_getparser
43
+ from rapidtide.workflows.niftidecomp import _get_parser_temporal as niftidecomp_getparser_temporal
44
+ from rapidtide.workflows.niftidecomp import _get_parser_spatial as niftidecomp_getparser_spatial
45
+ from rapidtide.workflows.niftistats import _get_parser as niftistats_getparser
46
+ from rapidtide.workflows.pairproc import _get_parser as pairproc_getparser
47
+ from rapidtide.workflows.pairwisemergenifti import _get_parser as pairwisemergenifti_getparser
48
+ from rapidtide.workflows.physiofreq import _get_parser as physiofreq_getparser
49
+ from rapidtide.workflows.pixelcomp import _get_parser as pixelcomp_getparser
50
+ from rapidtide.workflows.plethquality import _get_parser as plethquality_getparser
51
+ from rapidtide.workflows.polyfitim import _get_parser as polyfitim_getparser
52
+ from rapidtide.workflows.proj2flow import _get_parser as proj2flow_getparser
53
+ from rapidtide.workflows.rankimage import _get_parser as rankimage_getparser
54
+ from rapidtide.workflows.rapidtide2std import _get_parser as rapidtide2std_getparser
55
+ from rapidtide.workflows.resamplenifti import _get_parser as resamplenifti_getparser
56
+ from rapidtide.workflows.resampletc import _get_parser as resampletc_getparser
57
+ from rapidtide.workflows.retrolagtcs import _get_parser as retrolagtcs_getparser
58
+ from rapidtide.workflows.retroregress import _get_parser as retroregress_getparser
59
+ from rapidtide.workflows.roisummarize import _get_parser as roisummarize_getparser
60
+ from rapidtide.workflows.runqualitycheck import _get_parser as runqualitycheck_getparser
61
+ from rapidtide.workflows.showarbcorr import _get_parser as showarbcorr_getparser
62
+ from rapidtide.workflows.showhist import _get_parser as showhist_getparser
63
+ from rapidtide.workflows.showstxcorr import _get_parser as showstxcorr_getparser
64
+ from rapidtide.workflows.showtc import _get_parser as showtc_getparser
65
+ from rapidtide.workflows.showxcorrx import _get_parser as showxcorrx_getparser
66
+ from rapidtide.workflows.showxy import _get_parser as showxy_getparser
67
+ from rapidtide.workflows.simdata import _get_parser as simdata_getparser
68
+ from rapidtide.workflows.spatialfit import _get_parser as spatialfit_getparser
69
+ from rapidtide.workflows.spatialmi import _get_parser as spatialmi_getparser
70
+ from rapidtide.workflows.spectrogram import _get_parser as spectrogram_getparser
71
+ from rapidtide.workflows.synthASL import _get_parser as synthASL_getparser
72
+ from rapidtide.workflows.tcfrom2col import _get_parser as tcfrom2col_getparser
73
+ from rapidtide.workflows.tcfrom3col import _get_parser as tcfrom3col_getparser
74
+ from rapidtide.workflows.variabilityizer import _get_parser as variabilityizer_getparser
75
+
76
+
77
+ def test_parsers(debug=False):
78
+ parserlist = [ adjustoffset_getparser,
79
+ aligntcs_getparser,
80
+ applydlfilter_getparser,
81
+ atlasaverage_getparser,
82
+ atlastool_getparser,
83
+ calctexticc_getparser,
84
+ ccorrica_getparser,
85
+ delayvar_getparser,
86
+ diffrois_getparser,
87
+ endtidalproc_getparser,
88
+ fdica_getparser,
89
+ filtnifti_getparser,
90
+ filttc_getparser,
91
+ fixtr_getparser,
92
+ gmscalc_getparser,
93
+ happy_parser_getparser,
94
+ happy2std_getparser,
95
+ histnifti_getparser,
96
+ histtc_getparser,
97
+ linfitfilt_getparser,
98
+ localflow_getparser,
99
+ mergequality_getparser,
100
+ niftidecomp_getparser_temporal,
101
+ niftidecomp_getparser_spatial,
102
+ niftistats_getparser,
103
+ pairproc_getparser,
104
+ pairwisemergenifti_getparser,
105
+ physiofreq_getparser,
106
+ pixelcomp_getparser,
107
+ plethquality_getparser,
108
+ polyfitim_getparser,
109
+ proj2flow_getparser,
110
+ rankimage_getparser,
111
+ rapidtide2std_getparser,
112
+ resamplenifti_getparser,
113
+ resampletc_getparser,
114
+ retrolagtcs_getparser,
115
+ retroregress_getparser,
116
+ roisummarize_getparser,
117
+ runqualitycheck_getparser,
118
+ showarbcorr_getparser,
119
+ showhist_getparser,
120
+ showstxcorr_getparser,
121
+ showtc_getparser,
122
+ showxcorrx_getparser,
123
+ showxy_getparser,
124
+ simdata_getparser,
125
+ spatialfit_getparser,
126
+ spatialmi_getparser,
127
+ spectrogram_getparser,
128
+ synthASL_getparser,
129
+ tcfrom2col_getparser,
130
+ tcfrom3col_getparser,
131
+ variabilityizer_getparser ]
132
+
133
+ for thegetparser in parserlist:
134
+ theusage = thegetparser().format_help()
135
+ if debug:
136
+ print(theusage)
137
+
138
+
139
+ if __name__ == "__main__":
140
+ test_parsers(debug=True)
@@ -25,9 +25,17 @@ import rapidtide.io as tide_io
25
25
  from rapidtide.tests.utils import create_dir, get_examples_path, get_test_temp_path, mse
26
26
 
27
27
 
28
- def test_io(debug=True, displayplots=False):
28
+ def test_io(debug=True, local=False, displayplots=False):
29
+ # set input and output directories
30
+ if local:
31
+ exampleroot = "../data/examples/src"
32
+ testtemproot = "./tmp"
33
+ else:
34
+ exampleroot = get_examples_path()
35
+ testtemproot = get_test_temp_path()
36
+
29
37
  # create outputdir if it doesn't exist
30
- create_dir(get_test_temp_path())
38
+ create_dir(testtemproot)
31
39
 
32
40
  # test checkifnifti
33
41
  assert tide_io.checkifnifti("test.nii") == True
@@ -88,12 +96,12 @@ def test_io(debug=True, displayplots=False):
88
96
  # test fmritimeinfo
89
97
  fmritimeinfothresh = 1e-2
90
98
  tr, timepoints = tide_io.fmritimeinfo(
91
- os.path.join(get_examples_path(), "sub-HAPPYTEST.nii.gz")
99
+ os.path.join(exampleroot, "sub-HAPPYTEST.nii.gz")
92
100
  )
93
101
  assert np.fabs(tr - 1.16) < fmritimeinfothresh
94
102
  assert timepoints == 110
95
103
  tr, timepoints = tide_io.fmritimeinfo(
96
- os.path.join(get_examples_path(), "sub-RAPIDTIDETEST.nii.gz")
104
+ os.path.join(exampleroot, "sub-RAPIDTIDETEST.nii.gz")
97
105
  )
98
106
  assert np.fabs(tr - 1.5) < fmritimeinfothresh
99
107
  assert timepoints == 260
@@ -101,10 +109,10 @@ def test_io(debug=True, displayplots=False):
101
109
  # test niftifile reading
102
110
  sizethresh = 1e-3
103
111
  happy_img, happy_data, happy_hdr, happydims, happysizes = tide_io.readfromnifti(
104
- os.path.join(get_examples_path(), "sub-HAPPYTEST.nii.gz")
112
+ os.path.join(exampleroot, "sub-HAPPYTEST.nii.gz")
105
113
  )
106
114
  fmri_img, fmri_data, fmri_hdr, fmridims, fmrisizes = tide_io.readfromnifti(
107
- os.path.join(get_examples_path(), "sub-RAPIDTIDETEST.nii.gz")
115
+ os.path.join(exampleroot, "sub-RAPIDTIDETEST.nii.gz")
108
116
  )
109
117
  targetdims = [4, 65, 89, 64, 110, 1, 1, 1]
110
118
  targetsizes = [-1.00, 2.39583, 2.395830, 2.4, 1.16, 0.00, 0.00, 0.00]
@@ -120,7 +128,7 @@ def test_io(debug=True, displayplots=False):
120
128
  # test file writing
121
129
  datathresh = 2e-3 # relaxed threshold because sub-RAPIDTIDETEST has been converted to INT16
122
130
  tide_io.savetonifti(
123
- fmri_data, fmri_hdr, os.path.join(get_test_temp_path(), "sub-RAPIDTIDETEST_copy.nii.gz")
131
+ fmri_data, fmri_hdr, os.path.join(testtemproot, "sub-RAPIDTIDETEST_copy.nii.gz")
124
132
  )
125
133
  (
126
134
  fmricopy_img,
@@ -128,7 +136,7 @@ def test_io(debug=True, displayplots=False):
128
136
  fmricopy_hdr,
129
137
  fmricopydims,
130
138
  fmricopysizes,
131
- ) = tide_io.readfromnifti(os.path.join(get_test_temp_path(), "sub-RAPIDTIDETEST_copy.nii.gz"))
139
+ ) = tide_io.readfromnifti(os.path.join(testtemproot, "sub-RAPIDTIDETEST_copy.nii.gz"))
132
140
  assert tide_io.checkspacematch(fmri_hdr, fmricopy_hdr)
133
141
  assert tide_io.checktimematch(fmridims, fmridims)
134
142
  assert mse(fmri_data, fmricopy_data) < datathresh
@@ -141,10 +149,10 @@ def test_io(debug=True, displayplots=False):
141
149
 
142
150
  # test writing and reading text files
143
151
  debug = False
144
- DESTDIR = get_test_temp_path()
145
- SOURCEDIR = get_examples_path()
152
+ DESTDIR = testtemproot
153
+ SOURCEDIR = exampleroot
146
154
  EPSILON = 1e-5
147
- numpoints = 10
155
+ numpoints = 100
148
156
  the2darray = np.zeros((6, numpoints), dtype=float)
149
157
  the2darray[0, :] = np.linspace(0, 1.0, numpoints, endpoint=False)
150
158
  the2darray[1, :] = np.sin(the2darray[0, :] * 2.0 * np.pi)
@@ -174,7 +182,7 @@ def test_io(debug=True, displayplots=False):
174
182
  ["plaintsv", True, ".tsv.gz"],
175
183
  ]
176
184
 
177
- print("writing files")
185
+ print("writing files as a unit")
178
186
  for thistest in thetests:
179
187
  thetype = thistest[0]
180
188
  compressed = thistest[1]
@@ -218,6 +226,43 @@ def test_io(debug=True, displayplots=False):
218
226
  debug=debug,
219
227
  )
220
228
 
229
+ theappendtests = [
230
+ ["bidscontinuous", False, ".tsv"],
231
+ ["bidscontinuous", True, ".tsv.gz"],
232
+ ]
233
+
234
+ print("writing files with append")
235
+ for thistest in theappendtests:
236
+ thetype = thistest[0]
237
+ compressed = thistest[1]
238
+ if compressed:
239
+ compname = "compressed"
240
+ else:
241
+ compname = "uncompressed"
242
+
243
+ print(f"{the2darray.shape=}")
244
+ thefileroot = os.path.join(DESTDIR, f"testout_withcol_{thetype}_{compname}")
245
+ print(f"\t writing: {thefileroot}")
246
+ tide_io.writebidstsv(
247
+ thefileroot + "_append",
248
+ the2darray[:5, :],
249
+ inputsamplerate,
250
+ starttime=inputstarttime,
251
+ columns=thecols[:5],
252
+ compressed=compressed,
253
+ debug=debug,
254
+ )
255
+ tide_io.writebidstsv(
256
+ thefileroot + "_append",
257
+ the2darray[5, :],
258
+ inputsamplerate,
259
+ starttime=inputstarttime,
260
+ columns=[thecols[5]],
261
+ compressed=compressed,
262
+ append=True,
263
+ debug=debug,
264
+ )
265
+
221
266
  print("reading complete files")
222
267
  for thistest in thetests:
223
268
  thetype = thistest[0]
@@ -456,4 +501,4 @@ def test_io(debug=True, displayplots=False):
456
501
 
457
502
 
458
503
  if __name__ == "__main__":
459
- test_io(debug=True, displayplots=True)
504
+ test_io(debug=True, local=True, displayplots=True)
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright 2016-2025 Blaise Frederick
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ #
19
+ import os
20
+ import argparse
21
+ import rapidtide.workflows.parser_funcs as pf
22
+ from rapidtide.tests.utils import get_examples_path, get_test_temp_path
23
+
24
+ def _get_parser():
25
+ """
26
+ Argument parser for adjust offset
27
+ """
28
+ parser = argparse.ArgumentParser(
29
+ prog="dummy",
30
+ description="dummy",
31
+ allow_abbrev=False,
32
+ )
33
+
34
+ # Required arguments
35
+ parser.add_argument(
36
+ "inputmap",
37
+ type=lambda x: pf.is_valid_file(parser, x),
38
+ help="The name of the rapidtide maxtime map.",
39
+ )
40
+
41
+ return parser
42
+
43
+
44
+ def test_parserfuncs(debug=False, local=False, displayplots=False):
45
+ # set input and output directories
46
+ if local:
47
+ exampleroot = "../data/examples/src"
48
+ testtemproot = "./tmp"
49
+ else:
50
+ exampleroot = get_examples_path()
51
+ testtemproot = get_test_temp_path()
52
+
53
+
54
+ theparser = _get_parser()
55
+
56
+ filename = os.path.join(exampleroot,"sub-RAPIDTIDETEST_desc-oversampledmovingregressor_timeseries.json")
57
+ retval = pf.is_valid_file(theparser, filename)
58
+ print(filename, retval)
59
+
60
+ #filename = os.path.join(exampleroot,"sub-RAPIDTIDETEST_desc-oversampledmovingregressor_timeseriesxyz.json")
61
+ #retval = pf.is_valid_file(theparser, filename)
62
+ #print(filename, retval)
63
+
64
+ filename = os.path.join(exampleroot,"sub-RAPIDTIDETEST_desc-oversampledmovingregressor_timeseries.json:acolname")
65
+ retval = pf.is_valid_file(theparser, filename)
66
+ print(filename, retval)
67
+
68
+
69
+ if __name__ == "__main__":
70
+ test_parserfuncs(debug=True, local=True, displayplots=True)
@@ -59,7 +59,9 @@ def main(runninglocally=False):
59
59
  verbose=verbose,
60
60
  )
61
61
 
62
+ print("getting overlays")
62
63
  theoverlays = thesubject.getoverlays()
64
+ print("getting regressors")
63
65
  theregressors = thesubject.getregressors()
64
66
 
65
67
  assert thesubject.focusregressor == "prefilt"
rapidtide/voxelData.py CHANGED
@@ -128,6 +128,7 @@ class VoxelData:
128
128
  self.readdata(timestep, validstart, validend)
129
129
 
130
130
  def readdata(self, timestep, validstart, validend):
131
+ # load the data
131
132
  self.load()
132
133
 
133
134
  if tide_io.checkiftext(self.filename):
@@ -51,10 +51,32 @@ def cleanregressor(
51
51
  detrendorder=3,
52
52
  windowfunc="hamming",
53
53
  respdelete=False,
54
+ displayplots=False,
54
55
  debug=False,
55
56
  rt_floattype="float64",
56
57
  rt_floatset=np.float64,
57
58
  ):
59
+ # print debugging info
60
+ if debug:
61
+ print("cleanregressor:")
62
+ print(f"\t{thepass=}")
63
+ print(f"\t{lagmininpts=}")
64
+ print(f"\t{lagmaxinpts=}")
65
+ print(f"\t{lagmin=}")
66
+ print(f"\t{lagmax=}")
67
+ print(f"\t{detrendorder=}")
68
+ print(f"\t{windowfunc=}")
69
+ print(f"\t{respdelete=}")
70
+ print(f"\t{check_autocorrelation=}")
71
+ print(f"\t{fix_autocorrelation=}")
72
+ print(f"\t{despeckle_thresh=}")
73
+ print(f"\t{lthreshval=}")
74
+ print(f"\t{fixdelay=}")
75
+ print(f"\t{check_autocorrelation=}")
76
+ print(f"\t{displayplots=}")
77
+ print(f"\t{rt_floattype=}")
78
+ print(f"\t{rt_floatset=}")
79
+
58
80
  # check the regressor for periodic components in the passband
59
81
  dolagmod = True
60
82
  doreferencenotch = True
@@ -121,21 +143,33 @@ def cleanregressor(
121
143
  f"searching for sidelobes with amplitude > {theampthresh} "
122
144
  f"with abs(lag) < {thelagthresh} s"
123
145
  )
146
+ if debug:
147
+ print(
148
+ (
149
+ f"searching for sidelobes with amplitude > {theampthresh} "
150
+ f"with abs(lag) < {thelagthresh} s"
151
+ )
152
+ )
124
153
  sidelobetime, sidelobeamp = tide_corr.check_autocorrelation(
125
154
  accheckcorrscale,
126
155
  thexcorr,
127
156
  acampthresh=theampthresh,
128
157
  aclagthresh=thelagthresh,
129
158
  detrendorder=detrendorder,
159
+ displayplots=displayplots,
160
+ debug=debug,
130
161
  )
162
+ if debug:
163
+ print(f"check_autocorrelation returned: {sidelobetime=}, {sidelobeamp=}")
131
164
  absmaxsigma = acwidth * 10.0
132
165
  passsuffix = "_pass" + str(thepass)
133
166
  if sidelobetime is not None:
134
167
  despeckle_thresh = np.max([despeckle_thresh, sidelobetime / 2.0])
135
- LGR.warning(
136
- f"\n\nWARNING: check_autocorrelation found bad sidelobe at {sidelobetime} "
137
- f"seconds ({1.0 / sidelobetime} Hz)..."
138
- )
168
+ if LGR is not None:
169
+ LGR.warning(
170
+ f"\n\nWARNING: check_autocorrelation found bad sidelobe at {sidelobetime} "
171
+ f"seconds ({1.0 / sidelobetime} Hz)..."
172
+ )
139
173
  # bidsify
140
174
  """tide_io.writebidstsv(
141
175
  f"{outputname}_desc-movingregressor_timeseries",
@@ -160,7 +194,7 @@ def cleanregressor(
160
194
  LGR.info("removing spectral component at sidelobe frequency")
161
195
  acstopfreq = 1.0 / sidelobetime
162
196
  acfixfilter = tide_filt.NoncausalFilter(
163
- debug=debug,
197
+ debug=False,
164
198
  )
165
199
  acfixfilter.settype("arb_stop")
166
200
  acfixfilter.setfreqs(
@@ -175,7 +209,7 @@ def cleanregressor(
175
209
  detrendorder=detrendorder,
176
210
  )
177
211
  cleaned_referencetc = tide_math.corrnormalize(
178
- cleaned_resampref_y,
212
+ cleaned_resampref_y[osvalidsimcalcstart : osvalidsimcalcend + 1],
179
213
  detrendorder=detrendorder,
180
214
  windowfunc=windowfunc,
181
215
  )
@@ -222,6 +256,9 @@ def cleanregressor(
222
256
  cleaned_referencetc = 1.0 * referencetc
223
257
  cleaned_nonosreferencetc = 1.0 * resampnonosref_y
224
258
  else:
259
+ sidelobetime = None
260
+ sidelobeamp = None
261
+ lagmod = 1000.0
225
262
  acwidth = None
226
263
  absmaxsigma = None
227
264
  cleaned_resampref_y = 1.0 * tide_math.corrnormalize(