Ejemplo n.º 1
0
    def run_command(self, args):
        from tempfile import mkdtemp
        from clinica.utils.stream import cprint
        from clinica.pipelines.pet_surface.pet_surface_pipeline import PetSurface

        if args.working_directory is None:
            args.working_directory = mkdtemp()

        pipeline = PetSurface(
            bids_directory=self.absolute_path(args.bids_directory),
            caps_directory=self.absolute_path(args.caps_directory),
            tsv_file=self.absolute_path(args.subjects_sessions_tsv))
        pipeline.parameters = {
            'pet_type': args.pet_tracer,
            'wd': self.absolute_path(args.working_directory),
            'n_procs': args.n_procs
        }
        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 + ").")
Ejemplo n.º 2
0
def test_run_PETSurface(cmdopt):
    from clinica.pipelines.pet_surface.pet_surface_pipeline import PetSurface
    from os.path import dirname, join, abspath
    import shutil
    import nibabel as nib
    import numpy as np

    working_dir = cmdopt
    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, 'data', 'PETSurface')

    clean_folder(join(root, 'out', 'caps'), recreate=False)
    clean_folder(join(working_dir, 'PETSurface'))
    shutil.copytree(join(root, 'in', 'caps'), join(root, 'out', 'caps'))

    pipeline = PetSurface(bids_directory=join(root, 'in', 'bids'),
                          caps_directory=join(root, 'out', 'caps'),
                          tsv_file=join(root, 'in', 'subjects.tsv'))
    pipeline.parameters['pet_type'] = 'fdg'
    wd = join(working_dir, 'PETSurface')
    pipeline.base_dir = wd
    pipeline.parameters['wd'] = wd
    pipeline.build()
    pipeline.run(bypass_check=True)

    # Check files
    out_files = [
        join(
            root, 'out/caps/subjects/sub-ADNI011S4105/ses-M00/pet/surface',
            'sub-ADNI011S4105_ses-M00_task-rest_acq-fdg_pet_space-fsaverage_suvr-pons_pvc-iy_hemi-'
            + h + '_fwhm-' + str(f) + '_projection.mgh') for h in ['lh', 'rh']
        for f in [0, 5, 10, 15, 20, 25]
    ]
    ref_files = [
        join(
            root,
            'ref/sub-ADNI011S4105_ses-M00_task-rest_acq-fdg_pet_space-fsaverage_suvr-pons_pvc-iy_hemi-'
            + h + '_fwhm-' + str(f) + '_projection.mgh') for h in ['lh', 'rh']
        for f in [0, 5, 10, 15, 20, 25]
    ]

    for i in range(len(out_files)):
        assert np.allclose(np.squeeze(nib.load(out_files[i]).get_data()),
                           np.squeeze(nib.load(ref_files[i]).get_data()),
                           rtol=3e-2,
                           equal_nan=True)
    clean_folder(join(root, 'out', 'caps'), recreate=False)