def test_fetch_atlas_destrieux_2009_atlas(): datadir = os.path.join(tmpdir, 'destrieux_2009') os.mkdir(datadir) dummy = open( os.path.join(datadir, 'destrieux2009_rois_labels_lateralized.csv'), 'w') dummy.write("name,index") dummy.close() bunch = atlas.fetch_atlas_destrieux_2009(data_dir=tmpdir, verbose=0) assert_equal(len(mock_url_request.urls), 1) assert_equal( bunch['maps'], os.path.join(tmpdir, 'destrieux_2009', 'destrieux2009_rois_lateralized.nii.gz')) dummy = open(os.path.join(datadir, 'destrieux2009_rois_labels.csv'), 'w') dummy.write("name,index") dummy.close() bunch = atlas.fetch_atlas_destrieux_2009(lateralized=False, data_dir=tmpdir, verbose=0) assert_equal(len(mock_url_request.urls), 1) assert_equal( bunch['maps'], os.path.join(tmpdir, 'destrieux_2009', 'destrieux2009_rois.nii.gz'))
def test_fetch_atlas_destrieux_2009_warning_clean_labels(request_mocker): """Tests that ``fetch_atlas_destrieux_2009`` gives a FutureWarning when ``clean_labels`` isn't specified explicitly. """ request_mocker.url_mapping["*destrieux2009.tgz"] = _destrieux_data() with pytest.warns(FutureWarning, match=("Default value for parameter `clean_labels` " "will change from ``False`` to ``True`` " "in Nilearn 0.10.")): atlas.fetch_atlas_destrieux_2009() assert request_mocker.url_count == 1
def test_fetch_atlas_destrieux_2009(tmp_path, request_mocker): request_mocker.url_mapping["*destrieux2009.tgz"] = _destrieux_data() bunch = atlas.fetch_atlas_destrieux_2009(data_dir=str(tmp_path), verbose=0) assert request_mocker.url_count == 1 assert bunch['maps'] == str(tmp_path / 'destrieux_2009' / 'destrieux2009_rois_lateralized.nii.gz') bunch = atlas.fetch_atlas_destrieux_2009(lateralized=False, data_dir=str(tmp_path), verbose=0) assert request_mocker.url_count == 1 assert bunch['maps'] == str(tmp_path / 'destrieux_2009' / 'destrieux2009_rois.nii.gz')
def test_fetch_atlas_destrieux_2009_atlas(): datadir = os.path.join(tmpdir, "destrieux_2009") os.mkdir(datadir) dummy = open(os.path.join(datadir, "destrieux2009_rois_labels_lateralized.csv"), "w") dummy.write("name,index") dummy.close() bunch = atlas.fetch_atlas_destrieux_2009(data_dir=tmpdir, verbose=0) assert_equal(len(mock_url_request.urls), 1) assert_equal(bunch["maps"], os.path.join(tmpdir, "destrieux_2009", "destrieux2009_rois_lateralized.nii.gz")) dummy = open(os.path.join(datadir, "destrieux2009_rois_labels.csv"), "w") dummy.write("name,index") dummy.close() bunch = atlas.fetch_atlas_destrieux_2009(lateralized=False, data_dir=tmpdir, verbose=0) assert_equal(len(mock_url_request.urls), 1) assert_equal(bunch["maps"], os.path.join(tmpdir, "destrieux_2009", "destrieux2009_rois.nii.gz"))
def test_fetch_atlas_destrieux_2009(tmp_path, request_mocker): datadir = str(tmp_path / 'destrieux_2009') os.mkdir(datadir) dummy = open( os.path.join(datadir, 'destrieux2009_rois_labels_lateralized.csv'), 'w') dummy.write("name,index") dummy.close() bunch = atlas.fetch_atlas_destrieux_2009(data_dir=str(tmp_path), verbose=0) assert len(tst.mock_url_request.urls) == 1 assert bunch['maps'] == str(tmp_path / 'destrieux_2009' / 'destrieux2009_rois_lateralized.nii.gz') dummy = open(os.path.join(datadir, 'destrieux2009_rois_labels.csv'), 'w') dummy.write("name,index") dummy.close() bunch = atlas.fetch_atlas_destrieux_2009(lateralized=False, data_dir=str(tmp_path), verbose=0) assert len(tst.mock_url_request.urls) == 1 assert bunch['maps'] == os.path.join(datadir, 'destrieux2009_rois.nii.gz')
def test_fetch_atlas_destrieux_2009(): datadir = os.path.join(tst.tmpdir, 'destrieux_2009') os.mkdir(datadir) dummy = open(os.path.join( datadir, 'destrieux2009_rois_labels_lateralized.csv'), 'w') dummy.write("name,index") dummy.close() bunch = atlas.fetch_atlas_destrieux_2009(data_dir=tst.tmpdir, verbose=0) assert_equal(len(tst.mock_url_request.urls), 1) assert_equal(bunch['maps'], os.path.join( tst.tmpdir, 'destrieux_2009', 'destrieux2009_rois_lateralized.nii.gz')) dummy = open(os.path.join( datadir, 'destrieux2009_rois_labels.csv'), 'w') dummy.write("name,index") dummy.close() bunch = atlas.fetch_atlas_destrieux_2009( lateralized=False, data_dir=tst.tmpdir, verbose=0) assert_equal(len(tst.mock_url_request.urls), 1) assert_equal(bunch['maps'], os.path.join( tst.tmpdir, 'destrieux_2009', 'destrieux2009_rois.nii.gz'))
def test_fetch_atlas_destrieux_2009(tmp_path, request_mocker, lateralized): """Tests for function `fetch_atlas_destrieux_2009`. The atlas is fetched with different values for `lateralized`. """ request_mocker.url_mapping["*destrieux2009.tgz"] = _destrieux_data() bunch = atlas.fetch_atlas_destrieux_2009( lateralized=lateralized, data_dir=tmp_path, verbose=0 ) assert request_mocker.url_count == 1 name = '_lateralized' if lateralized else "" assert bunch['maps'] == str( tmp_path / 'destrieux_2009' / f'destrieux2009_rois{name}.nii.gz' ) labels_img = set(np.unique(get_data(bunch.maps))) labels = set([label.index for label in bunch.labels]) assert labels_img.issubset(labels)
def test_fetch_atlas_destrieux_2009(tmp_path, request_mocker, n_labels, lateralized, clean_labels): """Tests for function `fetch_atlas_destrieux_2009`. The atlas is fetched with different combinations of `lateralized` and `n_labels`. In the case `n_labels=11`, the fetcher should be able to remove the extra label ('10') not present in the atlas image. """ request_mocker.url_mapping["*destrieux2009.tgz"] = _destrieux_data( n_labels=n_labels) bunch = atlas.fetch_atlas_destrieux_2009(lateralized=lateralized, data_dir=tmp_path, verbose=0, clean_labels=clean_labels) assert request_mocker.url_count == 1 name = '_lateralized' if lateralized else "" assert bunch['maps'] == str(tmp_path / 'destrieux_2009' / f'destrieux2009_rois{name}.nii.gz') labels_img = set(np.unique(get_data(bunch.maps))) labels = set([label.index for label in bunch.labels]) if clean_labels: assert labels_img == labels else: assert labels_img.issubset(labels)