From d0ec2b2d790b6ababca3ecdc5b51467b166f4578 Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Fri, 15 Nov 2019 10:13:26 +1100 Subject: [PATCH 01/15] Add support for NIRS to plot_topomap --- doc/changes/latest.inc | 2 ++ mne/channels/channels.py | 3 ++- mne/viz/topomap.py | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/changes/latest.inc b/doc/changes/latest.inc index f85500dd1a1..33999191029 100644 --- a/doc/changes/latest.inc +++ b/doc/changes/latest.inc @@ -67,6 +67,8 @@ Changelog - Allow returning vector source estimates from sparse inverse solvers through ``pick_ori='vector'`` by `Christian Brodbeck`_ +- Add NIRS support to :func:`mne.viz.plot_topomap` by `Robert Luke`_ + Bug ~~~ diff --git a/mne/channels/channels.py b/mne/channels/channels.py index fb2eda06457..22f1130188d 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -73,7 +73,8 @@ def _get_ch_type(inst, ch_type, allow_ref_meg=False): then grads, then ... to plot. """ if ch_type is None: - allowed_types = ['mag', 'grad', 'planar1', 'planar2', 'eeg', 'csd'] + allowed_types = ['mag', 'grad', 'planar1', 'planar2', 'eeg', 'csd', + 'hbo', 'hbr'] allowed_types += ['ref_meg'] if allow_ref_meg else [] for type_ in allowed_types: if isinstance(inst, Info): diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index f1d95a288f4..f4d34f2ee6a 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -67,6 +67,9 @@ def _prepare_topo_plot(inst, ch_type, layout): elif ch_type == 'csd': picks = pick_types(info, meg=False, csd=True, ref_meg=False, exclude='bads') + elif ch_type in ['hbo', 'hbr']: + picks = pick_types(info, meg=False, csd=True, ref_meg=False, + fnirs=True, exclude='bads') else: picks = pick_types(info, meg=ch_type, ref_meg=False, exclude='bads') From 69158a59fb2068f6d234ddc0b8329b189af81e4c Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Fri, 15 Nov 2019 10:17:46 +1100 Subject: [PATCH 02/15] Add plot_topomap to NIRS tutorial --- .../preprocessing/plot_70_fnirs_processing.py | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tutorials/preprocessing/plot_70_fnirs_processing.py b/tutorials/preprocessing/plot_70_fnirs_processing.py index 23a83b75fa8..69aa2fa621d 100644 --- a/tutorials/preprocessing/plot_70_fnirs_processing.py +++ b/tutorials/preprocessing/plot_70_fnirs_processing.py @@ -17,6 +17,7 @@ # sphinx_gallery_thumbnail_number = 3 import os +import numpy as np import matplotlib.pyplot as plt import mne @@ -162,7 +163,7 @@ # Plot standard fNIRS response image # ---------------------------------- # -# Finally we generate the most common visualisation of fNIRS data, plotting +# Next we generate the most common visualisation of fNIRS data, plotting # both the HbO and HbR on the same figure to illustrate the relation between # the two signals. @@ -180,3 +181,31 @@ mne.viz.plot_compare_evokeds(evoked_dict, combine="mean", ci=0.95, colors=color_dict, styles=styles_dict) + + +############################################################################### +# View topographic representation of activity +# ------------------------------------------- +# +# Next we view how the topographic activity changes throughout the response. + +times = np.arange(-3.5, 13.2, 3.0) +epochs['Tapping'].average(picks='hbo').plot_joint(times=times) + + +############################################################################### +# Compare tapping of left and right hands +# --------------------------------------- +# +# Finally we generate topo maps for the left and right conditions to view +# the location of activity. First we visualise the HbO activity. + +times = np.arange(4.0, 11.0, 1.0) +epochs['Tapping/Left'].average(picks='hbo').plot_topomap(times=times) +epochs['Tapping/Right'].average(picks='hbo').plot_topomap(times=times) + +############################################################################### +# And we also view the HbR activity for the two conditions. + +epochs['Tapping/Left'].average(picks='hbr').plot_topomap(times=times) +epochs['Tapping/Right'].average(picks='hbr').plot_topomap(times=times) \ No newline at end of file From b382e8ab686b6d0a61a2fd612d8a5f825b48e6a7 Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Fri, 15 Nov 2019 10:30:35 +1100 Subject: [PATCH 03/15] Add newline to tutorial --- tutorials/preprocessing/plot_70_fnirs_processing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/preprocessing/plot_70_fnirs_processing.py b/tutorials/preprocessing/plot_70_fnirs_processing.py index 69aa2fa621d..e123b75c45e 100644 --- a/tutorials/preprocessing/plot_70_fnirs_processing.py +++ b/tutorials/preprocessing/plot_70_fnirs_processing.py @@ -208,4 +208,4 @@ # And we also view the HbR activity for the two conditions. epochs['Tapping/Left'].average(picks='hbr').plot_topomap(times=times) -epochs['Tapping/Right'].average(picks='hbr').plot_topomap(times=times) \ No newline at end of file +epochs['Tapping/Right'].average(picks='hbr').plot_topomap(times=times) From b71f10c0113e1c6d55b9ba1c9ac73588e3186e34 Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Fri, 15 Nov 2019 14:09:35 +1100 Subject: [PATCH 04/15] Do not modify nirs channel names --- mne/viz/topomap.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index f4d34f2ee6a..1a8eddef408 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -41,8 +41,11 @@ def _prepare_topo_plot(inst, ch_type, layout): layout = find_layout(info) # XXX : why not passing ch_type??? elif layout == 'auto': layout = None - - clean_ch_names = _clean_names(info['ch_names']) + if ch_type in ['hbo', 'hbr']: + # The naming for nirs is very specific and should not be modified + clean_ch_names = info['ch_names'] + else: + clean_ch_names = _clean_names(info['ch_names']) for ii, this_ch in enumerate(info['chs']): this_ch['ch_name'] = clean_ch_names[ii] info['bads'] = _clean_names(info['bads']) @@ -1640,7 +1643,6 @@ def plot_evoked_topomap(evoked, times="auto", ch_type=None, layout=None, mask_params = _handle_default('mask_params', mask_params) mask_params['markersize'] *= size / 2. mask_params['markeredgewidth'] *= size / 2. - picks, pos, merge_grads, names, ch_type = _prepare_topo_plot( evoked, ch_type, layout) From 6d6322ab0d4635a2eda068d9bfe060ce222abfeb Mon Sep 17 00:00:00 2001 From: Robert Luke <748691+rob-luke@users.noreply.github.com> Date: Sat, 16 Nov 2019 08:12:34 +1100 Subject: [PATCH 05/15] Update mne/viz/topomap.py Co-Authored-By: Eric Larson --- mne/viz/topomap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 1a8eddef408..a09d1df8f7c 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -71,7 +71,7 @@ def _prepare_topo_plot(inst, ch_type, layout): picks = pick_types(info, meg=False, csd=True, ref_meg=False, exclude='bads') elif ch_type in ['hbo', 'hbr']: - picks = pick_types(info, meg=False, csd=True, ref_meg=False, + picks = pick_types(info, meg=False, ref_meg=False, fnirs=True, exclude='bads') else: picks = pick_types(info, meg=ch_type, ref_meg=False, From 0c4421c2671020c886e0558fbd12f756303e7647 Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Sat, 16 Nov 2019 13:30:09 +1100 Subject: [PATCH 06/15] Add another example to nirs tutorial --- .../preprocessing/plot_70_fnirs_processing.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tutorials/preprocessing/plot_70_fnirs_processing.py b/tutorials/preprocessing/plot_70_fnirs_processing.py index e123b75c45e..1a23057181b 100644 --- a/tutorials/preprocessing/plot_70_fnirs_processing.py +++ b/tutorials/preprocessing/plot_70_fnirs_processing.py @@ -209,3 +209,25 @@ epochs['Tapping/Left'].average(picks='hbr').plot_topomap(times=times) epochs['Tapping/Right'].average(picks='hbr').plot_topomap(times=times) + +############################################################################### +# And we can plot the comparison at a single time point for two conditions. + +fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(8, 5)) +vmin, vmax, ts = -12, 12, 8.0 +epochs['Tapping/Left'].average(picks='hbo').\ + plot_topomap(ch_type='hbo', times=ts, axes=axes[0, 0], + vmin=vmin, vmax=vmax, colorbar=False) +epochs['Tapping/Left'].average(picks='hbr').\ + plot_topomap(ch_type='hbr', times=ts, axes=axes[1, 0], + vmin=vmin, vmax=vmax, colorbar=False) +epochs['Tapping/Right'].average(picks='hbo').\ + plot_topomap(ch_type='hbo', times=ts, axes=axes[0, 1], + vmin=vmin, vmax=vmax, colorbar=False) +epochs['Tapping/Right'].average(picks='hbr').\ + plot_topomap(ch_type='hbr', times=ts, + axes=axes[1, 1], vmin=vmin, vmax=vmax, colorbar=True) +for column, condition in enumerate(['Tapping Left', 'Tapping Right']): + axes[0, column].set_title('{}: {}'.format(condition, + axes[0, column].get_title())) + axes[1, column].set_title('') From 8590af8f25a3485a772f4610fe944831bb9499d7 Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Sat, 16 Nov 2019 14:02:04 +1100 Subject: [PATCH 07/15] Add fnirs_raw and fnirs_od to topomap --- mne/channels/channels.py | 2 +- mne/viz/topomap.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mne/channels/channels.py b/mne/channels/channels.py index 22f1130188d..de65a6624b5 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -74,7 +74,7 @@ def _get_ch_type(inst, ch_type, allow_ref_meg=False): """ if ch_type is None: allowed_types = ['mag', 'grad', 'planar1', 'planar2', 'eeg', 'csd', - 'hbo', 'hbr'] + 'fnirs_raw', 'fnirs_od', 'hbo', 'hbr'] allowed_types += ['ref_meg'] if allow_ref_meg else [] for type_ in allowed_types: if isinstance(inst, Info): diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index a09d1df8f7c..71ee184a0ee 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -41,7 +41,7 @@ def _prepare_topo_plot(inst, ch_type, layout): layout = find_layout(info) # XXX : why not passing ch_type??? elif layout == 'auto': layout = None - if ch_type in ['hbo', 'hbr']: + if ch_type in ['hbo', 'hbr', 'fnirs_raw', 'fnirs_od']: # The naming for nirs is very specific and should not be modified clean_ch_names = info['ch_names'] else: @@ -70,7 +70,7 @@ def _prepare_topo_plot(inst, ch_type, layout): elif ch_type == 'csd': picks = pick_types(info, meg=False, csd=True, ref_meg=False, exclude='bads') - elif ch_type in ['hbo', 'hbr']: + elif ch_type in ['hbo', 'hbr', 'fnirs_raw', 'fnirs_od']: picks = pick_types(info, meg=False, ref_meg=False, fnirs=True, exclude='bads') else: From bdf2916e27e2af60e768cd6a8bd7a721c5b190c3 Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Sun, 17 Nov 2019 10:33:59 +1100 Subject: [PATCH 08/15] Change nirs channel naming. Instead of modifying clean_names --- mne/io/nirx/nirx.py | 2 +- mne/io/nirx/tests/test_nirx.py | 22 ++++++++++----------- mne/preprocessing/nirs/_beer_lambert_law.py | 6 +++--- mne/viz/topomap.py | 6 +----- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/mne/io/nirx/nirx.py b/mne/io/nirx/nirx.py index 6e812c92529..172e1cad72c 100644 --- a/mne/io/nirx/nirx.py +++ b/mne/io/nirx/nirx.py @@ -198,7 +198,7 @@ def prepend(list, str): list = [str.format(i) for i in list] return(list) snames = prepend(sources[req_ind], 'S') - dnames = prepend(detectors[req_ind], '-D') + dnames = prepend(detectors[req_ind], '_D') sdnames = [m + str(n) for m, n in zip(snames, dnames)] sd1 = [s + ' ' + str(fnirs_wavelengths[0]) for s in sdnames] sd2 = [s + ' ' + str(fnirs_wavelengths[1]) for s in sdnames] diff --git a/mne/io/nirx/tests/test_nirx.py b/mne/io/nirx/tests/test_nirx.py index 4267fdb8f41..2a23ada7c0c 100644 --- a/mne/io/nirx/tests/test_nirx.py +++ b/mne/io/nirx/tests/test_nirx.py @@ -34,9 +34,9 @@ def test_nirx_15_2_short(): assert raw.info['sfreq'] == 12.5 # Test channel naming - assert raw.info['ch_names'][:4] == ["S1-D1 760", "S1-D1 850", - "S1-D9 760", "S1-D9 850"] - assert raw.info['ch_names'][24:26] == ["S5-D13 760", "S5-D13 850"] + assert raw.info['ch_names'][:4] == ["S1_D1 760", "S1_D1 850", + "S1_D9 760", "S1_D9 850"] + assert raw.info['ch_names'][24:26] == ["S5_D13 760", "S5_D13 850"] # Test info import assert raw.info['subject_info'] == dict(sex=1, first_name="MNE", @@ -119,8 +119,8 @@ def test_nirx_15_2(): assert raw.info['sfreq'] == 3.90625 # Test channel naming - assert raw.info['ch_names'][:4] == ["S1-D1 760", "S1-D1 850", - "S1-D10 760", "S1-D10 850"] + assert raw.info['ch_names'][:4] == ["S1_D1 760", "S1_D1 850", + "S1_D10 760", "S1_D10 850"] # Test info import assert raw.info['subject_info'] == dict(sex=1, first_name="TestRecording") @@ -153,12 +153,12 @@ def test_nirx_15_0(): assert raw.info['sfreq'] == 6.25 # Test channel naming - assert raw.info['ch_names'][:12] == ["S1-D1 760", "S1-D1 850", - "S2-D2 760", "S2-D2 850", - "S3-D3 760", "S3-D3 850", - "S4-D4 760", "S4-D4 850", - "S5-D5 760", "S5-D5 850", - "S6-D6 760", "S6-D6 850"] + assert raw.info['ch_names'][:12] == ["S1_D1 760", "S1_D1 850", + "S2_D2 760", "S2_D2 850", + "S3_D3 760", "S3_D3 850", + "S4_D4 760", "S4_D4 850", + "S5_D5 760", "S5_D5 850", + "S6_D6 760", "S6_D6 850"] # Test info import assert raw.info['subject_info'] == {'first_name': 'NIRX', diff --git a/mne/preprocessing/nirs/_beer_lambert_law.py b/mne/preprocessing/nirs/_beer_lambert_law.py index 8a3b59269a9..cd6413904d0 100644 --- a/mne/preprocessing/nirs/_beer_lambert_law.py +++ b/mne/preprocessing/nirs/_beer_lambert_law.py @@ -64,7 +64,7 @@ def _channel_frequencies(raw): picks = _picks_to_idx(raw.info, 'fnirs_od') freqs = np.empty(picks.size, int) for ii in picks: - ch_name_info = re.match(r'S(\d+)-D(\d+) (\d+)', + ch_name_info = re.match(r'S(\d+)_D(\d+) (\d+)', raw.info['chs'][ii]['ch_name']) freqs[ii] = ch_name_info.groups()[2] return freqs @@ -76,9 +76,9 @@ def _check_channels_ordered(raw, freqs): # and have the specified light frequencies. picks = _picks_to_idx(raw.info, 'fnirs_od') for ii in picks[::2]: - ch1_name_info = re.match(r'S(\d+)-D(\d+) (\d+)', + ch1_name_info = re.match(r'S(\d+)_D(\d+) (\d+)', raw.info['chs'][ii]['ch_name']) - ch2_name_info = re.match(r'S(\d+)-D(\d+) (\d+)', + ch2_name_info = re.match(r'S(\d+)_D(\d+) (\d+)', raw.info['chs'][ii + 1]['ch_name']) if (ch1_name_info.groups()[0] != ch2_name_info.groups()[0]) or \ diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 71ee184a0ee..b3165c915dc 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -41,11 +41,7 @@ def _prepare_topo_plot(inst, ch_type, layout): layout = find_layout(info) # XXX : why not passing ch_type??? elif layout == 'auto': layout = None - if ch_type in ['hbo', 'hbr', 'fnirs_raw', 'fnirs_od']: - # The naming for nirs is very specific and should not be modified - clean_ch_names = info['ch_names'] - else: - clean_ch_names = _clean_names(info['ch_names']) + clean_ch_names = _clean_names(info['ch_names']) for ii, this_ch in enumerate(info['chs']): this_ch['ch_name'] = clean_ch_names[ii] info['bads'] = _clean_names(info['bads']) From 7174e662ee6f60beee17ce2930a485609c01db72 Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Sun, 17 Nov 2019 11:59:35 +1100 Subject: [PATCH 09/15] Fix new nirs name in beerlambert test --- mne/preprocessing/tests/test_beer_lambert_law.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/preprocessing/tests/test_beer_lambert_law.py b/mne/preprocessing/tests/test_beer_lambert_law.py index c0c2ca9a401..1b7643862e0 100644 --- a/mne/preprocessing/tests/test_beer_lambert_law.py +++ b/mne/preprocessing/tests/test_beer_lambert_law.py @@ -68,6 +68,6 @@ def test_beer_lambert_v_matlab(): raw._data[idx]) assert mean_error < 0.1 matlab_name = ("S" + str(int(matlab_data['sources'][idx])) + - "-D" + str(int(matlab_data['detectors'][idx])) + + "_D" + str(int(matlab_data['detectors'][idx])) + " " + matlab_data['type'][idx]) assert raw.info['ch_names'][idx] == matlab_name From f75d74e38f6e5e06060b8713b5ae7fa3912a9514 Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Sun, 17 Nov 2019 12:14:25 +1100 Subject: [PATCH 10/15] Add combine evoked to tutorial --- .../preprocessing/plot_70_fnirs_processing.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tutorials/preprocessing/plot_70_fnirs_processing.py b/tutorials/preprocessing/plot_70_fnirs_processing.py index 1a23057181b..25b97f71227 100644 --- a/tutorials/preprocessing/plot_70_fnirs_processing.py +++ b/tutorials/preprocessing/plot_70_fnirs_processing.py @@ -231,3 +231,53 @@ axes[0, column].set_title('{}: {}'.format(condition, axes[0, column].get_title())) axes[1, column].set_title('') + +fig, axes = plt.subplots(nrows=2, ncols=4, figsize=(9, 5)) +vmin, vmax, ts = -8, 8, 9.0 +epochs['Tapping/Left'].average(picks='hbo').plot_topomap(ch_type='hbo', + times=ts, + axes=axes[0, 0], + vmin=vmin, + vmax=vmax, + colorbar=False) +epochs['Tapping/Left'].average(picks='hbr').plot_topomap(ch_type='hbr', + times=ts, + axes=axes[1, 0], + vmin=vmin, + vmax=vmax, + colorbar=False) +epochs['Tapping/Right'].average(picks='hbo').plot_topomap(ch_type='hbo', + times=ts, + axes=axes[0, 1], + vmin=vmin, + vmax=vmax, + colorbar=False) +epochs['Tapping/Right'].average(picks='hbr').plot_topomap(ch_type='hbr', + times=ts, + axes=axes[1, 1], + vmin=vmin, + vmax=vmax, + colorbar=False) + +left, right = epochs["Tapping/Left"].average(picks='hbo'), epochs[ + "Tapping/Right"].average(picks='hbo') +mne.combine_evoked([left, -right], weights='equal').plot_topomap(ch_type='hbo', + times=ts, + axes=axes[ + 0, 2], + vmin=vmin, + vmax=vmax) +left, right = epochs["Tapping/Left"].average(picks='hbr'), epochs[ + "Tapping/Right"].average(picks='hbr') +mne.combine_evoked([left, -right], weights='equal').plot_topomap(ch_type='hbr', + times=ts, + axes=axes[ + 1, 2], + vmin=vmin, + vmax=vmax, + colorbar=True) + +for column, condition in enumerate( + ['Tapping Left', 'Tapping Right', 'Left-Right']): + for row, chroma in enumerate(['HbO', 'HbR']): + axes[row, column].set_title('{}: {}'.format(chroma, condition)) From add05f314f094f42368dd8010441ed363d76d410 Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Sun, 17 Nov 2019 12:32:27 +1100 Subject: [PATCH 11/15] Remove repeated code in nirs tutorial --- .../preprocessing/plot_70_fnirs_processing.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/tutorials/preprocessing/plot_70_fnirs_processing.py b/tutorials/preprocessing/plot_70_fnirs_processing.py index 25b97f71227..9e20f31b6cc 100644 --- a/tutorials/preprocessing/plot_70_fnirs_processing.py +++ b/tutorials/preprocessing/plot_70_fnirs_processing.py @@ -213,25 +213,6 @@ ############################################################################### # And we can plot the comparison at a single time point for two conditions. -fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(8, 5)) -vmin, vmax, ts = -12, 12, 8.0 -epochs['Tapping/Left'].average(picks='hbo').\ - plot_topomap(ch_type='hbo', times=ts, axes=axes[0, 0], - vmin=vmin, vmax=vmax, colorbar=False) -epochs['Tapping/Left'].average(picks='hbr').\ - plot_topomap(ch_type='hbr', times=ts, axes=axes[1, 0], - vmin=vmin, vmax=vmax, colorbar=False) -epochs['Tapping/Right'].average(picks='hbo').\ - plot_topomap(ch_type='hbo', times=ts, axes=axes[0, 1], - vmin=vmin, vmax=vmax, colorbar=False) -epochs['Tapping/Right'].average(picks='hbr').\ - plot_topomap(ch_type='hbr', times=ts, - axes=axes[1, 1], vmin=vmin, vmax=vmax, colorbar=True) -for column, condition in enumerate(['Tapping Left', 'Tapping Right']): - axes[0, column].set_title('{}: {}'.format(condition, - axes[0, column].get_title())) - axes[1, column].set_title('') - fig, axes = plt.subplots(nrows=2, ncols=4, figsize=(9, 5)) vmin, vmax, ts = -8, 8, 9.0 epochs['Tapping/Left'].average(picks='hbo').plot_topomap(ch_type='hbo', From a9e7a4d3df5d3920c1250b0e8ac5179ceb2558df Mon Sep 17 00:00:00 2001 From: Robert Luke <748691+rob-luke@users.noreply.github.com> Date: Sun, 17 Nov 2019 17:48:40 +1100 Subject: [PATCH 12/15] Add back removed whitespace --- mne/viz/topomap.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index b3165c915dc..11f15bf23e3 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -42,6 +42,7 @@ def _prepare_topo_plot(inst, ch_type, layout): elif layout == 'auto': layout = None clean_ch_names = _clean_names(info['ch_names']) + for ii, this_ch in enumerate(info['chs']): this_ch['ch_name'] = clean_ch_names[ii] info['bads'] = _clean_names(info['bads']) @@ -1639,6 +1640,7 @@ def plot_evoked_topomap(evoked, times="auto", ch_type=None, layout=None, mask_params = _handle_default('mask_params', mask_params) mask_params['markersize'] *= size / 2. mask_params['markeredgewidth'] *= size / 2. + picks, pos, merge_grads, names, ch_type = _prepare_topo_plot( evoked, ch_type, layout) From 5f0ebce62723e76967ad1a0836a63ca4f0666dd9 Mon Sep 17 00:00:00 2001 From: Robert Luke <748691+rob-luke@users.noreply.github.com> Date: Sun, 17 Nov 2019 17:49:41 +1100 Subject: [PATCH 13/15] Fix whitespace error --- mne/viz/topomap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 11f15bf23e3..c4f35ead643 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -41,8 +41,8 @@ def _prepare_topo_plot(inst, ch_type, layout): layout = find_layout(info) # XXX : why not passing ch_type??? elif layout == 'auto': layout = None - clean_ch_names = _clean_names(info['ch_names']) + clean_ch_names = _clean_names(info['ch_names']) for ii, this_ch in enumerate(info['chs']): this_ch['ch_name'] = clean_ch_names[ii] info['bads'] = _clean_names(info['bads']) From 509f30d172c4af4ec9eb72d02524f3d80b0139e5 Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Mon, 18 Nov 2019 06:22:44 +1100 Subject: [PATCH 14/15] Extract only choma of choice in ch_type --- mne/viz/topomap.py | 2 +- .../preprocessing/plot_70_fnirs_processing.py | 61 ++++++------------- 2 files changed, 20 insertions(+), 43 deletions(-) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index c4f35ead643..2158ff015bb 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -69,7 +69,7 @@ def _prepare_topo_plot(inst, ch_type, layout): exclude='bads') elif ch_type in ['hbo', 'hbr', 'fnirs_raw', 'fnirs_od']: picks = pick_types(info, meg=False, ref_meg=False, - fnirs=True, exclude='bads') + fnirs=ch_type, exclude='bads') else: picks = pick_types(info, meg=ch_type, ref_meg=False, exclude='bads') diff --git a/tutorials/preprocessing/plot_70_fnirs_processing.py b/tutorials/preprocessing/plot_70_fnirs_processing.py index 9e20f31b6cc..710d8a2b3d5 100644 --- a/tutorials/preprocessing/plot_70_fnirs_processing.py +++ b/tutorials/preprocessing/plot_70_fnirs_processing.py @@ -215,48 +215,25 @@ fig, axes = plt.subplots(nrows=2, ncols=4, figsize=(9, 5)) vmin, vmax, ts = -8, 8, 9.0 -epochs['Tapping/Left'].average(picks='hbo').plot_topomap(ch_type='hbo', - times=ts, - axes=axes[0, 0], - vmin=vmin, - vmax=vmax, - colorbar=False) -epochs['Tapping/Left'].average(picks='hbr').plot_topomap(ch_type='hbr', - times=ts, - axes=axes[1, 0], - vmin=vmin, - vmax=vmax, - colorbar=False) -epochs['Tapping/Right'].average(picks='hbo').plot_topomap(ch_type='hbo', - times=ts, - axes=axes[0, 1], - vmin=vmin, - vmax=vmax, - colorbar=False) -epochs['Tapping/Right'].average(picks='hbr').plot_topomap(ch_type='hbr', - times=ts, - axes=axes[1, 1], - vmin=vmin, - vmax=vmax, - colorbar=False) - -left, right = epochs["Tapping/Left"].average(picks='hbo'), epochs[ - "Tapping/Right"].average(picks='hbo') -mne.combine_evoked([left, -right], weights='equal').plot_topomap(ch_type='hbo', - times=ts, - axes=axes[ - 0, 2], - vmin=vmin, - vmax=vmax) -left, right = epochs["Tapping/Left"].average(picks='hbr'), epochs[ - "Tapping/Right"].average(picks='hbr') -mne.combine_evoked([left, -right], weights='equal').plot_topomap(ch_type='hbr', - times=ts, - axes=axes[ - 1, 2], - vmin=vmin, - vmax=vmax, - colorbar=True) + +evoked_left = epochs['Tapping/Left'].average() +evoked_right = epochs['Tapping/Right'].average() + +evoked_left.plot_topomap(ch_type='hbo', times=ts, axes=axes[0, 0], + vmin=vmin, vmax=vmax, colorbar=False) +evoked_left.plot_topomap(ch_type='hbr', times=ts, axes=axes[1, 0], + vmin=vmin, vmax=vmax, colorbar=False) +evoked_right.plot_topomap(ch_type='hbo', times=ts, axes=axes[0, 1], + vmin=vmin, vmax=vmax, colorbar=False) +evoked_right.plot_topomap(ch_type='hbr', times=ts, axes=axes[1, 1], + vmin=vmin, vmax=vmax, colorbar=False) + +mne.combine_evoked([evoked_left, -evoked_right], weights='equal').\ + plot_topomap(ch_type='hbo', times=ts, axes=axes[0, 2], + vmin=vmin, vmax=vmax) +mne.combine_evoked([evoked_left, -evoked_right], weights='equal').\ + plot_topomap(ch_type='hbr', times=ts, axes=axes[1, 2], + vmin=vmin, vmax=vmax, colorbar=True) for column, condition in enumerate( ['Tapping Left', 'Tapping Right', 'Left-Right']): From 2d1da2c5df8b0b01a6f5fd28b2b32001f99f0501 Mon Sep 17 00:00:00 2001 From: Robert Luke Date: Mon, 18 Nov 2019 06:40:18 +1100 Subject: [PATCH 15/15] Reuse evoked objects to save memory --- tutorials/preprocessing/plot_70_fnirs_processing.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tutorials/preprocessing/plot_70_fnirs_processing.py b/tutorials/preprocessing/plot_70_fnirs_processing.py index 710d8a2b3d5..296b303358c 100644 --- a/tutorials/preprocessing/plot_70_fnirs_processing.py +++ b/tutorials/preprocessing/plot_70_fnirs_processing.py @@ -228,12 +228,12 @@ evoked_right.plot_topomap(ch_type='hbr', times=ts, axes=axes[1, 1], vmin=vmin, vmax=vmax, colorbar=False) -mne.combine_evoked([evoked_left, -evoked_right], weights='equal').\ - plot_topomap(ch_type='hbo', times=ts, axes=axes[0, 2], - vmin=vmin, vmax=vmax) -mne.combine_evoked([evoked_left, -evoked_right], weights='equal').\ - plot_topomap(ch_type='hbr', times=ts, axes=axes[1, 2], - vmin=vmin, vmax=vmax, colorbar=True) +evoked_diff = mne.combine_evoked([evoked_left, -evoked_right], weights='equal') + +evoked_diff.plot_topomap(ch_type='hbo', times=ts, axes=axes[0, 2], + vmin=vmin, vmax=vmax) +evoked_diff.plot_topomap(ch_type='hbr', times=ts, axes=axes[1, 2], + vmin=vmin, vmax=vmax, colorbar=True) for column, condition in enumerate( ['Tapping Left', 'Tapping Right', 'Left-Right']):