@@ -337,6 +337,9 @@ class CompCorInputSpec(BaseInterfaceInputSpec):
337
337
False , usedefault = True ,
338
338
desc = 'Use cosine basis to remove low-frequency trends pre-component '
339
339
'extraction' )
340
+ repetition_time = traits .Float (
341
+ desc = 'Repetition time (TR) of series - derived from image header if '
342
+ 'unspecified' )
340
343
save_hpf_basis = traits .Either (
341
344
traits .Bool , File , requires = ['high_pass_filter' ],
342
345
desc = 'Save high pass filter basis as text file' )
@@ -398,10 +401,10 @@ def _run_interface(self, runtime):
398
401
mmap = NUMPY_MMAP )
399
402
400
403
if len (imgseries .shape ) != 4 :
401
- raise ValueError ('tCompCor expected a 4-D nifti file. Input {} has '
402
- '{} dimensions (shape {})' .format (
403
- self .inputs . realigned_file , len ( imgseries . shape ) ,
404
- imgseries .shape ))
404
+ raise ValueError ('{} expected a 4-D nifti file. Input {} has '
405
+ '{} dimensions (shape {})' .format (
406
+ self ._header , self . inputs . realigned_file ,
407
+ len ( imgseries . shape ), imgseries .shape ))
405
408
406
409
if len (mask_images ) == 0 :
407
410
img = nb .Nifti1Image (np .ones (imgseries .shape [:3 ], dtype = np .bool ),
@@ -411,9 +414,27 @@ def _run_interface(self, runtime):
411
414
412
415
mask_images = self ._process_masks (mask_images , imgseries .get_data ())
413
416
417
+ TR = 0
418
+ if self .inputs .high_pass_filter :
419
+ if isdefined (self .inputs .repetition_time ):
420
+ TR = self .inputs .repetition_time
421
+ else :
422
+ # Derive TR from NIfTI header, if possible
423
+ try :
424
+ TR = imgseries .header .get_zooms ()[3 ]
425
+ if self .inputs .get_xyzt_units ()[1 ] == 'msec' :
426
+ TR /= 1000
427
+ except AttributeError , IndexError :
428
+ pass
429
+
430
+ if TR == 0 :
431
+ raise ValueError (
432
+ '{} cannot detect repetition time from image - '
433
+ 'Set the repetition_time input' .format (self ._header ))
434
+
414
435
components , hpf_basis = compute_noise_components (
415
436
imgseries .get_data (), mask_images , degree ,
416
- self .inputs .num_components , self .inputs .high_pass_filter )
437
+ self .inputs .num_components , self .inputs .high_pass_filter , TR )
417
438
418
439
components_file = os .path .join (os .getcwd (), self .inputs .components_file )
419
440
np .savetxt (components_file , components , fmt = b"%.10f" , delimiter = '\t ' ,
@@ -928,7 +949,7 @@ def combine_mask_files(mask_files, mask_method=None, mask_index=None):
928
949
929
950
930
951
def compute_noise_components (imgseries , mask_images , degree , num_components ,
931
- high_pass_filter = False ):
952
+ high_pass_filter = False , repetition_time = 0 ):
932
953
"""Compute the noise components from the imgseries for each mask
933
954
934
955
imgseries: a nibabel img
@@ -960,7 +981,8 @@ def compute_noise_components(imgseries, mask_images, degree, num_components,
960
981
if high_pass_filter :
961
982
# If degree == 0, remove mean in same pass
962
983
voxel_timecourses , hpf_basis = cosine_filter (
963
- voxel_timecourses , 2.5 , remove_mean = (degree == 0 ))
984
+ voxel_timecourses , repetition_time ,
985
+ remove_mean = (degree == 0 ))
964
986
965
987
# from paper:
966
988
# "The constant and linear trends of the columns in the matrix M were
0 commit comments