{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Generate a left cerebellum volume source space\n\nGenerate a volume source space of the left cerebellum and plot its vertices\nrelative to the left cortical surface source space and the FreeSurfer\nsegmentation file.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Author: Alan Leggitt \n#\n# License: BSD-3-Clause\n# Copyright the MNE-Python contributors." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import mne\nfrom mne import setup_source_space, setup_volume_source_space\nfrom mne.datasets import sample\n\nprint(__doc__)\n\ndata_path = sample.data_path()\nsubjects_dir = data_path / \"subjects\"\nsubject = \"sample\"\naseg_fname = subjects_dir / \"sample\" / \"mri\" / \"aseg.mgz\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Setup the source spaces\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# setup a cortical surface source space and extract left hemisphere\nsurf = setup_source_space(subject, subjects_dir=subjects_dir, add_dist=False)\nlh_surf = surf[0]\n\n# setup a volume source space of the left cerebellum cortex\nvolume_label = \"Left-Cerebellum-Cortex\"\nsphere = (0, 0, 0, 0.12)\nlh_cereb = setup_volume_source_space(\n subject,\n mri=aseg_fname,\n sphere=sphere,\n volume_label=volume_label,\n subjects_dir=subjects_dir,\n sphere_units=\"m\",\n)\n\n# Combine the source spaces\nsrc = surf + lh_cereb" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot the positions of each source space\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fig = mne.viz.plot_alignment(\n subject=subject,\n subjects_dir=subjects_dir,\n surfaces=\"white\",\n coord_frame=\"mri\",\n src=src,\n)\nmne.viz.set_3d_view(\n fig, azimuth=180, elevation=90, distance=0.30, focalpoint=(-0.03, -0.01, 0.03)\n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can export source positions to a NIfTI file::\n\n >>> nii_fname = 'mne_sample_lh-cerebellum-cortex.nii'\n >>> src.export_volume(nii_fname, mri_resolution=True)\n\nAnd display source positions in freeview::\n\n >>> from mne.utils import run_subprocess\n >>> mri_fname = subjects_dir / \"sample\" / \"mri\" / \"brain.mgz\"\n >>> run_subprocess([\"freeview\", \"-v\", str(mri_fname), \"-v\",\n f\"{aseg_fname}:colormap=lut:opacity=0.5\",\n \"-v\", f\"{nii_fname}:colormap=jet:colorscale=0,2\",\n \"--slice\", \"157\", \"75\", \"105\"])\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 0 }