Skip to content

Commit d5f1de4

Browse files
authored
[MRG] Fix bf proj with bads (#5855)
* _prepare_beamformer_input was ignoring the bad channels * update test for non-regression * update what's new * FIX: Fix tests
1 parent 42cf687 commit d5f1de4

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

doc/whats_new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Bug
6868

6969
- Fixed a bug where :meth:`mne.time_frequency.AverageTFR.plot_joint` would mishandle bad channels, by `David Haslacher`_ and `Jona Sassenhagen`_
7070

71+
- Fix issue with bad channels ignored in :func:`mne.beamformer.make_lcmv` and :func:`mne.beamformer.make_dics` by `Alex Gramfort`_
72+
7173
API
7274
~~~
7375

mne/beamformer/_compute_beamformer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def _prepare_beamformer_input(info, forward, label, picks, pick_ori,
171171
ch_names = [info_ch_names[k] for k in picks]
172172
fwd_ch_names = forward['sol']['row_names']
173173
# Keep channels in forward present in info:
174-
fwd_ch_names = [ch for ch in fwd_ch_names if ch in info_ch_names]
174+
fwd_ch_names = [ch for ch in fwd_ch_names if ch in ch_names]
175175
forward = pick_channels_forward(forward, fwd_ch_names)
176176
picks_forward = [fwd_ch_names.index(ch) for ch in ch_names]
177177

mne/beamformer/_lcmv.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,16 +423,17 @@ def _lcmv_source_power(info, forward, noise_cov, data_cov, reg=0.05,
423423
info, forward, label, picks, pick_ori)
424424

425425
# Handle whitening
426-
info = pick_info(
427-
info, [info['ch_names'].index(k) for k in ch_names
428-
if k in info['ch_names']])
426+
picks = [info['ch_names'].index(k) for k in ch_names
427+
if k in info['ch_names']]
428+
info = pick_info(info, picks)
429+
del picks # everything should be picked now
429430

430431
# XXX this could maybe use pca=True to avoid needing to use
431432
# _reg_pinv(..., rank=rank) later
432433
if noise_cov is not None:
433434
whitener_rank = None if rank == 'full' else rank
434435
whitener, _ = compute_whitener(
435-
noise_cov, info, picks, rank=whitener_rank)
436+
noise_cov, info, rank=whitener_rank)
436437

437438
# whiten the leadfield
438439
G = np.dot(whitener, G)

mne/beamformer/tests/test_lcmv.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,15 @@ def _get_data(tmin=-0.1, tmax=0.15, all_forward=True, epochs=True,
6666
left_temporal_channels = mne.read_selection('Left-temporal')
6767
picks = mne.pick_types(raw.info, selection=left_temporal_channels)
6868
picks = picks[::2] # decimate for speed
69+
# add a couple channels we will consider bad
70+
bad_picks = [100, 101]
71+
bads = [raw.ch_names[pick] for pick in bad_picks]
72+
assert not any(pick in picks for pick in bad_picks)
73+
picks = np.concatenate([picks, bad_picks])
6974
raw.pick_channels([raw.ch_names[ii] for ii in picks])
7075
del picks
76+
77+
raw.info['bads'] = bads # add more bads
7178
raw.info.normalize_proj() # avoid projection warnings
7279

7380
if epochs:

0 commit comments

Comments
 (0)