Esempio n. 1
0
def test_fetch_atlas_schaefer_2018():
    valid_n_rois = [100, 200, 300, 400, 500, 600, 800, 1000]
    valid_yeo_networks = [7, 17]
    valid_resolution_mm = [1, 2]

    assert_raises(ValueError, atlas.fetch_atlas_schaefer_2018, n_rois=44)
    assert_raises(ValueError, atlas.fetch_atlas_schaefer_2018, yeo_networks=10)
    assert_raises(ValueError, atlas.fetch_atlas_schaefer_2018, resolution_mm=3)

    for n_rois, yeo_networks, resolution_mm in \
            itertools.product(valid_n_rois, valid_yeo_networks,
                              valid_resolution_mm):
        data = atlas.fetch_atlas_schaefer_2018(n_rois=n_rois,
                                               yeo_networks=yeo_networks,
                                               resolution_mm=resolution_mm,
                                               data_dir=tst.tmpdir,
                                               verbose=0)
        assert_not_equal(data.description, '')
        assert_true(isinstance(data.maps, _basestring))
        assert_true(isinstance(data.labels, np.ndarray))
        assert_equal(len(data.labels), n_rois)
        assert_true(data.labels[0].astype(str).startswith("{}Networks".
                                              format(yeo_networks)))
        img = nibabel.load(data.maps)
        assert_equal(img.header.get_zooms()[0], resolution_mm)
        assert_true(np.array_equal(np.unique(img.dataobj),
                                   np.arange(n_rois+1)))
Esempio n. 2
0
def test_fetch_atlas_schaefer_2018(tmp_path):
    valid_n_rois = list(range(100, 1100, 100))
    valid_yeo_networks = [7, 17]
    valid_resolution_mm = [1, 2]

    pytest.raises(ValueError, atlas.fetch_atlas_schaefer_2018, n_rois=44)
    pytest.raises(ValueError, atlas.fetch_atlas_schaefer_2018, yeo_networks=10)
    pytest.raises(ValueError, atlas.fetch_atlas_schaefer_2018, resolution_mm=3)

    for n_rois, yeo_networks, resolution_mm in \
            itertools.product(valid_n_rois, valid_yeo_networks,
                              valid_resolution_mm):
        data = atlas.fetch_atlas_schaefer_2018(n_rois=n_rois,
                                               yeo_networks=yeo_networks,
                                               resolution_mm=resolution_mm,
                                               data_dir=str(tmp_path),
                                               verbose=0)
        assert data.description != ''
        assert isinstance(data.maps, _basestring)
        assert isinstance(data.labels, np.ndarray)
        assert len(data.labels) == n_rois
        assert data.labels[0].astype(str).startswith(
            "{}Networks".format(yeo_networks))
        img = nibabel.load(data.maps)
        assert img.header.get_zooms()[0] == resolution_mm
        assert np.array_equal(np.unique(img.dataobj), np.arange(n_rois + 1))
Esempio n. 3
0
def test_fetch_atlas_schaefer_2018(tmp_path, request_mocker):
    labels_pattern = re.compile(
        r".*2018_(?P<n_rois>\d+)Parcels_(?P<network>\d+)Networks_order.txt")
    img_pattern = re.compile(r".*_(?P<n_rois>\d+)Parcels_(?P<network>\d+)"
                             r"Networks_order_FSLMNI152_(?P<res>\d)mm.nii.gz")
    request_mocker.url_mapping[labels_pattern] = _schaefer_labels
    request_mocker.url_mapping[img_pattern] = _schaefer_img
    valid_n_rois = list(range(100, 1100, 100))
    valid_yeo_networks = [7, 17]
    valid_resolution_mm = [1, 2]

    pytest.raises(ValueError, atlas.fetch_atlas_schaefer_2018, n_rois=44)
    pytest.raises(ValueError, atlas.fetch_atlas_schaefer_2018, yeo_networks=10)
    pytest.raises(ValueError, atlas.fetch_atlas_schaefer_2018, resolution_mm=3)

    for n_rois, yeo_networks, resolution_mm in \
            itertools.product(valid_n_rois, valid_yeo_networks,
                              valid_resolution_mm):
        data = atlas.fetch_atlas_schaefer_2018(n_rois=n_rois,
                                               yeo_networks=yeo_networks,
                                               resolution_mm=resolution_mm,
                                               data_dir=str(tmp_path),
                                               verbose=0)
        assert data.description != ''
        assert isinstance(data.maps, str)
        assert isinstance(data.labels, np.ndarray)
        assert len(data.labels) == n_rois
        assert data.labels[0].astype(str).startswith(
            "{}Networks".format(yeo_networks))
        img = nibabel.load(data.maps)
        assert img.header.get_zooms()[0] == resolution_mm
        assert np.array_equal(np.unique(img.dataobj), np.arange(n_rois + 1))
Esempio n. 4
0
def test_fetch_atlas_schaefer_2018():
    valid_n_rois = [100, 200, 300, 400, 500, 600, 800, 1000]
    valid_yeo_networks = [7, 17]
    valid_resolution_mm = [1, 2]

    assert_raises(ValueError, atlas.fetch_atlas_schaefer_2018, n_rois=44)
    assert_raises(ValueError, atlas.fetch_atlas_schaefer_2018, yeo_networks=10)
    assert_raises(ValueError, atlas.fetch_atlas_schaefer_2018, resolution_mm=3)

    for n_rois, yeo_networks, resolution_mm in \
            itertools.product(valid_n_rois, valid_yeo_networks,
                              valid_resolution_mm):
        data = atlas.fetch_atlas_schaefer_2018(n_rois=n_rois,
                                               yeo_networks=yeo_networks,
                                               resolution_mm=resolution_mm,
                                               data_dir=tst.tmpdir,
                                               verbose=0)
        assert_not_equal(data.description, '')
        assert_true(isinstance(data.maps, _basestring))
        assert_true(isinstance(data.labels, np.ndarray))
        assert_equal(len(data.labels), n_rois)
        assert_true(data.labels[0].astype(str).startswith(
            "{}Networks".format(yeo_networks)))
        img = nibabel.load(data.maps)
        assert_equal(img.header.get_zooms()[0], resolution_mm)
        assert_true(
            np.array_equal(np.unique(img.dataobj), np.arange(n_rois + 1)))