From ad33da5934ef264618aec71feab5f94751218d8b Mon Sep 17 00:00:00 2001 From: Robert Luke <748691+rob-luke@users.noreply.github.com> Date: Sat, 4 Apr 2020 17:05:47 +1100 Subject: [PATCH] Handle cases with no fnirs picks for interpolation --- mne/channels/interpolation.py | 7 +++++-- mne/preprocessing/nirs/nirs.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mne/channels/interpolation.py b/mne/channels/interpolation.py index af6b0e0f413..0c6ea3e1234 100644 --- a/mne/channels/interpolation.py +++ b/mne/channels/interpolation.py @@ -233,13 +233,16 @@ def _interpolate_bads_nirs(inst, method='nearest', verbose=None): from mne.preprocessing.nirs import _channel_frequencies,\ _check_channels_ordered - freqs = np.unique(_channel_frequencies(inst)) # Returns pick of all nirs and ensures channels are correctly ordered + freqs = np.unique(_channel_frequencies(inst)) picks_nirs = _check_channels_ordered(inst, freqs) + if len(picks_nirs) == 0: + return + nirs_ch_names = [inst.info['ch_names'][p] for p in picks_nirs] bads_nirs = [ch for ch in inst.info['bads'] if ch in nirs_ch_names] - # select the bad meg channel to be interpolated + # select the bad nirs channel to be interpolated if len(bads_nirs) == 0: picks_bad = [] else: diff --git a/mne/preprocessing/nirs/nirs.py b/mne/preprocessing/nirs/nirs.py index bb82eecdb59..682c1edc5bb 100644 --- a/mne/preprocessing/nirs/nirs.py +++ b/mne/preprocessing/nirs/nirs.py @@ -58,7 +58,7 @@ def short_channels(info, threshold=0.01): def _channel_frequencies(raw): """Return the light frequency for each channel.""" - picks = _picks_to_idx(raw.info, 'fnirs', exclude=[]) + picks = _picks_to_idx(raw.info, 'fnirs', exclude=[], allow_empty=True) freqs = np.empty(picks.size, int) for ii in picks: freqs[ii] = raw.info['chs'][ii]['loc'][9] @@ -69,7 +69,7 @@ def _check_channels_ordered(raw, freqs): """Check channels followed expected fNIRS format.""" # Every second channel should be same SD pair # and have the specified light frequencies. - picks = _picks_to_idx(raw.info, 'fnirs', exclude=[]) + picks = _picks_to_idx(raw.info, 'fnirs', exclude=[], allow_empty=True) if len(picks) % 2 != 0: raise ValueError( 'NIRS channels not ordered correctly. An even number of NIRS '