@@ -144,6 +144,39 @@ def _run_interface(self, runtime):
144
144
return runtime
145
145
146
146
147
+ class _FramewiseDisplacementInputSpec (BaseInterfaceInputSpec ):
148
+ in_file = File (exists = True , desc = 'Head motion transform file' )
149
+ radius = traits .Float (50 , usedefault = True , desc = 'Radius of the head in mm' )
150
+
151
+
152
+ class _FramewiseDisplacementOutputSpec (TraitedSpec ):
153
+ out_file = File (desc = 'Output framewise displacement file' )
154
+
155
+
156
+ class FramewiseDisplacement (SimpleInterface ):
157
+ """Calculate framewise displacement estimates."""
158
+
159
+ input_spec = _FramewiseDisplacementInputSpec
160
+ output_spec = _FramewiseDisplacementOutputSpec
161
+
162
+ def _run_interface (self , runtime ):
163
+ self ._results ['out_file' ] = fname_presuffix (
164
+ self .inputs .in_file , suffix = '_fd.tsv' , newpath = runtime .cwd
165
+ )
166
+
167
+ motion = pd .read_csv (self .inputs .in_file , delimiter = '\t ' )
168
+
169
+ # Filter and ensure we have all parameters
170
+ diff = motion [['trans_x' , 'trans_y' , 'trans_z' , 'rot_x' , 'rot_y' , 'rot_z' ]].diff ()
171
+ diff [['rot_x' , 'rot_y' , 'rot_z' ]] *= self .inputs .radius
172
+
173
+ fd = pd .DataFrame (diff .abs ().sum (axis = 1 ), columns = ['FramewiseDisplacement' ])
174
+
175
+ fd .to_csv (self ._results ['out_file' ], sep = '\t ' , index = False )
176
+
177
+ return runtime
178
+
179
+
147
180
class _FilterDroppedInputSpec (BaseInterfaceInputSpec ):
148
181
in_file = File (exists = True , desc = 'input CompCor metadata' )
149
182
0 commit comments