rapidtide 3.0a15__py3-none-any.whl → 3.0.2__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.
@@ -227,7 +227,7 @@ def rapidtide_main(argparsingfunc):
227
227
  gc.enable()
228
228
  print("turning on garbage collection")
229
229
 
230
- # if running in Docker or Apptainer/Singularity, this is necessary to enforce memory limits properly
230
+ # If running in Docker or Apptainer/Singularity, this is necessary to enforce memory limits properly
231
231
  # otherwise likely to error out in gzip.py or at voxelnormalize step. But do nothing if running in CircleCI
232
232
  # because it does NOT like you messing with the container.
233
233
  optiondict["containertype"] = tide_util.checkifincontainer()
@@ -364,16 +364,13 @@ def rapidtide_main(argparsingfunc):
364
364
  theinputdata = tide_voxelData.VoxelData(inputdatafilename, timestep=optiondict["realtr"])
365
365
  if optiondict["debug"]:
366
366
  theinputdata.summarize()
367
- nim = theinputdata.nim
368
- nim_hdr = theinputdata.nim_hdr
369
- nim_affine = theinputdata.nim_affine
370
367
  xsize, ysize, numslices, timepoints = theinputdata.getdims()
371
368
  thesizes = theinputdata.thesizes
372
369
  xdim, ydim, slicethickness, fmritr = theinputdata.getsizes()
373
370
  numspatiallocs = theinputdata.numspatiallocs
374
371
  nativespaceshape = theinputdata.nativespaceshape
375
- cifti_hdr = theinputdata.cifti_hdr
376
372
  fmritr = theinputdata.timestep
373
+ optiondict["filetype"] = theinputdata.filetype
377
374
  if theinputdata.filetype == "cifti":
378
375
  fileiscifti = True
379
376
  optiondict["textio"] = False
@@ -447,9 +444,9 @@ def rapidtide_main(argparsingfunc):
447
444
  anatomicmasks.append(
448
445
  tide_mask.readamask(
449
446
  optiondict[thisanatomic[0]],
450
- nim_hdr,
447
+ theinputdata.nim_hdr,
451
448
  xsize,
452
- istext=optiondict["textio"],
449
+ istext=(theinputdata.filetype == "text"),
453
450
  valslist=optiondict[thisanatomic[1]],
454
451
  maskname=thisanatomic[2],
455
452
  tolerance=optiondict["spatialtolerance"],
@@ -476,8 +473,8 @@ def rapidtide_main(argparsingfunc):
476
473
  if optiondict["gausssigma"] > 0.0:
477
474
  TimingLGR.info("End 3D smoothing")
478
475
 
479
- # reshape the data and trim to a time range, if specified. Check for special case of no trimming to save RAM
480
- fmri_data = theinputdata.voxelbytime()
476
+ # Reshape the data and trim to a time range, if specified. Check for special case of no trimming to save RAM
477
+ fmri_data = theinputdata.byvoxel()
481
478
  print(f"{fmri_data.shape=}")
482
479
 
483
480
  # detect zero mean data
@@ -512,9 +509,9 @@ def rapidtide_main(argparsingfunc):
512
509
  optiondict["globalmeanincludevals"],
513
510
  optiondict["globalmeanexcludename"],
514
511
  optiondict["globalmeanexcludevals"],
515
- nim_hdr,
512
+ theinputdata.nim_hdr,
516
513
  numspatiallocs,
517
- istext=optiondict["textio"],
514
+ istext=(theinputdata.filetype == "text"),
518
515
  tolerance=optiondict["spatialtolerance"],
519
516
  )
520
517
  if internalinvbrainmask is not None:
@@ -529,9 +526,9 @@ def rapidtide_main(argparsingfunc):
529
526
  optiondict["refineincludevals"],
530
527
  optiondict["refineexcludename"],
531
528
  optiondict["refineexcludevals"],
532
- nim_hdr,
529
+ theinputdata.nim_hdr,
533
530
  numspatiallocs,
534
- istext=optiondict["textio"],
531
+ istext=(theinputdata.filetype == "text"),
535
532
  tolerance=optiondict["spatialtolerance"],
536
533
  )
537
534
  if internalinvbrainmask is not None:
@@ -546,9 +543,9 @@ def rapidtide_main(argparsingfunc):
546
543
  optiondict["offsetincludevals"],
547
544
  optiondict["offsetexcludename"],
548
545
  optiondict["offsetexcludevals"],
549
- nim_hdr,
546
+ theinputdata.nim_hdr,
550
547
  numspatiallocs,
551
- istext=optiondict["textio"],
548
+ istext=(theinputdata.filetype == "text"),
552
549
  tolerance=optiondict["spatialtolerance"],
553
550
  )
554
551
  if internalinvbrainmask is not None:
@@ -565,9 +562,9 @@ def rapidtide_main(argparsingfunc):
565
562
  if optiondict["corrmaskincludename"] is not None:
566
563
  thecorrmask = tide_mask.readamask(
567
564
  optiondict["corrmaskincludename"],
568
- nim_hdr,
565
+ theinputdata.nim_hdr,
569
566
  xsize,
570
- istext=optiondict["textio"],
567
+ istext=(theinputdata.filetype == "text"),
571
568
  valslist=optiondict["corrmaskincludevals"],
572
569
  maskname="correlation",
573
570
  tolerance=optiondict["spatialtolerance"],
@@ -577,7 +574,7 @@ def rapidtide_main(argparsingfunc):
577
574
 
578
575
  # last line sanity check - if data is 0 over all time in a voxel, force corrmask to zero.
579
576
  datarange = np.max(fmri_data, axis=1) - np.min(fmri_data, axis=1)
580
- if optiondict["textio"]:
577
+ if theinputdata.filetype == "text":
581
578
  tide_io.writenpvecs(
582
579
  datarange.reshape((numspatiallocs)),
583
580
  f"{outputname}_motionr2.txt",
@@ -586,18 +583,20 @@ def rapidtide_main(argparsingfunc):
586
583
  savename = f"{outputname}_desc-datarange"
587
584
  tide_io.savetonifti(
588
585
  datarange.reshape((xsize, ysize, numslices)),
589
- nim_hdr,
586
+ theinputdata.nim_hdr,
590
587
  savename,
591
588
  )
592
589
  corrmask[np.where(datarange == 0)] = 0.0
593
590
  else:
594
591
  # check to see if the data has been demeaned
595
- if fileiscifti or optiondict["textio"]:
596
- corrmask = np.uint(theinputdata.voxelbytime()[:, 0] * 0 + 1)
592
+ if theinputdata.filetype != "nifti":
593
+ corrmask = np.uint(theinputdata.byvoxel()[:, 0] * 0 + 1)
597
594
  else:
598
595
  if not optiondict["dataiszeromean"]:
599
596
  LGR.verbose("generating correlation mask from mean image")
600
- corrmask = np.uint16(tide_mask.makeepimask(nim).dataobj.reshape(numspatiallocs))
597
+ corrmask = np.uint16(
598
+ tide_mask.makeepimask(theinputdata.nim).dataobj.reshape(numspatiallocs)
599
+ )
601
600
  else:
602
601
  LGR.verbose("generating correlation mask from std image")
603
602
  corrmask = np.uint16(
@@ -638,11 +637,8 @@ def rapidtide_main(argparsingfunc):
638
637
  corrmask *= 0
639
638
  corrmask += 1
640
639
  threshval = -10000000.0
641
- if not (fileiscifti or optiondict["textio"]):
642
- theheader = copy.deepcopy(nim_hdr)
643
- theheader["dim"][0] = 3
644
- theheader["dim"][4] = 1
645
- theheader["pixdim"][4] = 1.0
640
+ if theinputdata.filetype == "nifti":
641
+ theheader = theinputdata.copyheader(numtimepoints=1)
646
642
  savename = f"{outputname}_desc-processed_mask"
647
643
  tide_io.savetonifti(corrmask.reshape(xsize, ysize, numslices), theheader, savename)
648
644
 
@@ -654,7 +650,7 @@ def rapidtide_main(argparsingfunc):
654
650
  numvalidspatiallocs = np.shape(validvoxels)[0]
655
651
  LGR.debug(f"validvoxels shape = {numvalidspatiallocs}")
656
652
  theinputdata.setvalidvoxels(validvoxels)
657
- fmri_data_valid = theinputdata.getvalidvoxels() + 0.0
653
+ fmri_data_valid = theinputdata.validdata() + 0.0
658
654
  LGR.verbose(
659
655
  f"original size = {np.shape(fmri_data)}, trimmed size = {np.shape(fmri_data_valid)}"
660
656
  )
@@ -794,8 +790,8 @@ def rapidtide_main(argparsingfunc):
794
790
  },
795
791
  )
796
792
  # save the confound filter R2 map
797
- if not optiondict["textio"]:
798
- if fileiscifti:
793
+ if theinputdata.filetype != "text":
794
+ if theinputdata.filetype == "cifti":
799
795
  timeindex = theheader["dim"][0] - 1
800
796
  spaceindex = theheader["dim"][0]
801
797
  theheader["dim"][timeindex] = 1
@@ -814,10 +810,9 @@ def rapidtide_main(argparsingfunc):
814
810
  nativespaceshape,
815
811
  theheader,
816
812
  bidsbasedict,
817
- textio=optiondict["textio"],
818
- fileiscifti=fileiscifti,
813
+ filetype=theinputdata.filetype,
819
814
  rt_floattype=rt_floattype,
820
- cifti_hdr=cifti_hdr,
815
+ cifti_hdr=theinputdata.cifti_hdr,
821
816
  )
822
817
  tide_stats.makeandsavehistogram(
823
818
  confoundr2,
@@ -843,23 +838,7 @@ def rapidtide_main(argparsingfunc):
843
838
  tide_util.logmem("after confound sLFO filter")
844
839
 
845
840
  if optiondict["saveconfoundfiltered"]:
846
- if not optiondict["textio"]:
847
- theheader = copy.deepcopy(nim_hdr)
848
- if fileiscifti:
849
- nativefmrishape = (1, 1, 1, validtimepoints, numspatiallocs)
850
- timeindex = theheader["dim"][0] - 1
851
- spaceindex = theheader["dim"][0]
852
- theheader["dim"][timeindex] = validtimepoints
853
- theheader["dim"][spaceindex] = numspatiallocs
854
- else:
855
- nativefmrishape = (xsize, ysize, numslices, validtimepoints)
856
- theheader["dim"][4] = validtimepoints
857
- theheader["pixdim"][4] = fmritr
858
- else:
859
- nativefmrishape = (xsize, validtimepoints)
860
- theheader = None
861
- cifti_hdr = None
862
-
841
+ theheader = theinputdata.copyheader(numtimepoints=validtimepoints, tr=fmritr)
863
842
  maplist = [
864
843
  (
865
844
  fmri_data_valid,
@@ -873,23 +852,22 @@ def rapidtide_main(argparsingfunc):
873
852
  outputname,
874
853
  maplist,
875
854
  validvoxels,
876
- nativefmrishape,
855
+ theinputdata.nativefmrishape,
877
856
  theheader,
878
857
  bidsbasedict,
879
- textio=optiondict["textio"],
880
- fileiscifti=fileiscifti,
858
+ filetype=theinputdata.filetype,
881
859
  rt_floattype=rt_floattype,
882
- cifti_hdr=cifti_hdr,
860
+ cifti_hdr=theinputdata.cifti_hdr,
883
861
  )
884
862
 
885
863
  # get rid of memory we aren't using
886
864
  tide_util.logmem("before purging full sized fmri data")
887
865
  meanvalue = np.mean(
888
- theinputdata.voxelbytime(),
866
+ theinputdata.byvoxel(),
889
867
  axis=1,
890
868
  )
891
869
  stddevvalue = np.std(
892
- theinputdata.voxelbytime(),
870
+ theinputdata.byvoxel(),
893
871
  axis=1,
894
872
  )
895
873
  covvalue = np.where(meanvalue > 0.0, stddevvalue / meanvalue, 0.0)
@@ -936,19 +914,9 @@ def rapidtide_main(argparsingfunc):
936
914
  inputperiod = meanperiod
937
915
  inputstarttime = meanstarttime
938
916
  inputvec = meanvec
939
- theheader = copy.deepcopy(nim_hdr)
940
917
 
941
918
  # save the meanmask
942
- if not optiondict["textio"]:
943
- if fileiscifti:
944
- timeindex = theheader["dim"][0] - 1
945
- spaceindex = theheader["dim"][0]
946
- theheader["dim"][timeindex] = 1
947
- theheader["dim"][spaceindex] = numspatiallocs
948
- else:
949
- theheader["dim"][0] = 3
950
- theheader["dim"][4] = 1
951
- theheader["pixdim"][4] = 1.0
919
+ theheader = theinputdata.copyheader(numtimepoints=1)
952
920
  masklist = [(meanmask, "globalmean", "mask", None, "Voxels used to calculate global mean")]
953
921
  tide_io.savemaplist(
954
922
  outputname,
@@ -957,10 +925,9 @@ def rapidtide_main(argparsingfunc):
957
925
  nativespaceshape,
958
926
  theheader,
959
927
  bidsbasedict,
960
- textio=optiondict["textio"],
961
- fileiscifti=fileiscifti,
928
+ filetype=theinputdata.filetype,
962
929
  rt_floattype=rt_floattype,
963
- cifti_hdr=cifti_hdr,
930
+ cifti_hdr=theinputdata.cifti_hdr,
964
931
  )
965
932
  optiondict["preprocskip"] = 0
966
933
  else:
@@ -1387,10 +1354,10 @@ def rapidtide_main(argparsingfunc):
1387
1354
  tide_util.logmem("after main array allocation")
1388
1355
 
1389
1356
  corroutlen = np.shape(trimmedcorrscale)[0]
1390
- if optiondict["textio"]:
1357
+ if theinputdata.filetype == "text":
1391
1358
  nativecorrshape = (xsize, corroutlen)
1392
1359
  else:
1393
- if fileiscifti:
1360
+ if theinputdata.filetype == "cifti":
1394
1361
  nativecorrshape = (1, 1, 1, corroutlen, numspatiallocs)
1395
1362
  else:
1396
1363
  nativecorrshape = (xsize, ysize, numslices, corroutlen)
@@ -1438,17 +1405,7 @@ def rapidtide_main(argparsingfunc):
1438
1405
  initialdelay_dims,
1439
1406
  initialdelay_sizes,
1440
1407
  ) = tide_io.readfromnifti(optiondict["initialdelayvalue"])
1441
- theheader = copy.deepcopy(nim_hdr)
1442
- if not optiondict["textio"]:
1443
- if fileiscifti:
1444
- timeindex = theheader["dim"][0] - 1
1445
- spaceindex = theheader["dim"][0]
1446
- theheader["dim"][timeindex] = 1
1447
- theheader["dim"][spaceindex] = numspatiallocs
1448
- else:
1449
- theheader["dim"][0] = 3
1450
- theheader["dim"][4] = 1
1451
- theheader["pixdim"][4] = 1.0
1408
+ theheader = theinputdata.copyheader(numtimepoints=1)
1452
1409
  if not tide_io.checkspacematch(theheader, initialdelay_header):
1453
1410
  raise ValueError("fixed delay map dimensions do not match fmri dimensions")
1454
1411
  theinitialdelay = initialdelay.reshape(numspatiallocs)[validvoxels]
@@ -1478,9 +1435,9 @@ def rapidtide_main(argparsingfunc):
1478
1435
  - fmritr * numpadtrs
1479
1436
  )
1480
1437
 
1481
- if optiondict["textio"]:
1438
+ if theinputdata.filetype == "text":
1482
1439
  nativefmrishape = (xsize, np.shape(initial_fmri_x)[0])
1483
- elif fileiscifti:
1440
+ elif theinputdata.filetype == "cifti":
1484
1441
  nativefmrishape = (1, 1, 1, np.shape(initial_fmri_x)[0], numspatiallocs)
1485
1442
  else:
1486
1443
  nativefmrishape = (xsize, ysize, numslices, np.shape(initial_fmri_x)[0])
@@ -1950,7 +1907,7 @@ def rapidtide_main(argparsingfunc):
1950
1907
  if optiondict["checkpoint"]:
1951
1908
  outcorrarray[:, :] = 0.0
1952
1909
  outcorrarray[validvoxels, :] = corrout[:, :]
1953
- if optiondict["textio"]:
1910
+ if theinputdata.filetype == "text":
1954
1911
  tide_io.writenpvecs(
1955
1912
  outcorrarray.reshape(nativecorrshape),
1956
1913
  f"{outputname}_corrout_prefit_pass" + str(thepass) + ".txt",
@@ -2142,8 +2099,8 @@ def rapidtide_main(argparsingfunc):
2142
2099
  internaldespeckleincludemask[validvoxels] == 0.0, 0, 1
2143
2100
  )
2144
2101
  if thepass == optiondict["passes"]:
2145
- if not optiondict["textio"]:
2146
- if fileiscifti:
2102
+ if theinputdata.filetype != "text":
2103
+ if theinputdata.filetype == "cifti":
2147
2104
  timeindex = theheader["dim"][0] - 1
2148
2105
  spaceindex = theheader["dim"][0]
2149
2106
  theheader["dim"][timeindex] = 1
@@ -2168,10 +2125,9 @@ def rapidtide_main(argparsingfunc):
2168
2125
  nativespaceshape,
2169
2126
  theheader,
2170
2127
  bidsbasedict,
2171
- textio=optiondict["textio"],
2172
- fileiscifti=fileiscifti,
2128
+ filetype=theinputdata.filetype,
2173
2129
  rt_floattype=rt_floattype,
2174
- cifti_hdr=cifti_hdr,
2130
+ cifti_hdr=theinputdata.cifti_hdr,
2175
2131
  )
2176
2132
  LGR.info(
2177
2133
  f"\n\n{voxelsprocessed_fc_ds} voxels despeckled in "
@@ -2206,18 +2162,17 @@ def rapidtide_main(argparsingfunc):
2206
2162
  nativespaceshape,
2207
2163
  theheader,
2208
2164
  bidsbasedict,
2209
- textio=optiondict["textio"],
2210
- fileiscifti=fileiscifti,
2165
+ filetype=theinputdata.filetype,
2211
2166
  rt_floattype=rt_floattype,
2212
- cifti_hdr=cifti_hdr,
2167
+ cifti_hdr=theinputdata.cifti_hdr,
2213
2168
  )
2214
2169
 
2215
2170
  # create list of anomalous 3D regions that don't match surroundings
2216
- if nim_affine is not None:
2171
+ if theinputdata.nim_affine is not None:
2217
2172
  # make an atlas of anomalous patches - each patch shares the same integer value
2218
2173
  step1 = tide_patch.calc_DoG(
2219
2174
  outmaparray.reshape(nativespaceshape).copy(),
2220
- nim_affine,
2175
+ theinputdata.nim_affine,
2221
2176
  thesizes,
2222
2177
  fwhm=optiondict["patchfwhm"],
2223
2178
  ratioopt=False,
@@ -2239,10 +2194,9 @@ def rapidtide_main(argparsingfunc):
2239
2194
  nativespaceshape,
2240
2195
  theheader,
2241
2196
  bidsbasedict,
2242
- textio=optiondict["textio"],
2243
- fileiscifti=fileiscifti,
2197
+ filetype=theinputdata.filetype,
2244
2198
  rt_floattype=rt_floattype,
2245
- cifti_hdr=cifti_hdr,
2199
+ cifti_hdr=theinputdata.cifti_hdr,
2246
2200
  )
2247
2201
  step2 = tide_patch.invertedflood3D(
2248
2202
  step1,
@@ -2264,10 +2218,9 @@ def rapidtide_main(argparsingfunc):
2264
2218
  nativespaceshape,
2265
2219
  theheader,
2266
2220
  bidsbasedict,
2267
- textio=optiondict["textio"],
2268
- fileiscifti=fileiscifti,
2221
+ filetype=theinputdata.filetype,
2269
2222
  rt_floattype=rt_floattype,
2270
- cifti_hdr=cifti_hdr,
2223
+ cifti_hdr=theinputdata.cifti_hdr,
2271
2224
  )
2272
2225
 
2273
2226
  patchmap = tide_patch.separateclusters(
@@ -2277,7 +2230,7 @@ def rapidtide_main(argparsingfunc):
2277
2230
  )
2278
2231
  # patchmap = tide_patch.getclusters(
2279
2232
  # outmaparray.reshape(nativespaceshape),
2280
- # nim_affine,
2233
+ # theinputdata.nim_affine,
2281
2234
  # thesizes,
2282
2235
  # fwhm=optiondict["patchfwhm"],
2283
2236
  # ratioopt=True,
@@ -2300,10 +2253,9 @@ def rapidtide_main(argparsingfunc):
2300
2253
  nativespaceshape,
2301
2254
  theheader,
2302
2255
  bidsbasedict,
2303
- textio=optiondict["textio"],
2304
- fileiscifti=fileiscifti,
2256
+ filetype=theinputdata.filetype,
2305
2257
  rt_floattype=rt_floattype,
2306
- cifti_hdr=cifti_hdr,
2258
+ cifti_hdr=theinputdata.cifti_hdr,
2307
2259
  )
2308
2260
 
2309
2261
  # now shift the patches to align with the majority of the image
@@ -2318,17 +2270,7 @@ def rapidtide_main(argparsingfunc):
2318
2270
  )
2319
2271
 
2320
2272
  if optiondict["saveintermediatemaps"]:
2321
- if not optiondict["textio"]:
2322
- theheader = copy.deepcopy(nim_hdr)
2323
- if fileiscifti:
2324
- timeindex = theheader["dim"][0] - 1
2325
- spaceindex = theheader["dim"][0]
2326
- theheader["dim"][timeindex] = 1
2327
- theheader["dim"][spaceindex] = numspatiallocs
2328
- else:
2329
- theheader["dim"][0] = 3
2330
- theheader["dim"][4] = 1
2331
- theheader["pixdim"][4] = 1.0
2273
+ theheader = theinputdata.copyheader(numtimepoints=1)
2332
2274
  bidspasssuffix = f"_intermediatedata-pass{thepass}"
2333
2275
  maplist = [
2334
2276
  (lagtimes, "maxtime", "map", "second", "Lag time in seconds"),
@@ -2349,10 +2291,9 @@ def rapidtide_main(argparsingfunc):
2349
2291
  nativespaceshape,
2350
2292
  theheader,
2351
2293
  bidsbasedict,
2352
- textio=optiondict["textio"],
2353
- fileiscifti=fileiscifti,
2294
+ filetype=theinputdata.filetype,
2354
2295
  rt_floattype=rt_floattype,
2355
- cifti_hdr=cifti_hdr,
2296
+ cifti_hdr=theinputdata.cifti_hdr,
2356
2297
  )
2357
2298
 
2358
2299
  # Step 3 - regressor refinement for next pass
@@ -2530,10 +2471,10 @@ def rapidtide_main(argparsingfunc):
2530
2471
  coherencefreqstep,
2531
2472
  coherencefreqaxissize,
2532
2473
  ) = theCoherer.getaxisinfo()
2533
- if optiondict["textio"]:
2474
+ if theinputdata.filetype == "text":
2534
2475
  nativecoherenceshape = (xsize, coherencefreqaxissize)
2535
2476
  else:
2536
- if fileiscifti:
2477
+ if theinputdata.filetype == "cifti":
2537
2478
  nativecoherenceshape = (1, 1, 1, coherencefreqaxissize, numspatiallocs)
2538
2479
  else:
2539
2480
  nativecoherenceshape = (xsize, ysize, numslices, coherencefreqaxissize)
@@ -2583,19 +2524,11 @@ def rapidtide_main(argparsingfunc):
2583
2524
  tide_util.enablemkl(optiondict["mklthreads"], debug=threaddebug)
2584
2525
 
2585
2526
  # save the results of the calculations
2586
- if not optiondict["textio"]:
2587
- theheader = copy.deepcopy(nim_hdr)
2588
- theheader["toffset"] = coherencefreqstart
2589
- theheader["pixdim"][4] = coherencefreqstep
2590
- if fileiscifti:
2591
- timeindex = theheader["dim"][0] - 1
2592
- spaceindex = theheader["dim"][0]
2593
- theheader["dim"][timeindex] = coherencefreqaxissize
2594
- theheader["dim"][spaceindex] = numspatiallocs
2595
- else:
2596
- theheader["dim"][0] = 3
2597
- theheader["dim"][4] = coherencefreqaxissize
2598
- theheader["pixdim"][4] = 1.0
2527
+ theheader = theinputdata.copyheader(
2528
+ numtimepoints=coherencefreqaxissize,
2529
+ tr=coherencefreqstep,
2530
+ toffset=coherencefreqstart,
2531
+ )
2599
2532
  maplist = [(coherencefunc, "coherence", "info", None, "Coherence function")]
2600
2533
  tide_io.savemaplist(
2601
2534
  outputname,
@@ -2604,10 +2537,9 @@ def rapidtide_main(argparsingfunc):
2604
2537
  nativecoherenceshape,
2605
2538
  theheader,
2606
2539
  bidsbasedict,
2607
- textio=optiondict["textio"],
2608
- fileiscifti=fileiscifti,
2540
+ filetype=theinputdata.filetype,
2609
2541
  rt_floattype=rt_floattype,
2610
- cifti_hdr=cifti_hdr,
2542
+ cifti_hdr=theinputdata.cifti_hdr,
2611
2543
  )
2612
2544
 
2613
2545
  TimingLGR.info(
@@ -2703,7 +2635,7 @@ def rapidtide_main(argparsingfunc):
2703
2635
  theinputdata.setvalidtimes(validstart, validend)
2704
2636
  theinputdata.setvalidvoxels(validvoxels)
2705
2637
 
2706
- fmri_data_valid = theinputdata.getvalidvoxels() + 0.0
2638
+ fmri_data_valid = theinputdata.validdata() + 0.0
2707
2639
 
2708
2640
  if optiondict["docvrmap"]:
2709
2641
  # percent normalize the fmri data
@@ -2806,20 +2738,13 @@ def rapidtide_main(argparsingfunc):
2806
2738
 
2807
2739
  if optiondict["debug"]:
2808
2740
  # dump the fmri input file going to sLFO filter
2809
- if not optiondict["textio"]:
2741
+ if theinputdata.filetype != "text":
2810
2742
  outfmriarray = np.zeros(internalfmrishape, dtype=rt_floattype)
2811
- theheader = copy.deepcopy(nim_hdr)
2812
- if fileiscifti:
2813
- timeindex = theheader["dim"][0] - 1
2814
- spaceindex = theheader["dim"][0]
2815
- theheader["dim"][timeindex] = np.shape(outfmriarray)[1]
2816
- theheader["dim"][spaceindex] = numspatiallocs
2817
- else:
2818
- theheader["dim"][4] = np.shape(outfmriarray)[1]
2819
- theheader["pixdim"][4] = fmritr
2743
+ theheader = theinputdata.copyheader(
2744
+ numtimepoints=np.shape(outfmriarray)[1], tr=fmritr
2745
+ )
2820
2746
  else:
2821
2747
  theheader = None
2822
- cifti_hdr = None
2823
2748
  outfmriarray = None
2824
2749
 
2825
2750
  maplist = [
@@ -2838,10 +2763,9 @@ def rapidtide_main(argparsingfunc):
2838
2763
  nativefmrishape,
2839
2764
  theheader,
2840
2765
  bidsbasedict,
2841
- textio=optiondict["textio"],
2842
- fileiscifti=fileiscifti,
2766
+ filetype=theinputdata.filetype,
2843
2767
  rt_floattype=rt_floattype,
2844
- cifti_hdr=cifti_hdr,
2768
+ cifti_hdr=theinputdata.cifti_hdr,
2845
2769
  )
2846
2770
  else:
2847
2771
  outfmriarray = None
@@ -2850,7 +2774,7 @@ def rapidtide_main(argparsingfunc):
2850
2774
  if optiondict["refinedelay"]:
2851
2775
  TimingLGR.info("Delay refinement start")
2852
2776
  LGR.info("\n\nDelay refinement")
2853
- if optiondict["delayoffsetgausssigma"] < 0.0 and not optiondict["textio"]:
2777
+ if optiondict["delayoffsetgausssigma"] < 0.0 and theinputdata.filetype != "text":
2854
2778
  # set gausssigma automatically
2855
2779
  optiondict["delayoffsetgausssigma"] = np.mean([xdim, ydim, slicethickness]) / 2.0
2856
2780
 
@@ -2888,8 +2812,7 @@ def rapidtide_main(argparsingfunc):
2888
2812
  (xdim, ydim, slicethickness),
2889
2813
  gausssigma=optiondict["delayoffsetgausssigma"],
2890
2814
  patchthresh=optiondict["delaypatchthresh"],
2891
- fileiscifti=fileiscifti,
2892
- textio=optiondict["textio"],
2815
+ filetype=theinputdata.filetype,
2893
2816
  rt_floattype="float64",
2894
2817
  debug=optiondict["debug"],
2895
2818
  )
@@ -2934,8 +2857,7 @@ def rapidtide_main(argparsingfunc):
2934
2857
  (xdim, ydim, slicethickness),
2935
2858
  gausssigma=optiondict["delayoffsetgausssigma"],
2936
2859
  patchthresh=optiondict["delaypatchthresh"],
2937
- fileiscifti=False,
2938
- textio=False,
2860
+ filetype=theinputdata.filetype,
2939
2861
  rt_floattype=rt_floattype,
2940
2862
  debug=optiondict["debug"],
2941
2863
  )
@@ -3145,21 +3067,7 @@ def rapidtide_main(argparsingfunc):
3145
3067
 
3146
3068
  # write the 3D maps that need to be remapped
3147
3069
  TimingLGR.info("Start saving maps")
3148
- if not optiondict["textio"]:
3149
- theheader = copy.deepcopy(nim_hdr)
3150
- if fileiscifti:
3151
- timeindex = theheader["dim"][0] - 1
3152
- spaceindex = theheader["dim"][0]
3153
- theheader["dim"][timeindex] = 1
3154
- theheader["dim"][spaceindex] = numspatiallocs
3155
- else:
3156
- theheader["dim"][0] = 3
3157
- theheader["dim"][4] = 1
3158
- theheader["pixdim"][4] = 1.0
3159
- else:
3160
- theheader = None
3161
- cifti_hdr = None
3162
-
3070
+ theheader = theinputdata.copyheader(numtimepoints=1)
3163
3071
  savelist = [
3164
3072
  (lagtimes, "maxtime", "map", "second", "Lag time in seconds"),
3165
3073
  (
@@ -3264,10 +3172,9 @@ def rapidtide_main(argparsingfunc):
3264
3172
  nativespaceshape,
3265
3173
  theheader,
3266
3174
  bidsbasedict,
3267
- textio=optiondict["textio"],
3268
- fileiscifti=fileiscifti,
3175
+ filetype=theinputdata.filetype,
3269
3176
  rt_floattype=rt_floattype,
3270
- cifti_hdr=cifti_hdr,
3177
+ cifti_hdr=theinputdata.cifti_hdr,
3271
3178
  )
3272
3179
  namesuffix = "_desc-MTT_hist"
3273
3180
  tide_stats.makeandsavehistogram(
@@ -3424,10 +3331,9 @@ def rapidtide_main(argparsingfunc):
3424
3331
  nativespaceshape,
3425
3332
  theheader,
3426
3333
  bidsbasedict,
3427
- textio=optiondict["textio"],
3428
- fileiscifti=fileiscifti,
3334
+ filetype=theinputdata.filetype,
3429
3335
  rt_floattype=rt_floattype,
3430
- cifti_hdr=cifti_hdr,
3336
+ cifti_hdr=theinputdata.cifti_hdr,
3431
3337
  )
3432
3338
 
3433
3339
  if optiondict["refinedelay"] and False:
@@ -3481,10 +3387,9 @@ def rapidtide_main(argparsingfunc):
3481
3387
  nativespaceshape,
3482
3388
  theheader,
3483
3389
  bidsbasedict,
3484
- textio=optiondict["textio"],
3485
- fileiscifti=fileiscifti,
3390
+ filetype=theinputdata.filetype,
3486
3391
  rt_floattype=rt_floattype,
3487
- cifti_hdr=cifti_hdr,
3392
+ cifti_hdr=theinputdata.cifti_hdr,
3488
3393
  )
3489
3394
 
3490
3395
  del fmri_data_valid
@@ -3525,10 +3430,9 @@ def rapidtide_main(argparsingfunc):
3525
3430
  nativespaceshape,
3526
3431
  theheader,
3527
3432
  bidsbasedict,
3528
- textio=optiondict["textio"],
3529
- fileiscifti=fileiscifti,
3433
+ filetype=theinputdata.filetype,
3530
3434
  rt_floattype=rt_floattype,
3531
- cifti_hdr=cifti_hdr,
3435
+ cifti_hdr=theinputdata.cifti_hdr,
3532
3436
  )
3533
3437
  del meanvalue
3534
3438
 
@@ -3564,10 +3468,9 @@ def rapidtide_main(argparsingfunc):
3564
3468
  nativespaceshape,
3565
3469
  theheader,
3566
3470
  bidsbasedict,
3567
- textio=optiondict["textio"],
3568
- fileiscifti=fileiscifti,
3471
+ filetype=theinputdata.filetype,
3569
3472
  rt_floattype=rt_floattype,
3570
- cifti_hdr=cifti_hdr,
3473
+ cifti_hdr=theinputdata.cifti_hdr,
3571
3474
  )
3572
3475
  del masklist
3573
3476
 
@@ -3594,10 +3497,9 @@ def rapidtide_main(argparsingfunc):
3594
3497
  nativespaceshape,
3595
3498
  theheader,
3596
3499
  bidsbasedict,
3597
- textio=optiondict["textio"],
3598
- fileiscifti=fileiscifti,
3500
+ filetype=theinputdata.filetype,
3599
3501
  rt_floattype=rt_floattype,
3600
- cifti_hdr=cifti_hdr,
3502
+ cifti_hdr=theinputdata.cifti_hdr,
3601
3503
  )
3602
3504
  del refinemask
3603
3505
 
@@ -3609,21 +3511,7 @@ def rapidtide_main(argparsingfunc):
3609
3511
  del fitmask
3610
3512
 
3611
3513
  # now do the 4D maps of the similarity function and friends
3612
- if not optiondict["textio"]:
3613
- theheader = copy.deepcopy(nim_hdr)
3614
- theheader["toffset"] = corrscale[corrorigin - lagmininpts]
3615
- if fileiscifti:
3616
- timeindex = theheader["dim"][0] - 1
3617
- spaceindex = theheader["dim"][0]
3618
- theheader["dim"][timeindex] = np.shape(outcorrarray)[1]
3619
- theheader["dim"][spaceindex] = numspatiallocs
3620
- else:
3621
- theheader["dim"][4] = np.shape(outcorrarray)[1]
3622
- theheader["pixdim"][4] = corrtr
3623
- else:
3624
- theheader = None
3625
- cifti_hdr = None
3626
-
3514
+ theheader = theinputdata.copyheader(numtimepoints=np.shape(outcorrarray)[1], tr=corrtr)
3627
3515
  if (
3628
3516
  optiondict["savecorrout"]
3629
3517
  or (optiondict["outputlevel"] != "min")
@@ -3650,10 +3538,9 @@ def rapidtide_main(argparsingfunc):
3650
3538
  nativecorrshape,
3651
3539
  theheader,
3652
3540
  bidsbasedict,
3653
- textio=optiondict["textio"],
3654
- fileiscifti=fileiscifti,
3541
+ filetype=theinputdata.filetype,
3655
3542
  rt_floattype=rt_floattype,
3656
- cifti_hdr=cifti_hdr,
3543
+ cifti_hdr=theinputdata.cifti_hdr,
3657
3544
  )
3658
3545
  del windowout
3659
3546
  del gaussout
@@ -3668,20 +3555,7 @@ def rapidtide_main(argparsingfunc):
3668
3555
  # now save all the files that are of the same length as the input data file and masked
3669
3556
  if outfmriarray is None:
3670
3557
  outfmriarray = np.zeros(internalfmrishape, dtype=rt_floattype)
3671
- if not optiondict["textio"]:
3672
- theheader = copy.deepcopy(nim_hdr)
3673
- if fileiscifti:
3674
- timeindex = theheader["dim"][0] - 1
3675
- spaceindex = theheader["dim"][0]
3676
- theheader["dim"][timeindex] = np.shape(outfmriarray)[1]
3677
- theheader["dim"][spaceindex] = numspatiallocs
3678
- else:
3679
- theheader["dim"][4] = np.shape(outfmriarray)[1]
3680
- theheader["pixdim"][4] = fmritr
3681
- else:
3682
- theheader = None
3683
- cifti_hdr = None
3684
-
3558
+ theheader = theinputdata.copyheader(numtimepoints=np.shape(outfmriarray)[1], tr=fmritr)
3685
3559
  maplist = []
3686
3560
  if optiondict["saveallsLFOfiltfiles"] and (
3687
3561
  optiondict["dolinfitfilt"] or optiondict["docvrmap"]
@@ -3775,10 +3649,9 @@ def rapidtide_main(argparsingfunc):
3775
3649
  nativefmrishape,
3776
3650
  theheader,
3777
3651
  bidsbasedict,
3778
- textio=optiondict["textio"],
3779
- fileiscifti=fileiscifti,
3652
+ filetype=theinputdata.filetype,
3780
3653
  rt_floattype=rt_floattype,
3781
- cifti_hdr=cifti_hdr,
3654
+ cifti_hdr=theinputdata.cifti_hdr,
3782
3655
  )
3783
3656
 
3784
3657
  # clean up