@@ -353,13 +353,23 @@ def extract_vols(self, dwi_full_path, dwi_basename):
353
353
354
354
self .insert_json_value ('IntendedFor' , f'ses-{ self ._ses } /dwi/{ dwi_basename } ' , fmap_json_file_path )
355
355
356
- if self ._truncate_fmap :
357
- shape = nib .load (fmap_path ).get_fdata ().shape
356
+
357
+ def execute_fmap_truncation (self )
358
+ """
359
+ If truncate fmaps is true, this method will go through all of the fmaps in the fmap BIDS dir and make sure they are only one volume in length
360
+ """
361
+ if self ._truncate_fmap :
362
+ fmap_files = self ._layout .get (subject = self ._sub , session = self ._ses , suffix = 'epi' , extension = '.nii.gz' , return_type = 'filename' )
363
+
364
+ for fmap in fmap_files :
365
+ shape = nib .load (fmap ).get_fdata ().shape
358
366
if len (shape ) == 4 :
359
367
num_vols = shape [3 ]
368
+ if num_vols == 1 :
369
+ continue
360
370
middle_vol = num_vols // 2
361
371
362
- self .run_fslroi (fmap_path , middle_vol )
372
+ self .run_fslroi (fmap , middle_vol )
363
373
364
374
def run_fslroi (self , fmap , volume ):
365
375
vol_index = int (volume ) - 1
@@ -529,6 +539,7 @@ def build(self):
529
539
self .check_output_resolution ()
530
540
self .check_fieldmaps ()
531
541
self .delete_bval_bvec ()
542
+ self .execute_fmap_truncation ()
532
543
try :
533
544
qsiprep_command = yaml .safe_load (open (self ._qsiprep_config ))
534
545
except yaml .parser .ParserError :
0 commit comments