Skip to content

Commit 949b504

Browse files
committed
[skip ds210][skip ds054][skip tests][skip docs] edits from effigies review
1 parent 11ea1c2 commit 949b504

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

fmriprep/workflows/bold/confounds.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -633,43 +633,39 @@ def _getbtthresh(medianval):
633633

634634

635635
def _remove_volumes(bold_file, skip_vols):
636-
import nibabel as nb
637-
from nipype.utils.filemanip import fname_presuffix
638-
639-
# load the bold file and get the 4d matrix
640-
bold_img = nb.load(bold_file)
641-
bold_data = bold_img.get_data()
636+
"""remove skip_vols from bold_file"""
637+
import nibabel as nb
638+
from nipype.utils.filemanip import fname_presuffix
642639

643-
# cut off the beginning volumes
644-
bold_data_cut = bold_data[..., skip_vols:]
640+
if skip_vols == 0:
641+
return bold_file
645642

646-
# modify header with new shape (fewer volumes)
647-
data_shape = list(bold_img.header.get_data_shape())
648-
data_shape[-1] -= skip_vols
649-
bold_img.header.set_data_shape(tuple(data_shape))
643+
out = fname_presuffix(bold_file, suffix='_cut')
644+
bold_img = nb.load(bold_file)
645+
bold_img.__class__(bold_img.dataobj[..., skip_vols:],
646+
bold_img.affine, bold_img.header).to_filename(out)
650647

651-
# save the resulting bold file
652-
out = fname_presuffix(bold_file, suffix='_cut')
653-
bold_img.__class__(bold_data_cut, bold_img.affine, bold_img.header).to_filename(out)
654-
return out
648+
return out
655649

656650

657651
def _add_volumes(bold_file, bold_cut_file, skip_vols):
658652
"""prepend skip_vols from bold_file onto bold_cut_file"""
659653
import nibabel as nb
654+
import numpy as np
660655
from nipype.utils.filemanip import fname_presuffix
661656

662-
# load the data
657+
if skip_vols == 0:
658+
return bold_cut_file
659+
663660
bold_img = nb.load(bold_file)
664-
bold_data = bold_img.get_data()
665661
bold_cut_img = nb.load(bold_cut_file)
666-
bold_cut_data = bold_cut_img.get_data()
667662

668-
# assign everything from skip_vols foward to bold_cut_data
669-
bold_data[..., skip_vols:] = bold_cut_data
663+
bold_data = np.concatenate((bold_img.dataobj[..., :skip_vols],
664+
bold_cut_img.dataobj), axis=3)
670665

671666
out = fname_presuffix(bold_cut_file, suffix='_addnonsteady')
672667
bold_img.__class__(bold_data, bold_img.affine, bold_img.header).to_filename(out)
668+
673669
return out
674670

675671

0 commit comments

Comments
 (0)