Skip to content

Commit 5b06c8e

Browse files
committed
enh: update examples with new interface
1 parent 7f5fd97 commit 5b06c8e

File tree

3 files changed

+6
-45
lines changed

3 files changed

+6
-45
lines changed

examples/fmri_ants_openfmri.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import nipype.pipeline.engine as pe
2727
import nipype.algorithms.modelgen as model
2828
import nipype.algorithms.rapidart as ra
29-
from nipype.algorithms.misc import TSNR
29+
from nipype.algorithms.misc import TSNR, CalculateMedian
3030
from nipype.interfaces.c3 import C3dAffineTool
3131
from nipype.interfaces import fsl, Function, ants, freesurfer as fs
3232
import nipype.interfaces.io as nio
@@ -55,33 +55,6 @@
5555
'from scipy.special import legendre'
5656
]
5757

58-
def median(in_files):
59-
"""Computes an average of the median of each realigned timeseries
60-
61-
Parameters
62-
----------
63-
64-
in_files: one or more realigned Nifti 4D time series
65-
66-
Returns
67-
-------
68-
69-
out_file: a 3D Nifti file
70-
"""
71-
average = None
72-
for idx, filename in enumerate(filename_to_list(in_files)):
73-
img = nb.load(filename, mmap=NUMPY_MMAP)
74-
data = np.median(img.get_data(), axis=3)
75-
if average is None:
76-
average = data
77-
else:
78-
average = average + data
79-
median_img = nb.Nifti1Image(average / float(idx + 1), img.affine,
80-
img.header)
81-
filename = os.path.join(os.getcwd(), 'median.nii.gz')
82-
median_img.to_filename(filename)
83-
return filename
84-
8558

8659
def create_reg_workflow(name='registration'):
8760
"""Create a FEAT preprocessing workflow together with freesurfer
@@ -818,11 +791,7 @@ def check_behav_list(behav, run_id, conds):
818791
wf.connect(preproc, "outputspec.realigned_files", tsnr, "in_file")
819792

820793
# Compute the median image across runs
821-
calc_median = Node(Function(input_names=['in_files'],
822-
output_names=['median_file'],
823-
function=median,
824-
imports=imports),
825-
name='median')
794+
calc_median = Node(CalculateMedian(), name='median')
826795
wf.connect(tsnr, 'detrended_file', calc_median, 'in_files')
827796

828797
"""

examples/rsfmri_vol_surface_preprocessing.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
# mlab.MatlabCommand.set_default_paths('/software/matlab/spm12')
6868

6969
from nipype.algorithms.rapidart import ArtifactDetect
70-
from nipype.algorithms.misc import TSNR
70+
from nipype.algorithms.misc import TSNR, CalculateMedian
7171
from nipype.interfaces.utility import Rename, Merge, IdentityInterface
7272
from nipype.utils.filemanip import filename_to_list
7373
from nipype.interfaces.io import DataSink, FreeSurferSource
@@ -623,11 +623,7 @@ def create_workflow(files,
623623
wf.connect(slice_timing, 'timecorrected_files', tsnr, 'in_file')
624624

625625
# Compute the median image across runs
626-
calc_median = Node(Function(input_names=['in_files'],
627-
output_names=['median_file'],
628-
function=median,
629-
imports=imports),
630-
name='median')
626+
calc_median = Node(CalculateMedian(), name='median')
631627
wf.connect(tsnr, 'detrended_file', calc_median, 'in_files')
632628

633629
"""Segment and Register

examples/rsfmri_vol_surface_preprocessing_nipy.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
from nipype import Workflow, Node, MapNode
6666

6767
from nipype.algorithms.rapidart import ArtifactDetect
68-
from nipype.algorithms.misc import TSNR
68+
from nipype.algorithms.misc import TSNR, CalculateMedian
6969
from nipype.algorithms.confounds import ACompCor
7070
from nipype.interfaces.utility import Rename, Merge, IdentityInterface
7171
from nipype.utils.filemanip import filename_to_list
@@ -556,11 +556,7 @@ def create_workflow(files,
556556
wf.connect(realign, "out_file", tsnr, "in_file")
557557

558558
# Compute the median image across runs
559-
calc_median = Node(Function(input_names=['in_files'],
560-
output_names=['median_file'],
561-
function=median,
562-
imports=imports),
563-
name='median')
559+
calc_median = Node(CalculateMedian(), name='median')
564560
wf.connect(tsnr, 'detrended_file', calc_median, 'in_files')
565561

566562
"""Segment and Register

0 commit comments

Comments
 (0)