rapidtide 3.0.2__py3-none-any.whl → 3.0.3__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.
@@ -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)
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(