From bc6a0197f51ce2cc7a7a2e1254548063ee91cfd5 Mon Sep 17 00:00:00 2001 From: Kshitij Chawla Date: Mon, 14 Oct 2019 16:48:28 +0200 Subject: [PATCH 1/2] Fix Flake8 errors overlooked when merging PR #2028 (Plot connectome strength) (#2174) * Fix Flake8 errors overlooked when merging PR #2028 (Plot connectome strength) * Ignore linting for W508 * Corrected linter code --- examples/03_connectivity/plot_sphere_based_connectome.py | 2 +- nilearn/plotting/img_plotting.py | 4 ++-- nilearn/plotting/tests/test_img_plotting.py | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/03_connectivity/plot_sphere_based_connectome.py b/examples/03_connectivity/plot_sphere_based_connectome.py index 8740979424..b3ba1a3593 100644 --- a/examples/03_connectivity/plot_sphere_based_connectome.py +++ b/examples/03_connectivity/plot_sphere_based_connectome.py @@ -52,7 +52,7 @@ 'Posterior Cingulate Cortex', 'Left Temporoparietal junction', 'Right Temporoparietal junction', - 'Medial prefrontal cortex' + 'Medial prefrontal cortex', ] ########################################################################## diff --git a/nilearn/plotting/img_plotting.py b/nilearn/plotting/img_plotting.py index 1bde5f1f01..52d7867fd5 100644 --- a/nilearn/plotting/img_plotting.py +++ b/nilearn/plotting/img_plotting.py @@ -1374,7 +1374,7 @@ def plot_connectome_strength(adjacency_matrix, node_coords, node_size="auto", adjacency_matrix = np.nan_to_num(adjacency_matrix) adjacency_matrix_shape = adjacency_matrix.shape - if (len(adjacency_matrix_shape) != 2 or + if (len(adjacency_matrix_shape) != 2 or # noqa: W504 adjacency_matrix_shape[0] != adjacency_matrix_shape[1]): raise ValueError( "'adjacency_matrix' is supposed to have shape (n, n)." @@ -1426,7 +1426,7 @@ def plot_connectome_strength(adjacency_matrix, node_coords, node_size="auto", ) # reduce alpha for the least strong regions color[-1] = ( - (region - strength_sorted.min()) * + (region - strength_sorted.min()) * # noqa: W504 (1 / (strength_sorted.max() - strength_sorted.min())) ) # make color to be a 2D array diff --git a/nilearn/plotting/tests/test_img_plotting.py b/nilearn/plotting/tests/test_img_plotting.py index 9ecd0f2f9b..28d138bb8b 100644 --- a/nilearn/plotting/tests/test_img_plotting.py +++ b/nilearn/plotting/tests/test_img_plotting.py @@ -578,7 +578,7 @@ def test_connectome_strength(): *args, output_file=filename, **kwargs ) assert_true(display is None) - assert_true(os.path.isfile(filename) and + assert_true(os.path.isfile(filename) and # noqa: W504 os.path.getsize(filename) > 0) finally: os.remove(filename) @@ -659,7 +659,8 @@ def test_plot_connectome_strength_exceptions(): node_coords[:, 2], **kwargs) wrong_adjacency_matrix = np.zeros((3, 3)) - assert_raises_regex(ValueError, r'Shape mismatch.+\(3L?, 3L?\).+\(2L?, 3L?\)', + assert_raises_regex(ValueError, + r'Shape mismatch.+\(3L?, 3L?\).+\(2L?, 3L?\)', plot_connectome_strength, wrong_adjacency_matrix, node_coords, **kwargs) From 65d8274432971319aa161e014cc02a3d7e93ade6 Mon Sep 17 00:00:00 2001 From: Kshitij Chawla Date: Thu, 17 Oct 2019 13:22:39 +0200 Subject: [PATCH 2/2] Removed sub-example due to unfit for lasso dataset - unstable float values (#2177) * Removed sub-example due to unfit for lasso dataset - unstable float values * Removed remaining mention of Seitzman atlas from example * Updated Whats whats_new --- doc/whats_new.rst | 4 ++ .../plot_sphere_based_connectome.py | 58 +------------------ 2 files changed, 6 insertions(+), 56 deletions(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 9fb607813b..43b0eb5dc3 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -67,6 +67,10 @@ Changes - :func:`nilearn.plotting.view_connectome` now converts NaNs in the adjacency matrix to 0. +- Removed the plotting connectomes example which used the Seitzman atlas + from `examples/03_connectivity/plot_sphere_based_connectome.py`. + The atlas data is unsuitable for the method & the example is redundant. + Fixes ----- diff --git a/examples/03_connectivity/plot_sphere_based_connectome.py b/examples/03_connectivity/plot_sphere_based_connectome.py index b3ba1a3593..616089d768 100644 --- a/examples/03_connectivity/plot_sphere_based_connectome.py +++ b/examples/03_connectivity/plot_sphere_based_connectome.py @@ -4,8 +4,8 @@ This example shows how to extract signals from spherical regions. We show how to build spheres around user-defined coordinates, as well as -centered on coordinates from the Power-264 atlas [1], the Dosenbach-160 -atlas [2], and the Seitzman-300 atlas [3]. +centered on coordinates from the Power-264 atlas [1], and the Dosenbach-160 +atlas [2]. **References** @@ -15,11 +15,6 @@ [2] Dosenbach N.U., Nardos B., et al. "Prediction of individual brain maturity using fMRI.", 2010, Science 329, 1358-1361. -[3] `Seitzman, B. A., et al. "A set of functionally-defined brain regions with -improved representation of the subcortex and cerebellum.", 2018, bioRxiv, -450452 -`_ - We estimate connectomes using two different methods: **sparse inverse covariance** and **partial_correlation**, to recover the functional brain **networks structure**. @@ -332,55 +327,6 @@ plotting.show() - -############################################################################### -# Connectome extracted from Seitzman's atlas -# ----------------------------------------------------- -# We repeat the same steps for Seitzman's atlas. -seitzman = datasets.fetch_coords_seitzman_2018() - -coords = np.vstack(( - seitzman.rois['x'], - seitzman.rois['y'], - seitzman.rois['z'], -)).T - -############################################################################### -# Before calculating the connectivity matrix, let's look at the distribution -# of the regions of the default mode network. -dmn_rois = seitzman.networks == "DefaultMode" -dmn_coords = coords[dmn_rois] -zero_matrix = np.zeros((len(dmn_coords), len(dmn_coords))) -plotting.plot_connectome(zero_matrix, dmn_coords, - title='Seitzman default mode network', - node_color='darkred', node_size=20) - -############################################################################### -# Now let's calculate connectivity for the Seitzman atlas. -spheres_masker = input_data.NiftiSpheresMasker( - seeds=coords, smoothing_fwhm=6, radius=4, - detrend=True, standardize=True, low_pass=0.1, high_pass=0.01, t_r=2, - allow_overlap=True) - -timeseries = spheres_masker.fit_transform(func_filename, - confounds=confounds_filename) - -covariance_estimator = GraphicalLassoCV() -covariance_estimator.fit(timeseries) -matrix = covariance_estimator.covariance_ - -plotting.plot_matrix(matrix, vmin=-1., vmax=1., colorbar=True, - title='Seitzman correlation matrix') - -plotting.plot_connectome(matrix, coords, title='Seitzman correlation graph', - edge_threshold="99.7%", node_size=20, colorbar=True) - - -############################################################################### -# We can easily identify the networks from the matrix blocks. -print('Seitzman networks names are {0}'.format(np.unique(seitzman.networks))) -plotting.show() - ############################################################################### # .. seealso:: #