Skip to content

Commit 71551ea

Browse files
davidhaslacherlarsoner
authored andcommitted
FIX: Selecting correct position information from layout in plot_joint (#5765)
* FIX: issue #5764. Position information from layout restricted to channels that actually exist in info. * Bugfix for issue #5764. Position information from layout restricted to channels that actually exist in info. * Update tfr.py * FIX: Issue #5764. * FIX: Issue #5764. * FIX: Issue #5764. * FIX: Issue #5764. * style * style * Update tfr.py * pep8 * pep8 * Update whats_new.rst * Update whats_new.rst
1 parent feb0bec commit 71551ea

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

doc/whats_new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Bug
4848

4949
- Fix path bugs in :func:`mne.bem.make_flash_bem` and :ref:`gen_mne_flash_bem` by `Eric Larson`_
5050

51+
- Fixed a bug where :meth:`mne.time_frequency.AverageTFR.plot_joint` would mishandle bad channels, by `David Haslacher`_ and `Jona Sassenhagen`_
52+
5153
API
5254
~~~
5355

@@ -3118,3 +3120,5 @@ of commits):
31183120
.. _Sara Sommariva: http://www.dima.unige.it/~sommariva/
31193121

31203122
.. _Cristóbal Moënne-Loccoz: https://github.com/cmmoenne
3123+
3124+
.. _David Haslacher: https://github.com/davidhaslacher

mne/time_frequency/tests/test_tfr.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,12 @@ def test_plot_joint():
521521
topomap_args=topomap_args)
522522
plt.close('all')
523523
assert_array_equal(tfr.data, tfr_orig.data)
524-
assert (set(tfr.ch_names) == set(tfr_orig.ch_names))
525-
assert (set(tfr.times) == set(tfr_orig.times))
524+
assert set(tfr.ch_names) == set(tfr_orig.ch_names)
525+
assert set(tfr.times) == set(tfr_orig.times)
526+
527+
# test tfr with picked channels
528+
tfr.pick_channels(tfr.ch_names[:-1])
529+
tfr.plot_joint(title='auto', colorbar=True, topomap_args=topomap_args)
526530

527531

528532
def test_add_channels():
@@ -633,8 +637,8 @@ def test_compute_tfr():
633637

634638
# Inter-trial coherence tests
635639
out = _compute_tfr(data, freqs, sfreq, output='itc', n_cycles=2.)
636-
assert (np.sum(out >= 1) == 0)
637-
assert (np.sum(out <= 0) == 0)
640+
assert np.sum(out >= 1) == 0
641+
assert np.sum(out <= 0) == 0
638642

639643
# Check decim shapes
640644
# 2: multiple of len(times) even

mne/time_frequency/tfr.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,14 @@ def plot_joint(self, timefreqs=None, picks=None, baseline=None,
15241524

15251525
data = tfr.data
15261526

1527-
pos = find_layout(tfr.info).pos if layout is None else layout.pos
1527+
if layout is None:
1528+
loaded_layout = find_layout(tfr.info)
1529+
1530+
# only use position information for channels from layout
1531+
# whose names appear as a substring in tfr.ch_names
1532+
idx = [any(ch_name in ch_name_tfr for ch_name_tfr in tfr.ch_names)
1533+
for ch_name in loaded_layout.names]
1534+
pos = loaded_layout.pos[np.array(idx)]
15281535

15291536
# merging grads here before rescaling makes ERDs visible
15301537
if ch_type == 'grad':

0 commit comments

Comments
 (0)