File: left_cerebellum_volume_source.py

package info (click to toggle)
python-mne 1.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 131,492 kB
  • sloc: python: 213,302; javascript: 12,910; sh: 447; makefile: 144
file content (80 lines) | stat: -rw-r--r-- 2,191 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
.. _ex-cerebellum-source-space:

==============================================
Generate a left cerebellum volume source space
==============================================

Generate a volume source space of the left cerebellum and plot its vertices
relative to the left cortical surface source space and the FreeSurfer
segmentation file.
"""

# Author: Alan Leggitt <alan.leggitt@ucsf.edu>
#
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.

# %%

import mne
from mne import setup_source_space, setup_volume_source_space
from mne.datasets import sample

print(__doc__)

data_path = sample.data_path()
subjects_dir = data_path / "subjects"
subject = "sample"
aseg_fname = subjects_dir / "sample" / "mri" / "aseg.mgz"

# %%
# Setup the source spaces

# setup a cortical surface source space and extract left hemisphere
surf = setup_source_space(subject, subjects_dir=subjects_dir, add_dist=False)
lh_surf = surf[0]

# setup a volume source space of the left cerebellum cortex
volume_label = "Left-Cerebellum-Cortex"
sphere = (0, 0, 0, 0.12)
lh_cereb = setup_volume_source_space(
    subject,
    mri=aseg_fname,
    sphere=sphere,
    volume_label=volume_label,
    subjects_dir=subjects_dir,
    sphere_units="m",
)

# Combine the source spaces
src = surf + lh_cereb

# %%
# Plot the positions of each source space

fig = mne.viz.plot_alignment(
    subject=subject,
    subjects_dir=subjects_dir,
    surfaces="white",
    coord_frame="mri",
    src=src,
)
mne.viz.set_3d_view(
    fig, azimuth=180, elevation=90, distance=0.30, focalpoint=(-0.03, -0.01, 0.03)
)

# %%
# You can export source positions to a NIfTI file::
#
#     >>> nii_fname = 'mne_sample_lh-cerebellum-cortex.nii'
#     >>> src.export_volume(nii_fname, mri_resolution=True)
#
# And display source positions in freeview::
#
#    >>> from mne.utils import run_subprocess
#    >>> mri_fname = subjects_dir / "sample" / "mri" / "brain.mgz"
#    >>> run_subprocess(["freeview", "-v", str(mri_fname), "-v",
#                        f"{aseg_fname}:colormap=lut:opacity=0.5",
#                        "-v", f"{nii_fname}:colormap=jet:colorscale=0,2",
#                        "--slice", "157", "75", "105"])