def _run_interface(self, runtime): from nipy.algorithms.registration import FmriRealign4d as FR4d all_ims = [load_image(fname) for fname in self.inputs.in_file] if not isdefined(self.inputs.tr_slices): TR_slices = None else: TR_slices = self.inputs.tr_slices R = FR4d(all_ims, tr=self.inputs.tr, slice_order=self.inputs.slice_order, tr_slices=TR_slices, time_interp=self.inputs.time_interp, start=self.inputs.start) R.estimate(loops=list(self.inputs.loops), between_loops=list(self.inputs.between_loops), speedup=list(self.inputs.speedup)) corr_run = R.resample() self._out_file_path = [] self._par_file_path = [] for j, corr in enumerate(corr_run): self._out_file_path.append( os.path.abspath('corr_%s.nii.gz' % (split_filename(self.inputs.in_file[j])[1]))) save_image(corr, self._out_file_path[j]) self._par_file_path.append( os.path.abspath('%s.par' % (os.path.split(self.inputs.in_file[j])[1]))) mfile = open(self._par_file_path[j], 'w') motion = R._transforms[j] # nipy does not encode euler angles. return in original form of # translation followed by rotation vector see: # http://en.wikipedia.org/wiki/Rodrigues'_rotation_formula for i, mo in enumerate(motion): params = [ '%.10f' % item for item in np.hstack((mo.translation, mo.rotation)) ] string = ' '.join(params) + '\n' mfile.write(string) mfile.close() return runtime
def _run_interface(self, runtime): all_ims = [load_image(fname) for fname in self.inputs.in_file] if not isdefined(self.inputs.tr_slices): TR_slices = None else: TR_slices = self.inputs.tr_slices R = FR4d(all_ims, tr=self.inputs.tr, slice_order=self.inputs.slice_order, tr_slices=TR_slices, time_interp=self.inputs.time_interp, start=self.inputs.start) R.estimate(loops=self.inputs.loops, between_loops=self.inputs.between_loops, speedup=self.inputs.speedup) corr_run = R.resample() self._out_file_path = [] self._par_file_path = [] for j, corr in enumerate(corr_run): self._out_file_path.append(os.path.abspath('corr_%s.nii.gz' % (split_filename(self.inputs.in_file[j])[1]))) save_image(corr, self._out_file_path[j]) self._par_file_path.append(os.path.abspath('%s.par' % (os.path.split(self.inputs.in_file[j])[1]))) mfile = open(self._par_file_path[j], 'w') motion = R._transforms[j] #output a .par file that looks like fsl.mcflirt's .par file for i, mo in enumerate(motion): params = ['%.10f' % item for item in np.hstack((mo.rotation, mo.translation))] string = ' '.join(params) + '\n' mfile.write(string) mfile.close() return runtime