예제 #1
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)
def test_instantiate_PETSurface():
    from os.path import dirname, join, abspath
    from clinica.pipelines.pet_surface.pet_surface_pipeline import PetSurface

    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, 'data', 'PETSurface')
    pipeline = PetSurface(
        bids_directory=join(root, 'in', 'bids'),
        caps_directory=join(root, 'in', 'caps'),
        tsv_file=join(root, 'in', 'subjects.tsv'),
    )
    pipeline.build()
def test_instantiate_PETSurface(tmpdir):
    from clinica.pipelines.pet_surface.pet_surface_pipeline import PetSurface
    from os.path import dirname, join, abspath

    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, 'data', 'PETSurface')
    pipeline = PetSurface(bids_directory=join(root, 'in', 'bids'),
                          caps_directory=join(root, 'in', 'caps'),
                          tsv_file=join(root, 'in', 'subjects.tsv'))
    pipeline.parameters['pet_type'] = 'fdg'
    pipeline.parameters['wd'] = str(tmpdir)
    pipeline.build()
def test_instantiate_PETSurfaceCrossSectional():
    from os.path import dirname, join, abspath
    from clinica.pipelines.pet_surface.pet_surface_pipeline import PetSurface

    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, 'data', 'PETSurface')
    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, 'in', 'caps'),
        tsv_file=join(root, 'in', 'subjects.tsv'),
        parameters=parameters,
    )
    pipeline.build()
예제 #5
0
def test_instantiate_PETSurfaceCrossSectional():
    from os.path import abspath, dirname, join

    from clinica.pipelines.pet_surface.pet_surface_pipeline import PetSurface

    root = dirname(abspath(join(abspath(__file__), pardir)))
    root = join(root, "data", "PETSurface")
    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, "in", "caps"),
        tsv_file=join(root, "in", "subjects.tsv"),
        parameters=parameters,
    )
    pipeline.build()
예제 #6
0
def test_instantiate_PETSurfaceCrossSectional(cmdopt):
    from os.path import abspath, dirname, join

    from clinica.pipelines.pet_surface.pet_surface_pipeline import PetSurface

    input_dir = Path(cmdopt["input"])
    root = input_dir / "PETSurface"

    parameters = {
        "acq_label": "FDG",
        "suvr_reference_region": "pons",
        "pvc_psf_tsv": fspath(root / "in" / "subjects.tsv"),
        "longitudinal": False,
        "skip_question": True,
    }
    pipeline = PetSurface(
        bids_directory=fspath(root / "in" / "bids"),
        caps_directory=fspath(root / "in" / "caps"),
        tsv_file=fspath(root / "in" / "subjects.tsv"),
        parameters=parameters,
    )
    pipeline.build()
예제 #7
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)
예제 #8
0
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,
        )