|
26 | 26 | import nipype.pipeline.engine as pe |
27 | 27 | import nipype.algorithms.modelgen as model |
28 | 28 | import nipype.algorithms.rapidart as ra |
29 | | -from nipype.algorithms.misc import TSNR |
| 29 | +from nipype.algorithms.misc import TSNR, CalculateMedian |
30 | 30 | from nipype.interfaces.c3 import C3dAffineTool |
31 | 31 | from nipype.interfaces import fsl, Function, ants, freesurfer as fs |
32 | 32 | import nipype.interfaces.io as nio |
|
55 | 55 | 'from scipy.special import legendre' |
56 | 56 | ] |
57 | 57 |
|
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 | | - |
85 | 58 |
|
86 | 59 | def create_reg_workflow(name='registration'): |
87 | 60 | """Create a FEAT preprocessing workflow together with freesurfer |
@@ -818,11 +791,7 @@ def check_behav_list(behav, run_id, conds): |
818 | 791 | wf.connect(preproc, "outputspec.realigned_files", tsnr, "in_file") |
819 | 792 |
|
820 | 793 | # 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') |
826 | 795 | wf.connect(tsnr, 'detrended_file', calc_median, 'in_files') |
827 | 796 |
|
828 | 797 | """ |
|
0 commit comments