Skip to content

Commit

Permalink
Drop channel selection from LCMV example (mne-tools#4887)
Browse files Browse the repository at this point in the history
* drop channel selection

* fix typo

* organize sections and select preview image
  • Loading branch information
britta-wstnr authored and agramfort committed Jan 23, 2018
1 parent d1a1c47 commit b223ea3
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions examples/inverse/plot_lcmv_beamformer_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,32 @@

print(__doc__)

# sphinx_gallery_thumbnail_number = 3


###############################################################################
# Data preprocessing:

data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
event_fname = data_path + '/MEG/sample/sample_audvis_raw-eve.fif'
fname_fwd = data_path + '/MEG/sample/sample_audvis-meg-vol-7-fwd.fif'

###############################################################################
# Get epochs
event_id, tmin, tmax = 1, -0.2, 0.5
event_id, tmin, tmax = [1, 2], -0.2, 0.5

# Setup for reading the raw data
raw = mne.io.read_raw_fif(raw_fname, preload=True)
raw.info['bads'] = ['MEG 2443', 'EEG 053'] # 2 bads channels
events = mne.read_events(event_fname)

# Set up pick list: EEG + MEG - bad channels (modify to your needs)
left_temporal_channels = mne.read_selection('Left-temporal')
# Set up pick list: gradiometers and magnetometers, excluding bad channels
picks = mne.pick_types(raw.info, meg=True, eeg=False, stim=True, eog=True,
exclude='bads', selection=left_temporal_channels)
exclude='bads')

# Pick the channels of interest
raw.pick_channels([raw.ch_names[pick] for pick in picks])

# Re-normalize our empty-room projectors, so they are fine after subselection
raw.info.normalize_proj()

Expand All @@ -54,13 +59,20 @@
reject=dict(grad=4000e-13, mag=4e-12, eog=150e-6))
evoked = epochs.average()

forward = mne.read_forward_solution(fname_fwd)
# Visualize sensor space data
evoked.plot_joint()

###############################################################################
# Compute covariance matrices, fit and apply spatial filter.

# Read regularized noise covariance and compute regularized data covariance
noise_cov = mne.compute_covariance(epochs, tmin=tmin, tmax=0, method='shrunk')
data_cov = mne.compute_covariance(epochs, tmin=0.04, tmax=0.15,
method='shrunk')

# Read forward model
forward = mne.read_forward_solution(fname_fwd)

# Compute weights of free orientation (vector) beamformer with weight
# normalization (neural activity index, NAI). Providing a noise covariance
# matrix enables whitening of the data and forward solution. Source orientation
Expand All @@ -79,6 +91,9 @@
# compare conditions.
stc = apply_lcmv(evoked, filters, max_ori_out='signed')

###############################################################################
# Plot source space activity:

# take absolute values for plotting
stc.data[:, :] = np.abs(stc.data)

Expand All @@ -94,12 +109,16 @@
t1_fname = data_path + '/subjects/sample/mri/T1.mgz'

# Plotting with nilearn ######################################################
plot_stat_map(index_img(img, 61), t1_fname, threshold=1.35,
title='LCMV (t=%.1f s.)' % stc.times[61])
# Based on the visualization of the sensor space data (gradiometers), plot
# activity at 88 ms
idx = stc.time_as_index(0.088)
plot_stat_map(index_img(img, idx), t1_fname, threshold=0.45,
title='LCMV (t=%.3f s.)' % stc.times[idx])

# plot source time courses with the maximum peak amplitudes
# plot source time courses with the maximum peak amplitudes at 88 ms
plt.figure()
plt.plot(stc.times, stc.data[np.argsort(np.max(stc.data, axis=1))[-40:]].T)
plt.plot(stc.times, stc.data[np.argsort(np.max(stc.data[:, idx],
axis=1))[-40:]].T)
plt.xlabel('Time (ms)')
plt.ylabel('LCMV value')
plt.show()

0 comments on commit b223ea3

Please sign in to comment.