@@ -102,8 +102,20 @@ def _add_extras(self, components, extra_regressors):
102
102
regressors = np .genfromtxt (self .inputs .extra_regressors )
103
103
return np .hstack ((components , regressors ))
104
104
105
+ class TCompCorInputSpec (CompCorInputSpec ):
106
+ # and all the fields in CompCorInputSpec
107
+ percentile_threshold = traits .Range (low = 0. , high = 1. , value = .02 ,
108
+ exclude_low = True , exclude_high = True ,
109
+ usedefault = True , desc = 'the percentile '
110
+ 'used to select highest-variance '
111
+ 'voxels. By default the 2% of voxels '
112
+ 'with the highest variance are used.' )
113
+
105
114
class TCompCor (CompCor ):
106
115
116
+ input_spec = TCompCorInputSpec
117
+ output_spec = CompCorOutputSpec
118
+
107
119
def _run_interface (self , runtime ):
108
120
imgseries = nb .load (self .inputs .realigned_file ).get_data ()
109
121
time_voxels = imgseries .T
@@ -119,16 +131,16 @@ def _run_interface(self, runtime):
119
131
tSTD = self ._compute_tSTD (time_voxels , 0 )
120
132
sortSTD = np .sort (tSTD , axis = None ) # flattened sorted matrix
121
133
122
- # "... and retained a pre-specified upper fraction of the sorted voxels
123
- # within each slice ... we chose a 2% threshold"
124
- threshold = sortSTD [int ( num_voxels * .98 ) ]
125
- mask = tSTD >= threshold
134
+ # use percentile_threshold to pick voxels
135
+ threshold_index = int ( num_voxels * ( 1. - self . inputs . percentile_threshold ))
136
+ threshold_std = sortSTD [threshold_index ]
137
+ mask = tSTD >= threshold_std
126
138
mask = mask .astype (int )
127
139
128
140
# save mask
129
141
mask_file = 'mask.nii'
130
142
nb .nifti1 .save (nb .Nifti1Image (mask , np .eye (4 )), mask_file )
131
- self .inputs .mask_file = 'mask.nii'
143
+ self .inputs .mask_file = mask_file
132
144
133
145
super (TCompCor , self )._run_interface (runtime )
134
146
return runtime
0 commit comments