<jupyter_start><jupyter_text>Compute source power using DICS beamfomerCompute a Dynamic Imaging of Coherent Sources (DICS) [1]_ filter fromsingle-trial activity to estimate source power across a frequency band. Thisexample demonstrates how to source localize the event-related synchronization(ERS) of beta band activity in the "somato" dataset.References----------.. [1] Gross et al. Dynamic imaging of coherent sources: Studying neural       interactions in the human brain. PNAS (2001) vol. 98 (2) pp. 694-699<jupyter_code># Author: <NAME> <<EMAIL>>
#         <NAME> <<EMAIL>>
#         <NAME> <<EMAIL>>
#
# License: BSD (3-clause)
import numpy as np
import mne
from mne.datasets import somato
from mne.time_frequency import csd_morlet
from mne.beamformer import make_dics, apply_dics_csd

print(__doc__)<jupyter_output><empty_output><jupyter_text>Reading the raw data and creating epochs:<jupyter_code>data_path = somato.data_path()
raw_fname = data_path + '/MEG/somato/sef_raw_sss.fif'
fname_fwd = data_path + '/MEG/somato/somato-meg-oct-6-fwd.fif'
subjects_dir = data_path + '/subjects'

raw = mne.io.read_raw_fif(raw_fname)

# Set picks, use a single sensor type
picks = mne.pick_types(raw.info, meg='grad', exclude='bads')

# Read epochs
events = mne.find_events(raw)
epochs = mne.Epochs(raw, events, event_id=1, tmin=-1.5, tmax=2, picks=picks,
                    preload=True)

# Read forward operator
fwd = mne.read_forward_solution(fname_fwd)<jupyter_output><empty_output><jupyter_text>We are interested in the beta band. Define a range of frequencies, using alog scale, from 12 to 30 Hz.<jupyter_code>freqs = np.logspace(np.log10(12), np.log10(30), 9)<jupyter_output><empty_output><jupyter_text>Computing the cross-spectral density matrix for the beta frequency band, fordifferent time intervals. We use a decim value of 20 to speed up thecomputation in this example at the loss of accuracy.<jupyter_code>csd = csd_morlet(epochs, freqs, tmin=-1, tmax=1.5, decim=20)
csd_baseline = csd_morlet(epochs, freqs, tmin=-1, tmax=0, decim=20)
# ERS activity starts at 0.5 seconds after stimulus onset
csd_ers = csd_morlet(epochs, freqs, tmin=0.5, tmax=1.5, decim=20)<jupyter_output><empty_output><jupyter_text>Computing DICS spatial filters using the CSD that was computed on the entiretimecourse.<jupyter_code>filters = make_dics(epochs.info, fwd, csd.mean(), pick_ori='max-power')<jupyter_output><empty_output><jupyter_text>Applying DICS spatial filters separately to the CSD computed using thebaseline and the CSD computed during the ERS activity.<jupyter_code>baseline_source_power, freqs = apply_dics_csd(csd_baseline.mean(), filters)
beta_source_power, freqs = apply_dics_csd(csd_ers.mean(), filters)<jupyter_output><empty_output><jupyter_text>Visualizing source power during ERS activity relative to the baseline power.<jupyter_code>stc = beta_source_power / baseline_source_power
message = 'DICS source power in the 12-30 Hz frequency band'
brain = stc.plot(hemi='both', views='par', subjects_dir=subjects_dir,
                 time_label=message)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10233160621761658, 'fraction_numerical': 0.018458549222797927, 'mean_word_length': 5.774122807017544, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '536333', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1055, 'n_words': 288, 'path': 'stable/_downloads/d4c795380277f09ea21841616baceb71/plot_dics_source_power.ipynb', 'repo_name': 'drammock/mne-tools.github.io', 'size': '3153'}