A python notebook

How can we share with non-techy friends

Published

2024-12-11

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.

STAT_IMG = datasets.load_sample_motor_activation_image()
fsaverage = datasets.fetch_surf_fsaverage()

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.

curv_right = surface.load_surf_data(fsaverage.curv_right)
curv_right_sign = np.sign(curv_right)
curv_left = surface.load_surf_data(fsaverage.curv_left)
curv_left_sign = np.sign(curv_left)

Now convert (sample) a 3d statistical image into the mesh format - a texture - that can be mapped onto the surface.

texture = surface.vol_to_surf(STAT_IMG, fsaverage.pial_right)
anat = plotting.plot_surf(fsaverage.pial_left, 
                          bg_map=curv_left_sign)

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} \]