Skip to content

Commit

Permalink
Merge pull request #224 from chrisfilo/fix/pymerge
Browse files Browse the repository at this point in the history
[RTM] use nibabel to merge nifti files
  • Loading branch information
chrisgorgo committed Dec 5, 2016
2 parents f96e7cf + b30c5dd commit 7497910
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions fmriprep/interfaces/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ def _tsv_format(translations, rot_angles, fmt='confounds'):
return out_file


def nii_concat(in_files):
from nibabel.funcs import concat_images
import os
new_nii = concat_images(in_files, check_affines=False)

new_nii.to_filename("merged.nii.gz")

return os.path.abspath("merged.nii.gz")


def reorient(in_file):
import os
import nibabel as nb
Expand Down
9 changes: 7 additions & 2 deletions fmriprep/workflows/epi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from fmriprep.interfaces import (DerivativesDataSink, FormatHMCParam,
ImageDataSink)
from fmriprep.interfaces.utils import nii_concat
from fmriprep.workflows.fieldmap import sdc_unwarp
from fmriprep.viz import stripped_brain_overlay
from fmriprep.workflows.sbref import _extract_wm
Expand Down Expand Up @@ -263,7 +264,9 @@ def epi_sbref_registration(settings, name='EPI_SBrefRegistration'):
epi_split = pe.Node(fsl.Split(dimension='t'), name='EPIsplit')
epi_xfm = pe.MapNode(fsl.preprocess.ApplyXFM(), name='EPIapplyXFM',
iterfield=['in_file'])
epi_merge = pe.Node(fsl.Merge(dimension='t'), name='EPImergeback')
epi_merge = pe.Node(niu.Function(input_names=["in_files"],
output_names=["merged_file"],
function=nii_concat), name='EPImergeback')

ds_sbref = pe.Node(
DerivativesDataSink(base_directory=settings['output_dir'],
Expand Down Expand Up @@ -356,7 +359,9 @@ def _aslist(in_value):
ants.ApplyTransforms(), iterfield=['input_image', 'transforms'],
name='EPIToMNITransform')
epi_to_mni_transform.terminal_output = 'file'
merge = pe.Node(fsl.Merge(dimension='t'), name='MergeEPI')
merge = pe.Node(niu.Function(input_names=["in_files"],
output_names=["merged_file"],
function=nii_concat), name='MergeEPI')

mask_merge_tfms = pe.Node(niu.Merge(2), name='MaskMergeTfms')
mask_mni_tfm = pe.Node(
Expand Down

0 comments on commit 7497910

Please sign in to comment.