@@ -633,43 +633,39 @@ def _getbtthresh(medianval):
633
633
634
634
635
635
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
642
639
643
- # cut off the beginning volumes
644
- bold_data_cut = bold_data [..., skip_vols :]
640
+ if skip_vols == 0 :
641
+ return bold_file
645
642
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 )
650
647
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
655
649
656
650
657
651
def _add_volumes (bold_file , bold_cut_file , skip_vols ):
658
652
"""prepend skip_vols from bold_file onto bold_cut_file"""
659
653
import nibabel as nb
654
+ import numpy as np
660
655
from nipype .utils .filemanip import fname_presuffix
661
656
662
- # load the data
657
+ if skip_vols == 0 :
658
+ return bold_cut_file
659
+
663
660
bold_img = nb .load (bold_file )
664
- bold_data = bold_img .get_data ()
665
661
bold_cut_img = nb .load (bold_cut_file )
666
- bold_cut_data = bold_cut_img .get_data ()
667
662
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 )
670
665
671
666
out = fname_presuffix (bold_cut_file , suffix = '_addnonsteady' )
672
667
bold_img .__class__ (bold_data , bold_img .affine , bold_img .header ).to_filename (out )
668
+
673
669
return out
674
670
675
671
0 commit comments