def _run_interface(self, runtime): EPI_data, EPI_voxel_sizes = broccoli.load_EPI(self.inputs.epi_file) T1_data, T1_voxel_sizes = broccoli.load_T1(self.inputs.t1_file) filters_parametric_mat = scipy.io.loadmat(self.inputs.filters_parametric) filters_nonparametric_mat = scipy.io.loadmat(self.inputs.filters_nonparametric) filters_parametric = [filters_parametric_mat['f%d_parametric_registration' % (i+1)] for i in range(3)] filters_nonparametric = [filters_nonparametric_mat['f%d_nonparametric_registration' % (i+1)] for i in range(6)] projection_tensor = [filters_nonparametric_mat['m%d' % (i+1)][0] for i in range(6)] filter_directions = [filters_nonparametric_mat['filter_directions_%s' % d][0] for d in ['x', 'y', 'z']] (Aligned_EPI_Volume, Interpolated_EPI_Volume, Registration_Parameters, Phase_Differences, Phase_Certainties, Phase_Gradients) = broccoli.registerEPIT1( EPI_data, EPI_voxel_sizes, T1_data, T1_voxel_sizes, filters_parametric, filters_nonparametric, projection_tensor, filter_directions, 20, int(round(8.0 / T1_voxel_sizes[0])), 20, self.inputs.opencl_platform, self.inputs.opencl_device, self.inputs.show_results, ) T1_nni = nb.load(self.inputs.t1_file) aligned_EPI_nni = nb.Nifti1Image(Aligned_EPI_Volume, None, T1_nni.get_header()) nb.save(aligned_EPI_nni, self._get_output_filename('_aligned.nii')) interpolated_EPI_nni = nb.Nifti1Image(Interpolated_EPI_Volume, None, T1_nni.get_header()) nb.save(interpolated_EPI_nni, self._get_output_filename('_interpolated.nii')) return runtime
def _run_interface(self, runtime): T1_data, T1_voxel_sizes = broccoli.load_T1(self.inputs.t1_file) MNI_data, MNI_brain_data, MNI_brain_mask_data, MNI_voxel_sizes = broccoli.load_MNI_templates(self.inputs.mni_file) filters_parametric_mat = scipy.io.loadmat(self.inputs.filters_parametric) filters_nonparametric_mat = scipy.io.loadmat(self.inputs.filters_nonparametric) filters_parametric = [filters_parametric_mat['f%d_parametric_registration' % (i+1)] for i in range(3)] filters_nonparametric = [filters_nonparametric_mat['f%d_nonparametric_registration' % (i+1)] for i in range(6)] projection_tensor = [filters_nonparametric_mat['m%d' % (i+1)][0] for i in range(6)] filter_directions = [filters_nonparametric_mat['filter_directions_%s' % d][0] for d in ['x', 'y', 'z']] (Aligned_T1_Volume, Aligned_T1_Volume_NonParametric, Skullstripped_T1_Volume, Interpolated_T1_Volume, Registration_Parameters, Phase_Differences, Phase_Certainties, Phase_Gradients, Slice_Sums, Top_Slice, A_Matrix, h_Vector) = broccoli.registerT1MNI( T1_data, T1_voxel_sizes, MNI_data, MNI_voxel_sizes, MNI_brain_data, MNI_brain_mask_data, filters_parametric, filters_nonparametric, projection_tensor, filter_directions, 10, 15, int(round(8 / MNI_voxel_sizes[0])), 30, self.inputs.opencl_platform, self.inputs.opencl_device, self.inputs.show_results, ) MNI_nni = nb.load(self.inputs.mni_file) aligned_T1_nni = nb.Nifti1Image(Aligned_T1_Volume, None, MNI_nni.get_header()) nb.save(aligned_T1_nni, self._get_output_filename('_aligned.nii')) interpolated_T1_nni = nb.Nifti1Image(Interpolated_T1_Volume, None, MNI_nni.get_header()) nb.save(interpolated_T1_nni, self._get_output_filename('_interpolated.nii')) return runtime
def _run_interface(self, runtime): EPI_data, EPI_voxel_sizes = broccoli.load_EPI(self.inputs.epi_file) T1_data, T1_voxel_sizes = broccoli.load_T1(self.inputs.t1_file) filters_parametric_mat = scipy.io.loadmat( self.inputs.filters_parametric) filters_nonparametric_mat = scipy.io.loadmat( self.inputs.filters_nonparametric) filters_parametric = [ filters_parametric_mat['f%d_parametric_registration' % (i + 1)] for i in range(3) ] filters_nonparametric = [ filters_nonparametric_mat['f%d_nonparametric_registration' % (i + 1)] for i in range(6) ] projection_tensor = [ filters_nonparametric_mat['m%d' % (i + 1)][0] for i in range(6) ] filter_directions = [ filters_nonparametric_mat['filter_directions_%s' % d][0] for d in ['x', 'y', 'z'] ] (Aligned_EPI_Volume, Interpolated_EPI_Volume, Registration_Parameters, Phase_Differences, Phase_Certainties, Phase_Gradients) = broccoli.registerEPIT1( EPI_data, EPI_voxel_sizes, T1_data, T1_voxel_sizes, filters_parametric, filters_nonparametric, projection_tensor, filter_directions, 20, int(round(8.0 / T1_voxel_sizes[0])), 20, self.inputs.opencl_platform, self.inputs.opencl_device, self.inputs.show_results, ) T1_nni = nb.load(self.inputs.t1_file) aligned_EPI_nni = nb.Nifti1Image(Aligned_EPI_Volume, None, T1_nni.get_header()) nb.save(aligned_EPI_nni, self._get_output_filename('_aligned.nii')) interpolated_EPI_nni = nb.Nifti1Image(Interpolated_EPI_Volume, None, T1_nni.get_header()) nb.save(interpolated_EPI_nni, self._get_output_filename('_interpolated.nii')) return runtime
def _run_interface(self, runtime): MNI, MNI_brain, MNI_brain_mask, MNI_voxel_sizes = broccoli.load_MNI_templates(self.inputs.MNI_file, self.inputs.MNI_brain_file, self.inputs.MNI_brain_mask_file) fMRI, fMRI_voxel_sizes = broccoli.load_EPI(self.inputs.fMRI_file, only_volume=False) T1, T1_voxel_sizes = broccoli.load_T1(self.inputs.T1_file) filters_parametric_mat = scipy.io.loadmat(self.inputs.filters_parametric) filters_nonparametric_mat = scipy.io.loadmat(self.inputs.filters_nonparametric) filters_parametric = [filters_parametric_mat['f%d_parametric_registration' % (i+1)] for i in range(3)] filters_nonparametric = [filters_nonparametric_mat['f%d_nonparametric_registration' % (i+1)] for i in range(6)] projection_tensor = [filters_nonparametric_mat['m%d' % (i+1)][0] for i in range(6)] filter_directions = [filters_nonparametric_mat['filter_directions_%s' % d][0] for d in ['x', 'y', 'z']] X_GLM = self.load_regressors(fMRI.shape[3]) print("X_GLM.shape = %s", X_GLM.shape) # print("X_GLM = %s", X_GLM) xtx = np.linalg.inv(np.dot(X_GLM.T, X_GLM)) print("xtx.shape = %s", xtx.shape) xtxxt_GLM = xtx.dot(X_GLM.T) confounds = 1 if self.inputs.regress_confounds: confounds = np.loadtxt(self.inputs.confounds_file) contrasts = np.array([[1, 0]]) print("contrasts = %s" % contrasts) ctxtxc_GLM = [contrasts[i:i+1].dot(xtx).dot(contrasts[i:i+1].T) for i in range(len(contrasts))] print("ctxtxc_GLM = %s" % ctxtxc_GLM) fMRI_voxel_sizes = [int(round(v)) for v in T1_voxel_sizes] T1_voxel_sizes = [int(round(v)) for v in T1_voxel_sizes] MNI_voxel_sizes = [int(round(v)) for v in T1_voxel_sizes] print("Parameters: %s" % self.inputs) statistical_maps = broccoli.performFirstLevelAnalysis( fMRI, fMRI_voxel_sizes, T1, T1_voxel_sizes, MNI, MNI_brain, MNI_brain_mask, MNI_voxel_sizes, filters_parametric, filters_nonparametric, projection_tensor, filter_directions, self.inputs.iterations_parametric, self.inputs.iterations_nonparametric, self.inputs.iterations_motion_correction, 4, 4, 0, 0, self.inputs.regress_motion, self.inputs.EPI_smoothing, self.inputs.AR_smoothing, X_GLM, xtxxt_GLM.transpose(), contrasts, ctxtxc_GLM, self.inputs.use_temporal_derivatives, getattr(broccoli, self.inputs.beta_space), confounds, self.inputs.regress_confounds, self.inputs.opencl_platform, self.inputs.opencl_device, self.inputs.show_results, ) EPI_nni = nb.load(self.inputs.fMRI_file) aligned_EPI_nni = nb.Nifti1Image(statistical_maps, None, EPI_nni.get_header()) nb.save(aligned_EPI_nni, self._get_output_filename('statistical_map.nii')) return runtime
'--filters-parametric-file', type=str, default="../Matlab_Wrapper/filters_for_parametric_registration.mat") parser.add_argument( '--filters-nonparametric-file', type=str, default="../Matlab_Wrapper/filters_for_nonparametric_registration.mat") parser.add_argument('--mm-t1-z-cut', type=int, default=30) parser.add_argument('--show-results', action='store_true') args = parser.parse_args() (MNI, MNI_brain, MNI_brain_mask, MNI_voxel_sizes) = broccoli.load_MNI_templates(args.mni_file) (T1, T1_voxel_sizes) = broccoli.load_T1(args.t1_file) coarsest_scale = int(round(8 / MNI_voxel_sizes[0])) filters_parametric_mat = scipy.io.loadmat(args.filters_parametric_file) filters_nonparametric_mat = scipy.io.loadmat( args.filters_nonparametric_file) parametric_filters = [ filters_parametric_mat['f%d_parametric_registration' % (i + 1)] for i in range(3) ] nonparametric_filters = [ filters_nonparametric_mat['f%d_nonparametric_registration' % (i + 1)] for i in range(6) ]
def _run_interface(self, runtime): T1_data, T1_voxel_sizes = broccoli.load_T1(self.inputs.t1_file) MNI_data, MNI_brain_data, MNI_brain_mask_data, MNI_voxel_sizes = broccoli.load_MNI_templates( self.inputs.mni_file) filters_parametric_mat = scipy.io.loadmat( self.inputs.filters_parametric) filters_nonparametric_mat = scipy.io.loadmat( self.inputs.filters_nonparametric) filters_parametric = [ filters_parametric_mat['f%d_parametric_registration' % (i + 1)] for i in range(3) ] filters_nonparametric = [ filters_nonparametric_mat['f%d_nonparametric_registration' % (i + 1)] for i in range(6) ] projection_tensor = [ filters_nonparametric_mat['m%d' % (i + 1)][0] for i in range(6) ] filter_directions = [ filters_nonparametric_mat['filter_directions_%s' % d][0] for d in ['x', 'y', 'z'] ] (Aligned_T1_Volume, Aligned_T1_Volume_NonParametric, Skullstripped_T1_Volume, Interpolated_T1_Volume, Registration_Parameters, Phase_Differences, Phase_Certainties, Phase_Gradients, Slice_Sums, Top_Slice, A_Matrix, h_Vector) = broccoli.registerT1MNI( T1_data, T1_voxel_sizes, MNI_data, MNI_voxel_sizes, MNI_brain_data, MNI_brain_mask_data, filters_parametric, filters_nonparametric, projection_tensor, filter_directions, 10, 15, int(round(8 / MNI_voxel_sizes[0])), 30, self.inputs.opencl_platform, self.inputs.opencl_device, self.inputs.show_results, ) MNI_nni = nb.load(self.inputs.mni_file) aligned_T1_nni = nb.Nifti1Image(Aligned_T1_Volume, None, MNI_nni.get_header()) nb.save(aligned_T1_nni, self._get_output_filename('_aligned.nii')) interpolated_T1_nni = nb.Nifti1Image(Interpolated_T1_Volume, None, MNI_nni.get_header()) nb.save(interpolated_T1_nni, self._get_output_filename('_interpolated.nii')) return runtime
parser.add_argument('--mni-brain-mask-file', type=str) parser.add_argument('--t1-file', type=str, required=True) parser.add_argument('--iterations-parametric', type=int, default=10) parser.add_argument('--iterations-nonparametric', type=int, default=15) parser.add_argument('--filters-parametric-file', type=str, default="../Matlab_Wrapper/filters_for_parametric_registration.mat") parser.add_argument('--filters-nonparametric-file', type=str, default="../Matlab_Wrapper/filters_for_nonparametric_registration.mat") parser.add_argument('--mm-t1-z-cut', type=int, default=30) parser.add_argument('--show-results', action='store_true') args = parser.parse_args() (MNI, MNI_brain, MNI_brain_mask, MNI_voxel_sizes) = broccoli.load_MNI_templates(args.mni_file) (T1, T1_voxel_sizes) = broccoli.load_T1(args.t1_file) coarsest_scale = int(round(8 / MNI_voxel_sizes[0])) filters_parametric_mat = scipy.io.loadmat(args.filters_parametric_file) filters_nonparametric_mat = scipy.io.loadmat(args.filters_nonparametric_file) parametric_filters = [filters_parametric_mat['f%d_parametric_registration' % (i+1)] for i in range(3)] nonparametric_filters = [filters_nonparametric_mat['f%d_nonparametric_registration' % (i+1)] for i in range(6)] results = broccoli.registerT1MNI(T1, T1_voxel_sizes, MNI, MNI_voxel_sizes, MNI_brain, MNI_brain_mask, parametric_filters, nonparametric_filters, [filters_nonparametric_mat['m%d' % (i+1)][0] for i in range(6)], [filters_nonparametric_mat['filter_directions_%s' % d][0] for d in ['x', 'y', 'z']], args.iterations_parametric, args.iterations_nonparametric, coarsest_scale,
def _run_interface(self, runtime): MNI, MNI_brain, MNI_brain_mask, MNI_voxel_sizes = broccoli.load_MNI_templates( self.inputs.MNI_file, self.inputs.MNI_brain_file, self.inputs.MNI_brain_mask_file) fMRI, fMRI_voxel_sizes = broccoli.load_EPI(self.inputs.fMRI_file, only_volume=False) T1, T1_voxel_sizes = broccoli.load_T1(self.inputs.T1_file) filters_parametric_mat = scipy.io.loadmat( self.inputs.filters_parametric) filters_nonparametric_mat = scipy.io.loadmat( self.inputs.filters_nonparametric) filters_parametric = [ filters_parametric_mat['f%d_parametric_registration' % (i + 1)] for i in range(3) ] filters_nonparametric = [ filters_nonparametric_mat['f%d_nonparametric_registration' % (i + 1)] for i in range(6) ] projection_tensor = [ filters_nonparametric_mat['m%d' % (i + 1)][0] for i in range(6) ] filter_directions = [ filters_nonparametric_mat['filter_directions_%s' % d][0] for d in ['x', 'y', 'z'] ] X_GLM = self.load_regressors(fMRI.shape[3]) xtx = np.linalg.inv(np.dot(X_GLM.T, X_GLM)) # print(xtx) xtxxt_GLM = xtx.dot(X_GLM.T) confounds = 1 if self.inputs.regress_confounds: confounds = np.loadtxt(self.inputs.confounds_file) contrasts = np.array([[1, 0], [1, 0], [1, 0], [1, 0]]) ctxtxc_GLM = [ contrasts[i:i + 1].dot(xtx).dot(contrasts[i:i + 1].T) for i in range(len(contrasts)) ] fMRI_voxel_sizes = [int(round(v)) for v in T1_voxel_sizes] T1_voxel_sizes = [int(round(v)) for v in T1_voxel_sizes] MNI_voxel_sizes = [int(round(v)) for v in T1_voxel_sizes] statistical_maps = broccoli.performFirstLevelAnalysis( fMRI, fMRI_voxel_sizes, T1, T1_voxel_sizes, MNI, MNI_brain, MNI_brain_mask, MNI_voxel_sizes, filters_parametric, filters_nonparametric, projection_tensor, filter_directions, self.inputs.iterations_parametric, self.inputs.iterations_nonparametric, self.inputs.iterations_motion_correction, 4, 4, 0, 0, self.inputs.regress_motion, self.inputs.EPI_smoothing, self.inputs.AR_smoothing, X_GLM, xtxxt_GLM.transpose(), contrasts, ctxtxc_GLM, self.inputs.use_temporal_derivatives, getattr(broccoli, self.inputs.beta_space), confounds, self.inputs.regress_confounds, self.inputs.opencl_platform, self.inputs.opencl_device, self.inputs.show_results, ) EPI_nni = nb.load(self.inputs.fMRI_file) aligned_EPI_nni = nb.Nifti1Image(statistical_maps, None, EPI_nni.get_header()) nb.save(aligned_EPI_nni, self._get_output_filename('statistical_map.nii')) return runtime