8
8
from ....interfaces import utility as util # utility
9
9
from ....pipeline import engine as pe # pypeline engine
10
10
from ....algorithms .misc import TSNR
11
-
12
-
13
- def extract_noise_components (realigned_file , noise_mask_file , num_components ):
14
- """Derive components most reflective of physiological noise
15
- """
16
- import os
17
- from nibabel import load
18
- import numpy as np
19
- import scipy as sp
20
- imgseries = load (realigned_file )
21
- components = None
22
- mask = load (noise_mask_file ).get_data ()
23
- voxel_timecourses = imgseries .get_data ()[mask > 0 ]
24
- voxel_timecourses [np .isnan (np .sum (voxel_timecourses , axis = 1 )), :] = 0
25
- # remove mean and normalize by variance
26
- # voxel_timecourses.shape == [nvoxels, time]
27
- X = voxel_timecourses .T
28
- stdX = np .std (X , axis = 0 )
29
- stdX [stdX == 0 ] = 1.
30
- stdX [np .isnan (stdX )] = 1.
31
- stdX [np .isinf (stdX )] = 1.
32
- X = (X - np .mean (X , axis = 0 )) / stdX
33
- u , _ , _ = sp .linalg .svd (X , full_matrices = False )
34
- if components is None :
35
- components = u [:, :num_components ]
36
- else :
37
- components = np .hstack ((components , u [:, :num_components ]))
38
- components_file = os .path .join (os .getcwd (), 'noise_components.txt' )
39
- np .savetxt (components_file , components , fmt = b"%.10f" )
40
- return components_file
41
-
11
+ from ....algorithms import compcor as cc
42
12
43
13
def select_volume (filename , which ):
44
14
"""Return the middle index of a file
@@ -148,11 +118,8 @@ def create_resting_preproc(name='restpreproc', base_dir=None):
148
118
getthresh = pe .Node (interface = fsl .ImageStats (op_string = '-p 98' ),
149
119
name = 'getthreshold' )
150
120
threshold_stddev = pe .Node (fsl .Threshold (), name = 'threshold' )
151
- compcor = pe .Node (util .Function (input_names = ['realigned_file' ,
152
- 'noise_mask_file' ,
153
- 'num_components' ],
154
- output_names = ['noise_components' ],
155
- function = extract_noise_components ),
121
+ compcor = pe .Node (cc .ACompCor (components_file = "noise_components.txt" ,
122
+ use_regress_poly = False ),
156
123
name = 'compcor' )
157
124
remove_noise = pe .Node (fsl .FilterRegressor (filter_all = True ),
158
125
name = 'remove_noise' )
@@ -170,12 +137,12 @@ def create_resting_preproc(name='restpreproc', base_dir=None):
170
137
restpreproc .connect (realigner , 'outputspec.realigned_file' ,
171
138
compcor , 'realigned_file' )
172
139
restpreproc .connect (threshold_stddev , 'out_file' ,
173
- compcor , 'noise_mask_file ' )
140
+ compcor , 'mask_file ' )
174
141
restpreproc .connect (inputnode , 'num_noise_components' ,
175
142
compcor , 'num_components' )
176
143
restpreproc .connect (tsnr , 'detrended_file' ,
177
144
remove_noise , 'in_file' )
178
- restpreproc .connect (compcor , 'noise_components ' ,
145
+ restpreproc .connect (compcor , 'components_file ' ,
179
146
remove_noise , 'design_file' )
180
147
restpreproc .connect (inputnode , 'highpass_sigma' ,
181
148
bandpass_filter , 'highpass_sigma' )
0 commit comments