@@ -85,146 +85,7 @@ def _list_outputs(self):
8585 return outputs
8686
8787
88- class FmriRealign4dInputSpec (BaseInterfaceInputSpec ):
89-
90- in_file = InputMultiPath (
91- File (exists = True ), mandatory = True , desc = "File to realign" )
92- tr = traits .Float (desc = "TR in seconds" , mandatory = True )
93- slice_order = traits .List (
94- traits .Int (),
95- desc = ('0 based slice order. This would be equivalent to entering'
96- 'np.argsort(spm_slice_order) for this field. This effects'
97- 'interleaved acquisition. This field will be deprecated in'
98- 'future Nipy releases and be replaced by actual slice'
99- 'acquisition times.' ),
100- requires = ["time_interp" ])
101- tr_slices = traits .Float (desc = "TR slices" , requires = ['time_interp' ])
102- start = traits .Float (
103- 0.0 , usedefault = True , desc = "time offset into TR to align slices to" )
104- time_interp = traits .Enum (
105- True ,
106- requires = ["slice_order" ],
107- desc = "Assume smooth changes across time e.g.,\
108- fmri series. If you don't want slice timing \
109- correction set this to undefined" )
110- loops = InputMultiPath (
111- [5 ], traits .Int , usedefault = True , desc = "loops within each run" )
112- between_loops = InputMultiPath (
113- [5 ],
114- traits .Int ,
115- usedefault = True ,
116- desc = "loops used to \
117- realign different \
118- runs" )
119- speedup = InputMultiPath (
120- [5 ],
121- traits .Int ,
122- usedefault = True ,
123- desc = "successive image \
124- sub-sampling factors \
125- for acceleration" )
126-
127-
128- class FmriRealign4dOutputSpec (TraitedSpec ):
129-
130- out_file = OutputMultiPath (File (exists = True ), desc = "Realigned files" )
131- par_file = OutputMultiPath (
132- File (exists = True ), desc = "Motion parameter files" )
133-
134-
135- class FmriRealign4d (BaseInterface ):
136- """Simultaneous motion and slice timing correction algorithm
137-
138- This interface wraps nipy's FmriRealign4d algorithm [1]_.
139-
140- Examples
141- --------
142- >>> from nipype.interfaces.nipy.preprocess import FmriRealign4d
143- >>> realigner = FmriRealign4d()
144- >>> realigner.inputs.in_file = ['functional.nii']
145- >>> realigner.inputs.tr = 2
146- >>> realigner.inputs.slice_order = list(range(0,67))
147- >>> res = realigner.run() # doctest: +SKIP
148-
149- References
150- ----------
151- .. [1] Roche A. A four-dimensional registration algorithm with \
152- application to joint correction of motion and slice timing \
153- in fMRI. IEEE Trans Med Imaging. 2011 Aug;30(8):1546-54. DOI_.
154-
155- .. _DOI: http://dx.doi.org/10.1109/TMI.2011.2131152
156-
157- """
158-
159- input_spec = FmriRealign4dInputSpec
160- output_spec = FmriRealign4dOutputSpec
161- keywords = ['slice timing' , 'motion correction' ]
162-
163- def __init__ (self , ** inputs ):
164- DeprecationWarning (('Will be deprecated in release 0.13. Please use'
165- 'SpaceTimeRealigner' ))
166- BaseInterface .__init__ (self , ** inputs )
167-
168- def _run_interface (self , runtime ):
169- from nipy .algorithms .registration import FmriRealign4d as FR4d
170- all_ims = [load_image (fname ) for fname in self .inputs .in_file ]
171-
172- if not isdefined (self .inputs .tr_slices ):
173- TR_slices = None
174- else :
175- TR_slices = self .inputs .tr_slices
176-
177- R = FR4d (
178- all_ims ,
179- tr = self .inputs .tr ,
180- slice_order = self .inputs .slice_order ,
181- tr_slices = TR_slices ,
182- time_interp = self .inputs .time_interp ,
183- start = self .inputs .start )
184-
185- R .estimate (
186- loops = list (self .inputs .loops ),
187- between_loops = list (self .inputs .between_loops ),
188- speedup = list (self .inputs .speedup ))
189-
190- corr_run = R .resample ()
191- self ._out_file_path = []
192- self ._par_file_path = []
193-
194- for j , corr in enumerate (corr_run ):
195- self ._out_file_path .append (
196- os .path .abspath ('corr_%s.nii.gz' %
197- (split_filename (self .inputs .in_file [j ])[1 ])))
198- save_image (corr , self ._out_file_path [j ])
199-
200- self ._par_file_path .append (
201- os .path .abspath ('%s.par' %
202- (os .path .split (self .inputs .in_file [j ])[1 ])))
203- mfile = open (self ._par_file_path [j ], 'w' )
204- motion = R ._transforms [j ]
205- # nipy does not encode euler angles. return in original form of
206- # translation followed by rotation vector see:
207- # http://en.wikipedia.org/wiki/Rodrigues'_rotation_formula
208- for i , mo in enumerate (motion ):
209- params = [
210- '%.10f' % item
211- for item in np .hstack ((mo .translation , mo .rotation ))
212- ]
213- string = ' ' .join (params ) + '\n '
214- mfile .write (string )
215- mfile .close ()
216-
217- return runtime
218-
219- def _list_outputs (self ):
220- outputs = self ._outputs ().get ()
221- outputs ['out_file' ] = self ._out_file_path
222- outputs ['par_file' ] = self ._par_file_path
223- return outputs
224-
225-
22688class SpaceTimeRealignerInputSpec (BaseInterfaceInputSpec ):
227-
22889 in_file = InputMultiPath (
22990 File (exists = True ),
23091 mandatory = True ,
0 commit comments