Esempio 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 + ").")
Esempio n. 2
0
def test_run_PETSurfaceCrossSectional(cmdopt):
    from os.path import dirname, join, abspath
    import shutil
    import nibabel as nib
    import numpy as np
    from clinica.pipelines.pet_surface.pet_surface_pipeline import PetSurface

    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'))

    parameters = {
        'acq_label': 'FDG',
        'suvr_reference_region': 'pons',
        'pvc_psf_tsv': join(root, 'in', 'subjects.tsv'),
        'longitudinal': False
    }
    pipeline = PetSurface(bids_directory=join(root, 'in', 'bids'),
                          caps_directory=join(root, 'out', 'caps'),
                          tsv_file=join(root, 'in', 'subjects.tsv'),
                          base_dir=join(working_dir, 'PETSurface'),
                          parameters=parameters)
    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)
    clean_folder(join(working_dir, 'PETSurface'), recreate=False)
Esempio n. 3
0
def test_run_PETSurfaceCrossSectional(cmdopt):
    import shutil
    from os.path import abspath, dirname, join

    import nibabel as nib
    import numpy as np

    from clinica.pipelines.pet_surface.pet_surface_pipeline import PetSurface

    working_dir = cmdopt
    root = dirname(abspath(join(abspath(__file__), pardir, 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"))

    parameters = {
        "acq_label": "FDG",
        "suvr_reference_region": "pons",
        "pvc_psf_tsv": join(root, "in", "subjects.tsv"),
        "longitudinal": False,
    }
    pipeline = PetSurface(
        bids_directory=join(root, "in", "bids"),
        caps_directory=join(root, "out", "caps"),
        tsv_file=join(root, "in", "subjects.tsv"),
        base_dir=join(working_dir, "PETSurface"),
        parameters=parameters,
    )
    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)
    clean_folder(join(working_dir, "PETSurface"), recreate=False)
def run_PETSurfaceCrossSectional(
    input_dir: Path, output_dir: Path, ref_dir: Path, working_dir: Path
) -> None:
    import shutil

    import nibabel as nib
    import numpy as np

    from clinica.pipelines.pet_surface.pet_surface_pipeline import PetSurface

    shutil.copytree(input_dir / "caps", output_dir / "caps", copy_function=shutil.copy)

    parameters = {
        "acq_label": "FDG",
        "suvr_reference_region": "pons",
        "pvc_psf_tsv": fspath(input_dir / "subjects.tsv"),
        "longitudinal": False,
        "skip_question": False,
    }
    pipeline = PetSurface(
        bids_directory=fspath(input_dir / "bids"),
        caps_directory=fspath(output_dir / "caps"),
        tsv_file=fspath(input_dir / "subjects.tsv"),
        base_dir=fspath(working_dir),
        parameters=parameters,
    )
    pipeline.build()
    pipeline.run(bypass_check=True)

    # Check files
    out_files = [
        (
            output_dir
            / "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 = [
        (
            ref_dir
            / (
                "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(fspath(out_files[i])).get_fdata(dtype="float32")),
            np.squeeze(nib.load(fspath(ref_files[i])).get_fdata(dtype="float32")),
            rtol=3e-2,
            equal_nan=True,
        )