= datasets.load_sample_motor_activation_image()
STAT_IMG = datasets.fetch_surf_fsaverage() fsaverage
A python notebook
How can we share with non-techy friends
VScode tells us about the conda
environment we used… to make sure we can re-run the code at some pointer later.
Connected to nsd-analysis (Python 3.10.15)
This is an ipynb
notebook
A minimal working example of a python notebook and how to render to a nice version in html
or pdf
Load in an example dataset that comes with the nilearn
module. And also get the mesh data from the freesurfer fsaverage
mesh.
To render the light gray and dark gray landmarks on the surface, we can use information about the curvature and label whether it is a a hump, gyrus or a trough, sulcus.
= surface.load_surf_data(fsaverage.curv_right)
curv_right = np.sign(curv_right)
curv_right_sign = surface.load_surf_data(fsaverage.curv_left)
curv_left = np.sign(curv_left) curv_left_sign
Now convert (sample) a 3d statistical image into the mesh format - a texture - that can be mapped onto the surface.
= surface.vol_to_surf(STAT_IMG, fsaverage.pial_right) texture
= plotting.plot_surf(fsaverage.pial_left,
anat =curv_left_sign) bg_map
Using more funky plotting
We can use a nilearn
function to display a rendering in place.
plotting.plot_surf_stat_map()
some gratuitious maths \[ \sum_i \frac{(x_i - \bar{x})^2}{n} \]