Skip to content

Commit

Permalink
Dev docs nilearn/nilearn@4a37172 : [ENH] Handling of SurfaceData in c…
Browse files Browse the repository at this point in the history
…ompute_contrast (#4610)

Co-authored-by: Remi Gau <[email protected]>
  • Loading branch information
actions-user and Remi-Gau committed Nov 12, 2024
1 parent 48ff05b commit 0562732
Show file tree
Hide file tree
Showing 744 changed files with 18,566 additions and 19,689 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@

# %%
# Display ROI on surface
from nilearn.experimental.plotting import plot_surf_roi, plot_surf_stat_map
from nilearn.plotting import show
from nilearn.plotting import plot_surf_roi, plot_surf_stat_map, show

# Transform ROI indices in ROI map
pcc_map = np.zeros(parcellation.shape[0], dtype=int)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,39 @@
cv=cv,
)
searchlight.fit(fmri_img, y)

# %%
# Accessing the searchlight results
# ---------------------------------
# Visualization
# -------------
from nilearn import image
from nilearn.plotting import plot_img, plot_stat_map, show

# After fitting the searchlight, we can access the searchlight scores
# as a NIfTI image using the `scores_img_` attribute.
scores_img = searchlight.scores_img_
print("Searchlight scores image created:", scores_img)

# Use the :term:`fMRI` mean image as a surrogate of anatomical data
mean_fmri = image.mean_img(fmri_img, copy_header=True)

# Because scores are not a zero-center test statistics,
# we cannot use plot_stat_map
plot_img(
scores_img,
bg_img=mean_fmri,
title="Searchlight scores image",
display_mode="z",
cut_coords=[-9],
vmin=0.42,
cmap="hot",
threshold=0.2,
black_bg=True,
)

# %%
# F-scores computation
# --------------------
from sklearn.feature_selection import f_classif

from nilearn.maskers import NiftiMasker

# For decoding, standardizing is often very important
Expand All @@ -111,37 +134,11 @@
)
fmri_masked = nifti_masker.fit_transform(fmri_img)

from sklearn.feature_selection import f_classif

_, p_values = f_classif(fmri_masked, y)
p_values = -np.log10(p_values)
p_values[p_values > 10] = 10
p_unmasked = get_data(nifti_masker.inverse_transform(p_values))

# %%
# Visualization
# -------------
# Use the :term:`fMRI` mean image as a surrogate of anatomical data
from nilearn import image

mean_fmri = image.mean_img(fmri_img, copy_header=True)

from nilearn.plotting import plot_img, plot_stat_map, show

# Because scores are not a zero-center test statistics, we cannot use
# plot_stat_map
plot_img(
scores_img,
bg_img=mean_fmri,
title="Searchlight scores image",
display_mode="z",
cut_coords=[-9],
vmin=0.42,
cmap="hot",
threshold=0.2,
black_bg=True,
)

# F_score results
p_ma = np.ma.array(p_unmasked, mask=np.logical_not(process_mask))
f_score_img = new_img_like(mean_fmri, p_ma)
Expand Down
Binary file modified dev/_downloads/2ce0f24d145edf0cb7091fe8dae3bd07/plot_carpet.zip
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 @@ -40,7 +40,7 @@
},
"outputs": [],
"source": [
"from nilearn.experimental import plotting\nfrom nilearn.plotting import show\n\nplotting.plot_surf_roi(\n roi_map=destrieux_atlas,\n hemi=\"left\",\n view=\"lateral\",\n bg_map=fsaverage_sulcal,\n bg_on_data=True,\n darkness=0.5,\n title=\"Destrieux parcellation on sulcal surface\",\n)"
"from nilearn.plotting import plot_surf_roi, show\n\nplot_surf_roi(\n roi_map=destrieux_atlas,\n hemi=\"left\",\n view=\"lateral\",\n bg_map=fsaverage_sulcal,\n bg_on_data=True,\n darkness=0.5,\n title=\"Destrieux parcellation on sulcal surface\",\n)"
]
},
{
Expand All @@ -58,7 +58,7 @@
},
"outputs": [],
"source": [
"for view in [\"lateral\", \"posterior\", \"ventral\"]:\n plotting.plot_surf_roi(\n surf_mesh=fsaverage_meshes[\"inflated\"],\n roi_map=destrieux_atlas,\n hemi=\"left\",\n view=view,\n bg_map=fsaverage_sulcal,\n bg_on_data=True,\n darkness=0.5,\n title=f\"Destrieux parcellation on inflated surface\\n{view} view\",\n )\n\nshow()"
"for view in [\"lateral\", \"posterior\", \"ventral\"]:\n plot_surf_roi(\n surf_mesh=fsaverage_meshes[\"inflated\"],\n roi_map=destrieux_atlas,\n hemi=\"left\",\n view=view,\n bg_map=fsaverage_sulcal,\n bg_on_data=True,\n darkness=0.5,\n title=f\"Destrieux parcellation on inflated surface\\n{view} view\",\n )\n\nshow()"
]
},
{
Expand All @@ -76,7 +76,7 @@
},
"outputs": [],
"source": [
"elev, azim = 210.0, 90.0 # appropriate for visualizing, e.g., the OTS\nplotting.plot_surf_roi(\n surf_mesh=fsaverage_meshes[\"inflated\"],\n roi_map=destrieux_atlas,\n hemi=\"left\",\n view=(elev, azim),\n bg_map=fsaverage_sulcal,\n bg_on_data=True,\n darkness=0.5,\n title=\"Arbitrary view of Destrieux parcellation\",\n)"
"elev, azim = 210.0, 90.0 # appropriate for visualizing, e.g., the OTS\nplot_surf_roi(\n surf_mesh=fsaverage_meshes[\"inflated\"],\n roi_map=destrieux_atlas,\n hemi=\"left\",\n view=(elev, azim),\n bg_map=fsaverage_sulcal,\n bg_on_data=True,\n darkness=0.5,\n title=\"Arbitrary view of Destrieux parcellation\",\n)"
]
},
{
Expand Down Expand Up @@ -112,7 +112,7 @@
},
"outputs": [],
"source": [
"view = plotting.view_surf(\n surf_mesh=fsaverage_meshes[\"inflated\"],\n surf_map=destrieux_atlas,\n cmap=\"gist_ncar\",\n symmetric_cmap=False,\n colorbar=False,\n)\n# In a Jupyter notebook, if ``view`` is the output of a cell,\n# it will be displayed below the cell\nview\n\n# uncomment this to open the plot in a web browser:\n# view.open_in_browser()"
"from nilearn.plotting import view_surf\n\nview = view_surf(\n surf_mesh=fsaverage_meshes[\"inflated\"],\n surf_map=destrieux_atlas,\n cmap=\"gist_ncar\",\n symmetric_cmap=False,\n colorbar=False,\n)\n# In a Jupyter notebook, if ``view`` is the output of a cell,\n# it will be displayed below the cell\nview\n\n# uncomment this to open the plot in a web browser:\n# view.open_in_browser()"
]
},
{
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 @@ -56,7 +56,7 @@
# You can visualize the texture on the surface using the function
# :func:`~nilearn.plotting.plot_surf_stat_map` which uses ``matplotlib``
# as the default plotting engine.
from nilearn.experimental.plotting import plot_surf_stat_map
from nilearn.plotting import plot_surf_stat_map

fig = plot_surf_stat_map(
stat_map=img,
Expand Down Expand Up @@ -172,7 +172,7 @@
# %%
# Display outlines of the regions of interest on top of a statistical map
# -----------------------------------------------------------------------
from nilearn.experimental.plotting import plot_surf_contours
from nilearn.plotting import plot_surf_contours

fsaverage_sulcal = load_fsaverage_data(data_type="sulcal", mesh_type="pial")

Expand All @@ -199,10 +199,11 @@
show()
elif engine == "plotly":
figure.add_contours(
roi_map=destrieux_atlas.data.parts["right"],
roi_map=destrieux_atlas,
levels=regions_indices,
labels=labels,
lines=[{"width": 5}],
hemi="right",
)
# view the contours in a browser
# figure.show()
Expand All @@ -229,7 +230,7 @@
)

plot_surf_stat_map(
big_img,
stat_map=big_img,
surf_mesh=big_fsaverage_meshes["inflated"],
hemi="right",
colorbar=True,
Expand Down Expand Up @@ -272,7 +273,7 @@
# :func:`nilearn.plotting.view_img_on_surf` that give
# more interactive visualizations in a web browser.
# See :ref:`interactive-surface-plotting` for more details.
from nilearn.experimental.plotting import view_surf
from nilearn.plotting import view_surf

view = view_surf(
surf_mesh=fsaverage_meshes["inflated"],
Expand Down
Binary file not shown.
Binary file modified dev/_downloads/44cb3a7d606fae23fb2b04d989cc6947/plot_hrf.zip
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 0562732

Please sign in to comment.