Skip to content

Commit

Permalink
Handle cases with no fnirs picks for interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-luke committed Apr 4, 2020
1 parent 90fd7fc commit ad33da5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions mne/channels/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions mne/preprocessing/nirs/nirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 '
Expand Down

0 comments on commit ad33da5

Please sign in to comment.