def test_instantiate_SpatialSVM(): from os.path import dirname, join, abspath from clinica.pipelines.machine_learning_spatial_svm.spatial_svm_pipeline import SpatialSVM root = dirname(abspath(join(abspath(__file__), pardir))) root = join(root, 'data', 'SpatialSVM') parameters = {'group_label': 'ADNIbl', 'orig_input_data': 't1-volume'} pipeline = SpatialSVM(caps_directory=join(root, 'in', 'caps'), tsv_file=join(root, 'in', 'subjects.tsv'), parameters=parameters) pipeline.build()
def run_command(self, args): """ """ from tempfile import mkdtemp from clinica.utils.stream import cprint from clinica.pipelines.machine_learning_spatial_svm.spatial_svm_pipeline import SpatialSVM pipeline = SpatialSVM( caps_directory=self.absolute_path(args.caps_directory), tsv_file=self.absolute_path(args.subjects_sessions_tsv)) pipeline.parameters = { 'group_id': args.group_id, 'fwhm': args.full_width_half_maximum, 'image_type': args.image_type, 'pet_type': args.pet_tracer, 'no_pvc': args.no_pvc } if args.working_directory is None: args.working_directory = mkdtemp() pipeline.base_dir = self.absolute_path(args.working_directory) if args.n_procs: pipeline.run(plugin='MultiProc', plugin_args={'n_procs': args.n_procs}) else: pipeline.run() cprint( "The " + self._name + " pipeline has completed. You can now delete the working directory (" + args.working_directory + ").")
def test_instantiate_SpatialSVM(cmdopt): from clinica.pipelines.machine_learning_spatial_svm.spatial_svm_pipeline import ( SpatialSVM, ) input_dir = Path(cmdopt["input"]) root = input_dir / "SpatialSVM" parameters = {"group_label": "ADNIbl", "orig_input_data": "t1-volume"} pipeline = SpatialSVM( caps_directory=fspath(root / "in" / "caps"), tsv_file=fspath(root / "in" / "subjects.tsv"), parameters=parameters, ) pipeline.build()
def test_instantiate_SpatialSVM(): from os.path import abspath, dirname, join from clinica.pipelines.machine_learning_spatial_svm.spatial_svm_pipeline import ( SpatialSVM, ) root = dirname(abspath(join(abspath(__file__), pardir))) root = join(root, "data", "SpatialSVM") parameters = {"group_label": "ADNIbl", "orig_input_data": "t1-volume"} pipeline = SpatialSVM( caps_directory=join(root, "in", "caps"), tsv_file=join(root, "in", "subjects.tsv"), parameters=parameters, ) pipeline.build()
def test_instantiate_SpatialSVM(): from clinica.pipelines.machine_learning_spatial_svm.spatial_svm_pipeline import SpatialSVM from os.path import dirname, join, abspath root = join(dirname(abspath(__file__)), 'data', 'SpatialSVM') pipeline = SpatialSVM(caps_directory=join(root, 'in', 'caps'), tsv_file=join(root, 'in', 'subjects.tsv')) pipeline.parameters['group_id'] = 'ADNIbl' pipeline.parameters['fwhm'] = 4 pipeline.parameters['image_type'] = 't1' pipeline.parameters['pet_type'] = 'fdg' pipeline.parameters['no_pvc'] = 'True' pipeline.build()
def test_run_SpatialSVM(cmdopt): from os.path import dirname, join, abspath import shutil import numpy as np import nibabel as nib from clinica.pipelines.machine_learning_spatial_svm.spatial_svm_pipeline import SpatialSVM working_dir = cmdopt root = dirname(abspath(join(abspath(__file__), pardir))) root = join(root, 'data', 'SpatialSVM') # Remove potential residual of previous UT clean_folder(join(root, 'out', 'caps'), recreate=False) clean_folder(join(working_dir, 'SpatialSVM'), recreate=False) # Copy necessary data from in to out shutil.copytree(join(root, 'in', 'caps'), join(root, 'out', 'caps')) parameters = {'group_label': 'ADNIbl', 'orig_input_data': 't1-volume'} # Instantiate pipeline and run() pipeline = SpatialSVM(caps_directory=join(root, 'out', 'caps'), tsv_file=join(root, 'in', 'subjects.tsv'), base_dir=join(working_dir, 'SpatialSVM'), parameters=parameters) pipeline.build() pipeline.run(plugin='MultiProc', plugin_args={'n_procs': 4}, bypass_check=True) # Check output vs ref subjects = ['sub-ADNI011S0023', 'sub-ADNI013S0325'] out_data_REG_NIFTI = [ nib.load( join( root, 'out', 'caps', 'subjects', sub, 'ses-M00', 'machine_learning', 'input_spatial_svm', 'group-ADNIbl', sub + '_ses-M00_T1w_segm-graymatter_space-Ixi549Space_modulated-on_spatialregularization.nii.gz' )).get_data() for sub in subjects ] ref_data_REG_NIFTI = [ nib.load( join( root, 'ref', sub + '_ses-M00_T1w_segm-graymatter_space-Ixi549Space_modulated-on_spatialregularization.nii.gz' )).get_data() for sub in subjects ] for i in range(len(out_data_REG_NIFTI)): assert np.allclose(out_data_REG_NIFTI[i], ref_data_REG_NIFTI[i], rtol=1e-3, equal_nan=True) # Remove data in out folder clean_folder(join(root, 'out', 'caps'), recreate=True) clean_folder(join(working_dir, 'SpatialSVM'), recreate=False)
def run_SpatialSVM(input_dir: Path, output_dir: Path, ref_dir: Path, working_dir: Path) -> None: import shutil from os import fspath import nibabel as nib import numpy as np from clinica.pipelines.machine_learning_spatial_svm.spatial_svm_pipeline import ( SpatialSVM, ) caps_dir = output_dir / "caps" tsv = input_dir / "subjects.tsv" # Copy necessary data from in to out shutil.copytree(input_dir / "caps", caps_dir, copy_function=shutil.copy) parameters = {"group_label": "ADNIbl", "orig_input_data": "t1-volume"} # Instantiate pipeline and run() pipeline = SpatialSVM( caps_directory=fspath(caps_dir), tsv_file=fspath(tsv), base_dir=fspath(working_dir), parameters=parameters, ) pipeline.build() pipeline.run(plugin="MultiProc", plugin_args={"n_procs": 4}, bypass_check=True) # Check output vs ref subjects = ["sub-ADNI011S0023", "sub-ADNI013S0325"] out_data_REG_NIFTI = [ nib.load( fspath( caps_dir / "subjects" / sub / "ses-M00" / "machine_learning" / "input_spatial_svm" / "group-ADNIbl" / (sub + "_ses-M00_T1w_segm-graymatter_space-Ixi549Space_modulated-on_spatialregularization.nii.gz" ))).get_fdata(dtype="float32") for sub in subjects ] ref_data_REG_NIFTI = [ nib.load( fspath(ref_dir / ( sub + "_ses-M00_T1w_segm-graymatter_space-Ixi549Space_modulated-on_spatialregularization.nii.gz" ))).get_fdata(dtype="float32") for sub in subjects ] for i in range(len(out_data_REG_NIFTI)): assert np.allclose(out_data_REG_NIFTI[i], ref_data_REG_NIFTI[i], rtol=1e-3, equal_nan=True)
def test_run_SpatialSVM(cmdopt): import shutil from os.path import abspath, dirname, join import nibabel as nib import numpy as np from clinica.pipelines.machine_learning_spatial_svm.spatial_svm_pipeline import ( SpatialSVM, ) working_dir = cmdopt root = dirname(abspath(join(abspath(__file__), pardir, pardir))) root = join(root, "data", "SpatialSVM") # Remove potential residual of previous UT clean_folder(join(root, "out", "caps"), recreate=False) clean_folder(join(working_dir, "SpatialSVM"), recreate=False) # Copy necessary data from in to out shutil.copytree(join(root, "in", "caps"), join(root, "out", "caps")) parameters = {"group_label": "ADNIbl", "orig_input_data": "t1-volume"} # Instantiate pipeline and run() pipeline = SpatialSVM( caps_directory=join(root, "out", "caps"), tsv_file=join(root, "in", "subjects.tsv"), base_dir=join(working_dir, "SpatialSVM"), parameters=parameters, ) pipeline.build() pipeline.run(plugin="MultiProc", plugin_args={"n_procs": 4}, bypass_check=True) # Check output vs ref subjects = ["sub-ADNI011S0023", "sub-ADNI013S0325"] out_data_REG_NIFTI = [ nib.load( join( root, "out", "caps", "subjects", sub, "ses-M00", "machine_learning", "input_spatial_svm", "group-ADNIbl", sub + "_ses-M00_T1w_segm-graymatter_space-Ixi549Space_modulated-on_spatialregularization.nii.gz", )).get_data() for sub in subjects ] ref_data_REG_NIFTI = [ nib.load( join( root, "ref", sub + "_ses-M00_T1w_segm-graymatter_space-Ixi549Space_modulated-on_spatialregularization.nii.gz", )).get_data() for sub in subjects ] for i in range(len(out_data_REG_NIFTI)): assert np.allclose(out_data_REG_NIFTI[i], ref_data_REG_NIFTI[i], rtol=1e-3, equal_nan=True) # Remove data in out folder clean_folder(join(root, "out", "caps"), recreate=True) clean_folder(join(working_dir, "SpatialSVM"), recreate=False)