Skip to content

Commit

Permalink
Make install
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Dec 23, 2024
1 parent b84de1a commit 9dafe0d
Show file tree
Hide file tree
Showing 950 changed files with 30,138 additions and 25,113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
This example shows how to download and fetch brain parcellations of
multiple networks using
:func:`nilearn.datasets.fetch_atlas_basc_multiscale_2015`
and visualize them using plotting function :func:`nilearn.plotting.plot_roi`.
:func:`~nilearn.datasets.fetch_atlas_basc_multiscale_2015`
and visualize them using plotting function :func:`~nilearn.plotting.plot_roi`.
We show here only three different networks of 'symmetric' version. For more
details about different versions and different networks, please refer to its
Expand All @@ -17,12 +17,12 @@
# -----------------------------------------------

# import datasets module and use `fetch_atlas_basc_multiscale_2015` function
from nilearn import datasets
from nilearn.datasets import fetch_atlas_basc_multiscale_2015

parcellations = [
datasets.fetch_atlas_basc_multiscale_2015(version="sym", resolution=64),
datasets.fetch_atlas_basc_multiscale_2015(version="sym", resolution=197),
datasets.fetch_atlas_basc_multiscale_2015(version="sym", resolution=444),
fetch_atlas_basc_multiscale_2015(version="sym", resolution=64),
fetch_atlas_basc_multiscale_2015(version="sym", resolution=197),
fetch_atlas_basc_multiscale_2015(version="sym", resolution=444),
]

# We show here networks of 64, 197, 444
Expand All @@ -35,20 +35,14 @@
# -------------------------------

# import plotting module and use `plot_roi` function, since the maps are in 3D
from nilearn import plotting
from nilearn.plotting import cm, plot_roi, show

# The coordinates of all plots are selected automatically by itself
# We manually change the colormap of our choice
plotting.plot_roi(
networks_64, cmap=plotting.cm.bwr, title="64 regions of brain clusters"
)
plot_roi(networks_64, cmap=cm.bwr, title="64 regions of brain clusters")

plotting.plot_roi(
networks_197, cmap=plotting.cm.bwr, title="197 regions of brain clusters"
)
plot_roi(networks_197, cmap=cm.bwr, title="197 regions of brain clusters")

plotting.plot_roi(
networks_444, cmap=plotting.cm.bwr_r, title="444 regions of brain clusters"
)
plot_roi(networks_444, cmap=cm.bwr_r, title="444 regions of brain clusters")

plotting.show()
show()
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,9 @@ def plot_slices(data, title=None):
# We can now run different estimators and look at their prediction score,
# as well as the feature maps that they recover. Namely, we will use
#
# * A support vector regression (`SVM
# <https://scikit-learn.org/stable/modules/svm.html>`_)
# * A :sklearn:`support vector regression </modules/svm.html>`
#
# * An `elastic-net
# <https://scikit-learn.org/stable/modules/linear_model.html#elastic-net>`_
# * An :sklearn:`elastic-net <modules/linear_model.html#elastic-net>`
#
# * A *Bayesian* ridge estimator, i.e. a ridge estimator that sets its
# parameter according to a metaprior
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
},
"outputs": [],
"source": [
"from sklearn.feature_selection import f_regression\n\n# f_regression implicitly adds intercept\n_, pvals_bonferroni = f_regression(\n grouped_fmri_masked, grouped_conditions_encoded\n)\npvals_bonferroni *= fmri_masked.shape[1]\npvals_bonferroni[np.isnan(pvals_bonferroni)] = 1\npvals_bonferroni[pvals_bonferroni > 1] = 1\nneg_log_pvals_bonferroni = -np.log10(pvals_bonferroni)\nneg_log_pvals_bonferroni_unmasked = nifti_masker.inverse_transform(\n neg_log_pvals_bonferroni\n)"
"from sklearn.feature_selection import f_regression\n\n# f_regression implicitly adds intercept\n_, pvals_bonferroni = f_regression(\n grouped_fmri_masked,\n grouped_conditions_encoded.ravel(),\n)\npvals_bonferroni *= fmri_masked.shape[1]\npvals_bonferroni[np.isnan(pvals_bonferroni)] = 1\npvals_bonferroni[pvals_bonferroni > 1] = 1\nneg_log_pvals_bonferroni = -np.log10(pvals_bonferroni)\nneg_log_pvals_bonferroni_unmasked = nifti_masker.inverse_transform(\n neg_log_pvals_bonferroni\n)"
]
},
{
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
# given in the documentation section: :ref:`loading_data`.
#
# Functions accept either 3D or 4D images, and we need to use on the one
# hand :func:`nilearn.image.index_img` or :func:`nilearn.image.iter_img`
# hand :func:`~nilearn.image.index_img` or :func:`~nilearn.image.iter_img`
# to break down 4D images into 3D images, and on the other hand
# :func:`nilearn.image.concat_imgs` to group a list of 3D images into a 4D
# :func:`~nilearn.image.concat_imgs` to group a list of 3D images into a 4D
# image.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Technical point: Illustration of the volume to surface sampling schemes
=======================================================================
In nilearn, :func:`nilearn.surface.vol_to_surf` allows us to measure values of
In nilearn, :func:`~nilearn.surface.vol_to_surf` allows us to measure values of
a 3d volume at the nodes of a cortical mesh, transforming it into surface data.
This data can then be plotted with :func:`nilearn.plotting.plot_surf_stat_map`
This data can then be plotted with :func:`~nilearn.plotting.plot_surf_stat_map`
for example.
This script shows, on a toy example, where samples are drawn around each mesh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This example uses voxel-based morphometry (:term:`VBM`) to study the
relationship between aging, sex, and gray matter density.
The data come from the `OASIS <https://www.oasis-brains.org/>`_ project.
The data come from the `OASIS <https://sites.wustl.edu/oasisbrains/>`_ project.
If you use it, you need to agree with the data usage agreement available
on the website.
Expand Down Expand Up @@ -79,7 +79,7 @@
)

# %%
# Analyse data
# Analyze data
# ------------
# First, we create an adequate design matrix with three columns: 'age', 'sex',
# and 'intercept'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Visualizing Megatrawls Network Matrices from Human Connectome Project\n\nThis example shows how to fetch network matrices data from HCP beta-release\nof the Functional Connectivity Megatrawl project.\n\nSee :func:`nilearn.datasets.fetch_megatrawls_netmats`\ndocumentation for more details.\n"
"\n# Visualizing Megatrawls Network Matrices from Human Connectome Project\n\nThis example shows how to fetch network matrices data from HCP beta-release\nof the Functional Connectivity Megatrawl project.\n\nSee :func:`~nilearn.datasets.fetch_megatrawls_netmats`\ndocumentation for more details.\n"
]
},
{
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Understanding :class:`nilearn.decoding.Decoder`
"""Understanding :class:`~nilearn.decoding.Decoder`
==================================================
Nilearn's :class:`nilearn.decoding.Decoder` object is a composite estimator
Nilearn's :class:`~nilearn.decoding.Decoder` object is a composite estimator
that does several things under the hood and can hence be a bit difficult to
understand at first.
This example aims to provide a clear understanding of the
:class:`nilearn.decoding.Decoder` object by demonstrating these steps via a
:class:`~nilearn.decoding.Decoder` object by demonstrating these steps via a
Scikit-Learn pipeline.
We will use the :footcite:t:`Haxby2001` dataset where the participants were
Expand Down Expand Up @@ -65,23 +65,24 @@
# of brain volumes acquired while visual stimuli were presented, each
# corresponding to one of the 8 labels we selected above.
#
# :class:`nilearn.decoding.Decoder` can convert this 4D image to a 2D numpy
# :class:`~nilearn.decoding.Decoder` can convert this 4D image to a 2D numpy
# array where each row corresponds to a trial and each column corresponds to a
# voxel. In addition, it can also do several other things like masking,
# smoothing, standardizing the data etc. depending on your requirements.
#
# Under the hood, :class:`nilearn.decoding.Decoder` uses
# :class:`nilearn.maskers.NiftiMasker` to do all these operations. So here we
# Under the hood, :class:`~nilearn.decoding.Decoder` uses
# :class:`~nilearn.maskers.NiftiMasker` to do all these operations. So here we
# will demonstrate this by directly using the
# :class:`nilearn.maskers.NiftiMasker`. Specifically, we will use it to:
# :class:`~nilearn.maskers.NiftiMasker`. Specifically, we will use it to:
#
# 1. only keep the data from the Ventral Temporal cortex by providing the
# mask image (in :class:`nilearn.decoding.Decoder` this is done by
# mask image (in :class:`~nilearn.decoding.Decoder` this is done by
# providing the mask image in the ``mask`` parameter).
#
# 2. standardize the data by z-scoring it such that the data is scaled to
# have zero mean and unit variance across trials (in
# :class:`nilearn.decoding.Decoder` this is done by setting the ``standardize``
# :class:`~nilearn.decoding.Decoder`
# this is done by setting the ``standardize``
# parameter to ``"zscore_sample"``).

from nilearn.maskers import NiftiMasker
Expand All @@ -92,7 +93,7 @@
# Convert the multi-class labels to binary labels
# -----------------------------------------------
#
# The :class:`nilearn.decoding.Decoder` converts multi-class classification
# The :class:`~nilearn.decoding.Decoder` converts multi-class classification
# problem to N one-vs-others binary classification problems by default (where N
# is the number of unique labels)
#
Expand Down Expand Up @@ -129,7 +130,7 @@
fig, (ax_binary, ax_multi) = plt.subplots(
2, gridspec_kw={"height_ratios": [10, 1.5]}, figsize=(12, 2)
)
cmap = ListedColormap(["white"] + list(plt.cm.tab10.colors)[0:n_labels])
cmap = ListedColormap(["white"] + list(plt.cm.tab10.colors)[:n_labels])
binary_plt = ax_binary.imshow(
y_binary_.T,
aspect="auto",
Expand All @@ -145,7 +146,7 @@
label_multi = LabelEncoder()
y_multi = label_multi.fit_transform(y)
y_multi = y_multi.reshape(1, -1)
cmap = ListedColormap(list(plt.cm.tab10.colors)[0:n_labels])
cmap = ListedColormap(list(plt.cm.tab10.colors)[:n_labels])
multi_plt = ax_multi.imshow(
y_multi,
aspect="auto",
Expand Down Expand Up @@ -175,7 +176,7 @@
# -----------------
#
# After preprocessing the provided fMRI data, the
# :class:`nilearn.decoding.Decoder` performs a univariate feature selection on
# :class:`~nilearn.decoding.Decoder` performs a univariate feature selection on
# the voxels of the brain volume. It uses Scikit-Learn's
# :class:`~sklearn.feature_selection.SelectPercentile` with
# :func:`~sklearn.feature_selection.f_classif` to calculate ANOVA F-scores for
Expand Down Expand Up @@ -210,7 +211,7 @@
# Hyperparameter optimization
# ---------------------------
#
# The :class:`nilearn.decoding.Decoder` also performs hyperparameter tuning.
# The :class:`~nilearn.decoding.Decoder` also performs hyperparameter tuning.
# How this is done depends on the estimator used.
#
# For the support vector classifiers (known as SVC, and used by setting
Expand All @@ -224,14 +225,14 @@
# the training data.
#
# In addition, the parameter grids that are used for hyperparameter tuning
# by :class:`nilearn.decoding.Decoder` are also different from the default
# by :class:`~nilearn.decoding.Decoder` are also different from the default
# Scikit-Learn parameter grids for the corresponding ``<estimator_name>CV``
# objects.
#
# For simplicity, let's use Scikit-Learn's
# :class:`~sklearn.linear_model.LogisticRegressionCV` with custom parameter
# grid (via ``Cs`` parameter) as used in Nilearn's
# :class:`nilearn.decoding.Decoder`.
# :class:`~nilearn.decoding.Decoder`.

from sklearn.linear_model import LogisticRegressionCV

Expand All @@ -247,7 +248,7 @@
# -----------------------------------------------------
#
# Now let's put all the pieces together to train and cross-validate. The
# :class:`nilearn.decoding.Decoder` uses a leave-one-group-out
# :class:`~nilearn.decoding.Decoder` uses a leave-one-group-out
# cross-validation scheme by default in cases where groups are defined. In our
# example a group is a run, so we will use Scikit-Learn's
# :class:`~sklearn.model_selection.LeaveOneGroupOut`
Expand Down Expand Up @@ -290,12 +291,12 @@
scores_sklearn.append(score)

# %%
# Decode via the :class:`nilearn.decoding.Decoder`
# ------------------------------------------------
# Decode via the :class:`~nilearn.decoding.Decoder`
# -------------------------------------------------
#
# All these steps can be done in a few lines and made faster via parallel
# processing using the ``n_jobs`` parameter in
# :class:`nilearn.decoding.Decoder`.
# :class:`~nilearn.decoding.Decoder`.

from nilearn.decoding import Decoder

Expand Down Expand Up @@ -323,10 +324,10 @@

# %%
# As we can see, the mean AU-ROC scores from the Scikit-Learn pipeline and
# Nilearn's :class:`nilearn.decoding.Decoder` are identical.
# Nilearn's :class:`~nilearn.decoding.Decoder` are identical.
#
# The advantage of using Nilearn's :class:`nilearn.decoding.Decoder` is
# The advantage of using Nilearn's :class:`~nilearn.decoding.Decoder` is
# that it does all these steps under the hood and provides a simple interface
# to train, cross-validate and predict on new data, while also parallelizing
# the computations to make the cross-validation faster. It also organises the
# results in a structured way that can be easily accessed and analysed.
# the computations to make the cross-validation faster. It also organizes the
# results in a structured way that can be easily accessed and analyzed.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Run different estimators\n\nWe can now run different estimators and look at their prediction score,\nas well as the feature maps that they recover. Namely, we will use\n\n* A support vector regression ([SVM](https://scikit-learn.org/stable/modules/svm.html))\n\n* An [elastic-net](https://scikit-learn.org/stable/modules/linear_model.html#elastic-net)\n\n* A *Bayesian* ridge estimator, i.e. a ridge estimator that sets its\n parameter according to a metaprior\n\n* A ridge estimator that set its parameter by cross-validation\n\nNote that the `RidgeCV` and the `ElasticNetCV` have names ending in `CV`\nthat stands for `cross-validation`: in the list of possible `alpha`\nvalues that they are given, they choose the best by cross-validation.\n\n"
"## Run different estimators\n\nWe can now run different estimators and look at their prediction score,\nas well as the feature maps that they recover. Namely, we will use\n\n* A :sklearn:`support vector regression </modules/svm.html>`\n\n* An :sklearn:`elastic-net <modules/linear_model.html#elastic-net>`\n\n* A *Bayesian* ridge estimator, i.e. a ridge estimator that sets its\n parameter according to a metaprior\n\n* A ridge estimator that set its parameter by cross-validation\n\nNote that the `RidgeCV` and the `ElasticNetCV` have names ending in `CV`\nthat stands for `cross-validation`: in the list of possible `alpha`\nvalues that they are given, they choose the best by cross-validation.\n\n"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This example uses Voxel-Based Morphometry (:term:`VBM`)
to study the relationship between aging and gray matter density.
The data come from the `OASIS <https://www.oasis-brains.org/>`_ project.
The data come from the `OASIS <https://sites.wustl.edu/oasisbrains/>`_ project.
If you use it, you need to agree with the data usage agreement available
on the website.
Expand Down Expand Up @@ -56,7 +56,7 @@
# %%
import numpy as np

from nilearn import datasets
from nilearn.datasets import fetch_oasis_vbm
from nilearn.image import get_data
from nilearn.maskers import NiftiMasker

Expand All @@ -65,9 +65,7 @@
# %%
# Load Oasis dataset
# ------------------
oasis_dataset = datasets.fetch_oasis_vbm(
n_subjects=n_subjects, legacy_format=False
)
oasis_dataset = fetch_oasis_vbm(n_subjects=n_subjects, legacy_format=False)
gray_matter_map_filenames = oasis_dataset.gray_matter_maps
age = oasis_dataset.ext_vars["age"].to_numpy()

Expand Down Expand Up @@ -109,7 +107,7 @@

# %%
# Prediction pipeline with :term:`ANOVA` and SVR using
# :class:`nilearn.decoding.DecoderRegressor` Object
# :class:`~nilearn.decoding.DecoderRegressor` Object
#
# In nilearn we can benefit from the built-in DecoderRegressor object to
# do :term:`ANOVA` with SVR instead of manually defining the whole pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# NeuroVault cross-study ICA maps\n\nThis example shows how to download statistical maps from\nNeuroVault, label them with NeuroSynth terms,\nand compute :term:`ICA` components across all the maps.\n\nSee :func:`nilearn.datasets.fetch_neurovault`\ndocumentation for more details.\n\n.. include:: ../../../examples/masker_note.rst\n\n..\n Original authors:\n\n - Ben Cipollini\n\n Ported from code authored by Chris Filo Gorgolewski, Gael Varoquaux\n https://github.com/NeuroVault/neurovault_analysis\n"
"\n# NeuroVault cross-study ICA maps\n\nThis example shows how to download statistical maps from\nNeuroVault, label them with NeuroSynth terms,\nand compute :term:`ICA` components across all the maps.\n\nSee :func:`~nilearn.datasets.fetch_neurovault`\ndocumentation for more details.\n\n.. include:: ../../../examples/masker_note.rst\n\n..\n Original authors:\n\n - Ben Cipollini\n\n Ported from code authored by Chris Filo Gorgolewski, Gael Varoquaux\n https://github.com/NeuroVault/neurovault_analysis\n"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
===============================
The goal of this example is to illustrate the use of the function
:func:`nilearn.image.resample_to_img` to resample an image to a template.
:func:`~nilearn.image.resample_to_img` to resample an image to a template.
We use the MNI152 template as the reference for resampling a t-map image.
Function :func:`nilearn.image.resample_img` could also be used to achieve this.
Function :func:`~nilearn.image.resample_img`
could also be used to achieve this.
"""

# %%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
Regions extraction using dictionary learning and functional connectomes
=======================================================================
This example shows how to use :class:`nilearn.regions.RegionExtractor`
This example shows how to use :class:`~nilearn.regions.RegionExtractor`
to extract spatially constrained brain regions from whole brain maps decomposed
using :term:`Dictionary learning` and use them to build
a :term:`functional connectome`.
We used 20 movie-watching functional datasets from
:func:`nilearn.datasets.fetch_development_fmri` and
:class:`nilearn.decomposition.DictLearning` for set of brain atlas maps.
:func:`~nilearn.datasets.fetch_development_fmri` and
:class:`~nilearn.decomposition.DictLearning` for set of brain atlas maps.
This example can also be inspired to apply the same steps
to even regions extraction
using :term:`ICA` maps.
In that case, idea would be to replace
:term:`Dictionary learning` to canonical :term:`ICA` decomposition
using :class:`nilearn.decomposition.CanICA`
using :class:`~nilearn.decomposition.CanICA`
Please see the related documentation
of :class:`nilearn.regions.RegionExtractor` for more details.
of :class:`~nilearn.regions.RegionExtractor` for more details.
"""

Expand Down
Loading

0 comments on commit 9dafe0d

Please sign in to comment.