示例#1
0
def test_fail_fetch_atlas_harvard_oxford():
    # specify non-existing atlas item
    assert_raises_regex(ValueError, 'Invalid atlas name',
                        atlas.fetch_atlas_harvard_oxford,
                        'not_inside')

    # specify existing atlas item
    target_atlas = 'cort-maxprob-thr0-1mm'
    target_atlas_fname = 'HarvardOxford-' + target_atlas + '.nii.gz'

    ho_dir = os.path.join(tst.tmpdir, 'fsl', 'data', 'atlases')
    os.makedirs(ho_dir)
    nifti_dir = os.path.join(ho_dir, 'HarvardOxford')
    os.makedirs(nifti_dir)

    target_atlas_nii = os.path.join(nifti_dir, target_atlas_fname)
    struct.load_mni152_template().to_filename(target_atlas_nii)

    dummy = open(os.path.join(ho_dir, 'HarvardOxford-Cortical.xml'), 'w')
    dummy.write("<?xml version='1.0' encoding='us-ascii'?> "
                "<metadata>"
                "</metadata>")
    dummy.close()

    ho = atlas.fetch_atlas_harvard_oxford(target_atlas,
                                          data_dir=tst.tmpdir)

    assert_true(isinstance(nibabel.load(ho.maps), nibabel.Nifti1Image))
    assert_true(isinstance(ho.labels, np.ndarray))
    assert_true(len(ho.labels) > 0)
示例#2
0
def test_fail_fetch_atlas_harvard_oxford():
    # specify non-existing atlas item
    assert_raises_regex(ValueError, 'Invalid atlas name',
                        atlas.fetch_atlas_harvard_oxford, 'not_inside')

    # specify existing atlas item
    target_atlas = 'cort-maxprob-thr0-1mm'
    target_atlas_fname = 'HarvardOxford-' + target_atlas + '.nii.gz'

    ho_dir = os.path.join(tmpdir, 'fsl', 'data', 'atlases')
    os.makedirs(ho_dir)
    nifti_dir = os.path.join(ho_dir, 'HarvardOxford')
    os.makedirs(nifti_dir)

    target_atlas_nii = os.path.join(nifti_dir, target_atlas_fname)
    struct.load_mni152_template().to_filename(target_atlas_nii)

    dummy = open(os.path.join(ho_dir, 'HarvardOxford-Cortical.xml'), 'w')
    dummy.write("<?xml version='1.0' encoding='us-ascii'?> "
                "<metadata>"
                "</metadata>")
    dummy.close()

    ho = atlas.fetch_atlas_harvard_oxford(target_atlas, data_dir=tmpdir)

    assert_true(isinstance(nibabel.load(ho.maps), nibabel.Nifti1Image))
    assert_true(isinstance(ho.labels, np.ndarray))
    assert_true(len(ho.labels) > 0)
示例#3
0
def test_fail_fetch_atlas_harvard_oxford():
    # specify non-existing atlas item
    assert_raises_regex(ValueError, "Invalid atlas name", atlas.fetch_atlas_harvard_oxford, "not_inside")

    # specify existing atlas item
    target_atlas = "cort-maxprob-thr0-1mm"
    target_atlas_fname = "HarvardOxford-" + target_atlas + ".nii.gz"

    ho_dir = os.path.join(tmpdir, "fsl", "data", "atlases")
    os.makedirs(ho_dir)
    nifti_dir = os.path.join(ho_dir, "HarvardOxford")
    os.makedirs(nifti_dir)

    target_atlas_nii = os.path.join(nifti_dir, target_atlas_fname)
    struct.load_mni152_template().to_filename(target_atlas_nii)

    dummy = open(os.path.join(ho_dir, "HarvardOxford-Cortical.xml"), "w")
    dummy.write("<?xml version='1.0' encoding='us-ascii'?> " "<metadata>" "</metadata>")
    dummy.close()

    ho = atlas.fetch_atlas_harvard_oxford(target_atlas, data_dir=tmpdir)

    assert_true(isinstance(nibabel.load(ho.maps), nibabel.Nifti1Image))
    assert_true(isinstance(ho.labels, np.ndarray))
    assert_true(len(ho.labels) > 0)
示例#4
0
def test_load_mni152_template():
    # All subjects
    template_nii_1mm = struct.load_mni152_template(resolution=1)
    template_nii_2mm = struct.load_mni152_template()
    assert template_nii_1mm.shape == (197, 233, 189)
    assert template_nii_2mm.shape == (99, 117, 95)
    assert template_nii_1mm.header.get_zooms() == (1.0, 1.0, 1.0)
    assert template_nii_2mm.header.get_zooms() == (2.0, 2.0, 2.0)
示例#5
0
def test_load_mni152_template():
    # All subjects
    template_nii = struct.load_mni152_template()
    assert_equal(template_nii.shape, (91, 109, 91))
    assert_equal(template_nii.get_header().get_zooms(), (2.0, 2.0, 2.0))
示例#6
0
def test_fetch_icbm152_brain_gm_mask():
    dataset = struct.fetch_icbm152_2009(data_dir=tst.tmpdir, verbose=0)
    struct.load_mni152_template().to_filename(dataset.gm)
    grey_matter_img = struct.fetch_icbm152_brain_gm_mask(data_dir=tst.tmpdir,
                                                         verbose=0)
    assert_true(isinstance(grey_matter_img, nibabel.Nifti1Image))
示例#7
0
def test_load_mni152_template():
    # All subjects
    template_nii = struct.load_mni152_template()
    assert_equal(template_nii.shape, (91, 109, 91))
    assert_equal(template_nii.header.get_zooms(), (2.0, 2.0, 2.0))
示例#8
0
def test_fetch_icbm152_brain_gm_mask(tmp_path, request_mocker):
    dataset = struct.fetch_icbm152_2009(data_dir=str(tmp_path), verbose=0)
    struct.load_mni152_template().to_filename(dataset.gm)
    grey_matter_img = struct.fetch_icbm152_brain_gm_mask(
        data_dir=str(tmp_path), verbose=0)
    assert isinstance(grey_matter_img, nibabel.Nifti1Image)
示例#9
0
def test_load_mni152_template():
    # All subjects
    template_nii = struct.load_mni152_template()
    assert template_nii.shape == (91, 109, 91)
    assert template_nii.header.get_zooms() == (2.0, 2.0, 2.0)
示例#10
0
def test_fetch_icbm152_brain_gm_mask():
    dataset = struct.fetch_icbm152_2009(data_dir=tst.tmpdir, verbose=0)
    struct.load_mni152_template().to_filename(dataset.gm)
    grey_matter_img = struct.fetch_icbm152_brain_gm_mask(data_dir=tst.tmpdir,
                                                         verbose=0)
    assert_true(isinstance(grey_matter_img, nibabel.Nifti1Image))