"""
.. _ex-source-space-morphing:
=========================
Use source space morphing
=========================
This example shows how to use source space morphing (as opposed to
:class:`~mne.SourceEstimate` morphing) to create data that can be compared
between subjects.
.. warning:: Source space morphing will likely lead to source spaces that are
less evenly sampled than source spaces created for individual
subjects. Use with caution and check effects on localization
before use.
"""
import mne
data_path = mne.datasets.sample.data_path()
subjects_dir = data_path / "subjects"
fname_trans = data_path / "MEG" / "sample" / "sample_audvis_raw-trans.fif"
fname_bem = subjects_dir / "sample" / "bem" / "sample-5120-bem-sol.fif"
fname_src_fs = subjects_dir / "fsaverage" / "bem" / "fsaverage-ico-5-src.fif"
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_raw.fif"
info = mne.io.read_info(raw_fname)
info = mne.pick_info(info, mne.pick_types(info, meg=True, eeg=False, exclude=[]))
src_fs = mne.read_source_spaces(fname_src_fs)
src_morph = mne.morph_source_spaces(
src_fs, subject_to="sample", subjects_dir=subjects_dir
)
fwd = mne.make_forward_solution(info, trans=fname_trans, src=src_morph, bem=fname_bem)
mag_map = mne.sensitivity_map(fwd, ch_type="mag")
mag_map_fs = mag_map.to_original_src(src_fs, subjects_dir=subjects_dir)
kwargs = dict(
clim=dict(kind="percent", lims=[0, 50, 99]),
smoothing_steps=1,
hemi="rh",
views=["lat"],
)
brain_subject = mag_map.plot(
time_label="Morphed", subjects_dir=subjects_dir, **kwargs
)
brain_fs = mag_map_fs.plot(
time_label="Remapped", subjects_dir=subjects_dir, **kwargs
)