Skip to content

Commit 11820cb

Browse files
committed
ref: consolidate compcor code to workflows
1 parent 4237bc0 commit 11820cb

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

examples/rsfmri_preprocessing.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
3939
The 2mm version was generated with::
4040
41-
>>> from nipype import freesurfer as fs
41+
>>> from nipype.interfaces import freesurfer as fs
4242
>>> rs = fs.Resample()
4343
>>> rs.inputs.in_file = 'OASIS-TRT-20_jointfusion_DKT31_CMA_labels_in_MNI152.nii.gz'
4444
>>> rs.inputs.resampled_file = 'OASIS-TRT-20_jointfusion_DKT31_CMA_labels_in_MNI152_2mm.nii.gz'
@@ -56,7 +56,8 @@
5656
from nipype import config
5757
config.enable_provenance()
5858

59-
from nipype import (ants, afni, fsl, freesurfer, nipy, Function, DataSink)
59+
from nipype.interfaces import (ants, afni, fsl, freesurfer, nipy, Function,
60+
DataSink)
6061
from nipype import Workflow, Node, MapNode
6162

6263
from nipype.algorithms.rapidart import ArtifactDetect
@@ -66,6 +67,7 @@
6667
from nipype.interfaces.c3 import C3dAffineTool
6768
from nipype.interfaces.utility import Merge, IdentityInterface
6869
from nipype.utils.filemanip import filename_to_list
70+
from nipype.workflows.rsfmri.fsl.resting import extract_noise_components
6971

7072
import numpy as np
7173
import scipy as sp
@@ -192,30 +194,6 @@ def build_filter1(motion_params, comp_norm, outliers):
192194
return out_files
193195

194196

195-
def extract_noise_components(realigned_file, mask_file, num_components=6):
196-
"""Derive components most reflective of physiological noise
197-
198-
Parameters
199-
----------
200-
realigned_file: a 4D Nifti file containing realigned volumes
201-
mask_file: a 3D Nifti file containing white matter + ventricular masks
202-
num_components: number of components to use for noise decomposition
203-
204-
Returns
205-
-------
206-
components_file: a text file containing the noise components
207-
"""
208-
imgseries = nb.load(realigned_file)
209-
noise_mask = nb.load(mask_file)
210-
voxel_timecourses = imgseries.get_data()[np.nonzero(noise_mask.get_data())]
211-
voxel_timecourses = voxel_timecourses.byteswap().newbyteorder()
212-
voxel_timecourses[np.isnan(np.sum(voxel_timecourses, axis=1)), :] = 0
213-
_, _, v = sp.linalg.svd(voxel_timecourses, full_matrices=False)
214-
components_file = os.path.join(os.getcwd(), 'noise_components.txt')
215-
np.savetxt(components_file, v[:num_components, :].T)
216-
return components_file
217-
218-
219197
def extract_subrois(timeseries_file, label_file, indices):
220198
"""Extract voxel time courses for each subcortical roi index
221199

0 commit comments

Comments
 (0)