Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nilearn/nilearn into spri…
Browse files Browse the repository at this point in the history
…nt_modify_fetch_dev

* 'master' of https://github.com/nilearn/nilearn:
  Removed sub-example due to unfit for lasso dataset - unstable float values (nilearn#2177)
  Fix Flake8 errors overlooked when merging PR nilearn#2028 (Plot connectome strength) (nilearn#2174)
  • Loading branch information
kchawla-pi committed Oct 17, 2019
2 parents 7470f67 + 65d8274 commit c89239c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 61 deletions.
4 changes: 4 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----

Expand Down
60 changes: 3 additions & 57 deletions examples/03_connectivity/plot_sphere_based_connectome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand All @@ -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
<http://doi.org/10.1101/450452>`_
We estimate connectomes using two different methods: **sparse inverse
covariance** and **partial_correlation**, to recover the functional brain
**networks structure**.
Expand Down Expand Up @@ -52,7 +47,7 @@
'Posterior Cingulate Cortex',
'Left Temporoparietal junction',
'Right Temporoparietal junction',
'Medial prefrontal cortex'
'Medial prefrontal cortex',
]

##########################################################################
Expand Down Expand Up @@ -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::
#
Expand Down
4 changes: 2 additions & 2 deletions nilearn/plotting/img_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions nilearn/plotting/tests/test_img_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c89239c

Please sign in to comment.