Note
Go to the end to download the full example code.
Run ICA on group fMRI data¶
ICA can be used to derive spatial maps or networks from group fMRI data by identifying distributed brain regions that exhibit similar BOLD fluctuations over time.
This example applies ICA to fMRI data measured while children and young adults watch movies. The resulting maps are visualized using Nilearn’s atlas plotting tools.
This example is borrowed from the nilearn Python package. We visually compare AMICA to the CanICA method implemented in Nilearn, which is specifically designed for group-level analysis of fMRI data.
Tip
TL;DR - I would probably just use CanICA or some other Group ICA method when working with study-wide fMRI data. This tutorial is for demonstration purposes and does not advocate for the use of AMICA over other methods tailored for fMRI.
from pathlib import Path
import warnings
import numpy as np
from sklearn.exceptions import ConvergenceWarning
from sklearn.utils.extmath import randomized_svd
from amica import AMICA
from nilearn.datasets import fetch_development_fmri
from nilearn.decomposition import CanICA
from nilearn.image import iter_img, math_img
from nilearn.plotting import plot_prob_atlas, plot_stat_map
def _orient_components(components):
"""Flip each component so its largest-magnitude peak is positive."""
components = components.copy()
for component in components:
if abs(component.min()) > abs(component.max()):
component *= -1.0
return components
def _subject_pca_reduce(subject_data, *, n_components, random_state):
"""Reduce one subject to a low-rank voxel representation."""
left_singular_vectors, singular_values, _ = randomized_svd(
subject_data.T,
n_components=n_components,
random_state=random_state,
)
return left_singular_vectors.T * singular_values[:, None]
def _build_group_matrix(func_filenames, *, masker, n_components, random_state):
"""Build a group matrix from masked subject data."""
reduced_subjects = [
_subject_pca_reduce(
masker.transform(func_file),
n_components=n_components,
random_state=random_state,
)
for func_file in func_filenames
]
reduced_data = np.vstack(reduced_subjects)
group_components, _, _ = randomized_svd(
reduced_data.T,
n_components=n_components,
transpose=True,
random_state=random_state,
n_iter=3,
)
return group_components.T
def fit_amica_components(canica, func_filenames):
"""Fit AMICA on a group matrix and return maps."""
group_matrix = _build_group_matrix(
func_filenames,
masker=canica.masker_,
n_components=canica.n_components,
random_state=canica.random_state,
)
amica = AMICA(
n_components=canica.n_components,
batch_size=4096,
max_iter=200,
random_state=canica.random_state,
verbose=1,
)
spatial_maps = _orient_components(amica.fit_transform(group_matrix.T).T)
components_img = canica.masker_.inverse_transform(spatial_maps)
return amica, group_matrix, components_img
def plot_components(components_img, *, prefix, n_plots=6):
"""Plot the first few component maps with a common color scale."""
vmax = np.percentile(np.abs(components_img.get_fdata()), 99.5)
for i, cur_img in enumerate(iter_img(components_img)):
if i >= n_plots:
break
plot_stat_map(
cur_img,
display_mode="z",
title=f"{prefix} IC {i}",
cut_coords=1,
vmin=-vmax,
vmax=vmax,
colorbar=False,
)
Load brain development fMRI dataset¶
rest_dataset = fetch_development_fmri(n_subjects=30)
func_filenames = rest_dataset.func
print(f"First functional nifti image (4D) is at: {rest_dataset.func[0]}")
[fetch_development_fmri] Added README.md to /home/circleci/nilearn_data
[fetch_development_fmri] Dataset created in
/home/circleci/nilearn_data/development_fmri
[fetch_development_fmri] Added README.md to
/home/circleci/nilearn_data/development_fmri
[fetch_development_fmri] Dataset created in
/home/circleci/nilearn_data/development_fmri/development_fmri
[fetch_development_fmri] Downloading data from https://osf.io/yr3av/download ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Dataset found in
/home/circleci/nilearn_data/development_fmri/development_fmri
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3ea4712b400183b70b7/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3eb2286e80019c3c194/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3e52286e80018c3e439/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3e72286e80017c41b3d/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3e4a743a9001760814f/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3e54712b400183b70a5/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3e14712b400183b7097/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3e32286e80018c3e42c/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3df4712b400183b7092/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3e04712b400193b5bdf/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3e9a743a90017608158/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3e82286e80018c3e443/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb47052f2be3c0017057069/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb46e5c353c5800199ac79f/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb47045a3bc970019f073a0/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb46e913992690018133b1c/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3912286e80018c3e393/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3952286e80017c41a1b/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb47023353c58001c9ac02b/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb46eaa39926900160f69af/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff391a743a900176080a9/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3914712b400173b5329/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb4702a353c58001b9cb5ae/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb46e9b39926900190fad5c/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff38f2286e80018c3e38d/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3914712b4001a3b5579/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb470413992690018133d8c/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb46e9a353c58001c9abeac/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb47016a3bc970017efe44f/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb46e43f2be3c0017056b8a/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff37da743a90018606df1/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff37c2286e80019c3c102/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb47056353c58001c9ac064/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb46e5af2be3c001801f799/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff38ca743a90018606dfe/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff38ca743a9001760809e/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff389a743a9001660a016/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff38c2286e80016c3c2da/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3884712b400183b7023/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3884712b400193b5b5c/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3872286e80017c419ea/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3872286e80017c419e9/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb4702f39926900171090ee/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb46e8b353c58001c9abe98/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3842286e80017c419e0/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3854712b4001a3b5568/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3814712b4001a3b5561/ ...
[fetch_development_fmri] ...done. (2 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3832286e80016c3c2d1/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3822286e80018c3e37b/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff382a743a90018606df8/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff37e2286e80016c3c2cb/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff3832286e80019c3c10f/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff37d4712b400193b5b54/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff37d4712b400183b7011/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb4701e3992690018133d4f/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb46e6b353c58001b9cb34f/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb4703bf2be3c001801fa49/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5cb46e92a3bc970019f0717f/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff38c4712b4001a3b5573/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
[fetch_development_fmri] Downloading data from
https://osf.io/download/5c8ff38da743a900176080a2/ ...
[fetch_development_fmri] ...done. (1 seconds, 0 min)
First functional nifti image (4D) is at: /home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar128_task-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz
Apply ICA on the data¶
output_dir = Path.cwd() / "results" / "plot_compare_decomposition"
output_dir.mkdir(exist_ok=True, parents=True)
print(f"Output will be saved to: {output_dir}")
Output will be saved to: /home/circleci/project/amica-python/docs/source/examples/results/plot_compare_decomposition
CanICA¶
canica = CanICA(
n_components=20,
memory="nilearn_cache",
memory_level=1,
verbose=1,
random_state=0,
mask_strategy="whole-brain-template",
n_jobs=4,
)
with warnings.catch_warnings():
warnings.filterwarnings(action="ignore", category=ConvergenceWarning)
canica.fit(func_filenames)
canica_components_img = canica.components_img_
canica_components_img.to_filename(output_dir / "canica_resting_state.nii.gz")
[CanICA.fit] Loading data from
['/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar128_tas
k-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar126_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar125_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar124_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar123_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar127_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar024_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar023_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar022_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar021_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar020_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar019_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar018_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar017_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar016_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar001_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar013_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar012_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar011_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar010_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar009_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar008_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar007_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar006_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar005_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar004_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar003_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar002_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar014_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz',
'/home/circleci/nilearn_data/development_fmri/development_fmri/sub-pixar015_task
-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz']
[CanICA.fit] Computing mask
[CanICA.fit] Resampling mask
[CanICA.fit] Finished fit
[CanICA.fit] Loading data
[CanICA.fit] Computing image from signals
[Parallel(n_jobs=4)]: Using backend LokyBackend with 4 concurrent workers.
[Parallel(n_jobs=4)]: Done 10 out of 10 | elapsed: 21.0s finished
[CanICA.fit] Computing image from signals
AMICA on a group matrix¶
_amica, amica_group_matrix, amica_components_img = fit_amica_components(
canica,
func_filenames,
)
amica_components_img.to_filename(output_dir / "amica_resting_state.nii.gz")
print(f"AMICA group matrix shape: {amica_group_matrix.shape}")
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/docs/source/examples/plot_fmri.py:60: FutureWarning: The 'zscore' strategy incorrectly uses population std to calculate sample zscores. The new strategy 'zscore_sample' corrects this behavior by using the sample std. In release 0.14.0, the 'zscore' option will be removed and using standardize=True will fall back to 'zscore_sample'.To avoid this warning, please use 'zscore_sample' instead.
masker.transform(func_file),
/home/circleci/project/amica-python/src/amica/core.py:890: ConvergenceWarning: Maximum number of iterations reached before convergence. Consider increasing max_iter or relaxing tol.
warn(
Finished in 95.90 seconds
[MultiNiftiMasker.inverse_transform] Computing image from signals
AMICA group matrix shape: (20, 21781)
Plot all components together¶
plot_prob_atlas(canica_components_img, title="All CanICA components")
plot_prob_atlas(
math_img("np.abs(img)", img=amica_components_img),
title="All AMICA components",
)
/home/circleci/project/amica-python/.venv/lib/python3.11/site-packages/numpy/ma/core.py:2885: UserWarning: Warning: converting a masked element to nan.
_data = np.array(data, dtype=dtype, copy=copy,
<nilearn.plotting.displays._slicers.OrthoSlicer object at 0x74b57f271950>
Plot the first few component maps separately¶
plot_components(canica_components_img, prefix="CanICA")
plot_components(amica_components_img, prefix="AMICA")
Total running time of the script: (5 minutes 23.727 seconds)













