.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/mass-univariate-statistics/volume-source-space.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_mass-univariate-statistics_volume-source-space.py: .. _exa-vol: Volume source space =================== .. currentmodule:: eelbrain Basic analysis of volume source space vector data. .. contents:: Contents :local: Dataset ^^^^^^^ Load the :mod:`mne` sample data with responses to tones. Data contains multiple trials for a single subject, with tones presented to the left or right ear: .. GENERATED FROM PYTHON SOURCE LINES 20-33 .. code-block:: Python # sphinx_gallery_thumbnail_number = 2 # dataset: mne_sample from pathlib import Path from eelbrain import * import mne # Load the dataset data = datasets.get_mne_sample(src='vol', ori='vector') data.head() .. raw:: html
# i_start trigger index condition side modality
0 6994 2 0 RA R A
1 7192 1 2 LA L A
2 7413 2 4 RA R A
3 7612 1 6 LA L A
4 7810 2 8 RA R A
5 8025 1 10 LA L A
6 8233 2 12 RA R A
7 8428 1 14 LA L A
8 8633 2 16 RA R A
9 8857 1 19 LA L A
NDVars: src


.. GENERATED FROM PYTHON SOURCE LINES 34-38 One-sample test ^^^^^^^^^^^^^^^ A one-sample test can be used to detect significant activations. Perform a one-sample test on the right-ear trials only: .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python result = testnd.Vector('src', sub="side == 'R'", data=data, samples=250, tfce=True, tstart=0.05, tstop=0.200) .. GENERATED FROM PYTHON SOURCE LINES 42-43 Morph the data to the template brain for anatomical visualization. .. GENERATED FROM PYTHON SOURCE LINES 43-68 .. code-block:: Python # Store the test result as NDVar y = result.masked_difference() # Make sure the source space for fsaverage exists fname_src_fsaverage = Path(y.source.subjects_dir) / "fsaverage" / "bem" / "fsaverage-vol-7-src.fif" if fname_src_fsaverage.exists(): src_fs = mne.read_source_spaces(fname_src_fsaverage) else: src_fs = mne.setup_volume_source_space('fsaverage', 7, subjects_dir=y.source.subjects_dir) src_fs.save(Path(y.source.subjects_dir) / "fsaverage" / "bem" / "fsaverage-vol-7-src.fif") # Compute the transformation from the sample subject to fsaverage morph = mne.compute_source_morph( y.source.get_source_space(), subject_from=y.source.subject, subjects_dir=y.source.subjects_dir, niter_affine=[10, 10, 5], niter_sdr=[10, 10, 5], # just for speed src_to=src_fs, ) # Morph the test result y = morph_source_space(y, 'fsaverage', morph=morph) .. rst-class:: sphx-glr-script-out .. code-block:: none [2026-05-19 11:06:53][dipy] INFO: ➞ Running center_of_mass step from affine registration... [2026-05-19 11:06:53][dipy] INFO: ➞ Running translation step from affine registration... [2026-05-19 11:06:54][dipy] INFO: ➞ Running rigid step from affine registration... [2026-05-19 11:06:54][dipy] INFO: ➞ Running affine step from affine registration... [2026-05-19 11:06:54][dipy] INFO: Creating scale space from the moving image. Levels: 3. Sigma factor: 0.200000. [2026-05-19 11:06:54][dipy] INFO: Creating scale space from the static image. Levels: 3. Sigma factor: 0.200000. [2026-05-19 11:06:54][dipy] INFO: Optimizing level 2 [2026-05-19 11:06:54][dipy] INFO: Optimizing level 1 [2026-05-19 11:06:54][dipy] INFO: Optimizing level 0 .. GENERATED FROM PYTHON SOURCE LINES 69-73 For static visualization, we can use a combination of :class:`plot.Butterfly` and :class:`plot.GlassBrain` plots. A :class:`plot.Butterfly` plot can give a quick overview of amplitudes over time: .. GENERATED FROM PYTHON SOURCE LINES 73-85 .. code-block:: Python # Extract vector norm (amplitude) y_norm = y.norm('space') # Split data by hemisphere butterfly_data = [y_norm.sub(source=hemi, name=hemi.capitalize()) for hemi in ['lh', 'rh']] # Buterfly plot p = plot.Butterfly(butterfly_data, axh=2, axw=3) # Mark time points for anatomical visualization times = [0.090, 0.160] for t in times: p.add_vline(t) .. image-sg:: /auto_examples/mass-univariate-statistics/images/sphx_glr_volume-source-space_001.png :alt: Lh, Rh :srcset: /auto_examples/mass-univariate-statistics/images/sphx_glr_volume-source-space_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 86-93 :class:`plot.GlassBrain` plots show anatomical distribution of activity at relevant time points. Glassbrains project activity through the head, i.e., each voxel in a projection shows the largest value along the line of sight. By comparing different projections, the 3D distribution of activity can be inferred. Here, the lateral view shows activity in temporal regions over auditory cortex, while the coronal view shows how lateral/medial the peaks are: .. GENERATED FROM PYTHON SOURCE LINES 93-97 .. code-block:: Python for t in times: p = plot.GlassBrain(y.sub(time=t), title=f"{t * 1000:.0f} ms", vmax=4) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/mass-univariate-statistics/images/sphx_glr_volume-source-space_002.png :alt: 90 ms :srcset: /auto_examples/mass-univariate-statistics/images/sphx_glr_volume-source-space_002.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/mass-univariate-statistics/images/sphx_glr_volume-source-space_003.png :alt: 160 ms :srcset: /auto_examples/mass-univariate-statistics/images/sphx_glr_volume-source-space_003.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 98-101 In a notebook, `LiveNeuron `_ can provide interactive visualization. Start the visualization with the code below (after uncommenting): .. GENERATED FROM PYTHON SOURCE LINES 101-107 .. code-block:: Python # from eelbrain_plotly_viz import EelbrainPlotly2DViz # viz = EelbrainPlotly2DViz(result.difference, layout_mode='horizontal', realtime=True, arrow_scale=0.2) # viz.show_in_jupyter() .. GENERATED FROM PYTHON SOURCE LINES 108-110 In an interactive iPython session, butterfly and glassbrain plots can be linked for interactive visualization using: .. GENERATED FROM PYTHON SOURCE LINES 110-112 .. code-block:: Python # butterfly, brain = plot.GlassBrain.butterfly(result) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 54.080 seconds) .. _sphx_glr_download_auto_examples_mass-univariate-statistics_volume-source-space.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: volume-source-space.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: volume-source-space.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: volume-source-space.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_