ILCB -TD MASCO 2023

This course is an introduction to the practice of the ‘nilearn’ (TD_MRI) and ‘MNE-python’ (TD_MEG) toolboxes. Focus will be placed on visualization and more classical analysis of functional MRI and MEG data. (For more details, on python toolboxes, see MNE-python and Nilearn web pages.

Please download datasets and install the toolbox beforehand according to the following instructions (It takes a little time!).
In case of installation problems, please send an email to the following contact: valerie.chanoine@uni-amu.fr

The steps 4 and 5 are optional. Use only if you want to use an editor called ‘spyder’ instead of ‘notebooks’.
Other comment for MNE-python : If you already have a version of mne-python installed. Go to steps 7 and 8 to check that the script works. If the 2 tests work, that’s fine. If test1 only works, you won’t have access to the visualisations of 3D images.

Step 1. Download datasets

Link to MRI ressources

Link to MEG ressources

Step 2. MNE-Python installer

IF YOU DO NOT HAVE MNE-PYTHON INSTALLED – have an install via the installers page, here

Write ‘yes’ to accept the license.

Step 3. Open an terminal

Here, this is an example with Linux.

Step 4. Check your “python.exe” based on mne environment

Write the following command in your terminal.

python -c "import sys; print(sys.executable)"

Step 5. Test an IDE (integrated development environment) called SPYDER

Write the following command in your terminal.

spyder

The last command open an application “Spyder”. Go to the Menu -> Tools > Preferences > Python interpreter

Check “Use the following Python interpreter” and select the file “python.exe” from “mne’ environment if the mne environment is not the default one.

Open a new python file (extension “py”) , write “import mne” and execute the file

import mne

Step 6. Test “jupyter notebook”

In the terminal, type the following command:

jupyter notebook

This command open a jupyter web page…

Create a new notebook(menu File>New>Notebook).

Select the default kernel

Step 7. Test your MNE-python install (test 1)

Write ‘import mne’

import mne

Execute the code…

If no errors appear, that’s perfect!

Step 8. Test your MNE-python install (test 2)

Execute the following code on jupyter notebook. Modify the dataset path and don’t forget to unzip the archived folders from dataset!

import mne
from os.path import join as op

# Define a folder for the MNE-python dataset

# with Windows:
# datasetDir = r"F:\MASCO_TD\MEG module\2022\dataset"

# with Linux or MacOs:
datasetDir = '/home/chanoine/Documents/TD-MASCO/MEG/dataset'

fsDir = op(datasetDir,"FreeSurfer")
subName = 'sample'

Brain = mne.viz.get_brain_class()
brain = Brain(subName, hemi='lh', surf='pial', subjects_dir=fsDir, size=(800, 600))

# Interact with the Brain object (e.g., rotating, zooming)
brain.show_view('lateral')  # Change the view

# To display the Brain object in your Jupyter Notebook, simply execute the object
brain

Step 9. Test your nilearn package

import nilearn

If the command doesn’t work, go to the web page, here for the install recommandations, here.

Step 10. Download the notebooks

MRI notebooks

MEG notebooks

Blog du Centre de Ressources pour l'Expérimentation de l'ILCB

Rechercher dans OpenEdition Search

Vous allez être redirigé vers OpenEdition Search