Skip to content

Commit

Permalink
Change nirs interpolation method to nearest
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-luke committed Apr 3, 2020
1 parent 4e9b0e1 commit 428c907
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions mne/channels/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,16 @@ def _interpolate_bads_meg(inst, mode='accurate', origin=(0., 0., 0.04),


@verbose
def _interpolate_bads_nirs(inst, method='closest', verbose=None):
def _interpolate_bads_nirs(inst, method='nearest', verbose=None):
"""Interpolate bad nirs channels. Simply replaces by closest non bad.
Parameters
----------
inst : mne.io.Raw, mne.Epochs or mne.Evoked
The data to interpolate. Must be preloaded.
method : str
Only the method 'closest' is currently available. This method replaces
each bad channel with the closest non bad channel.
Only the method 'nearest' is currently available. This method replaces
each bad channel with the nearest non bad channel.
%(verbose)s
"""
from scipy.spatial.distance import pdist, squareform
Expand All @@ -251,18 +251,24 @@ def _interpolate_bads_nirs(inst, method='closest', verbose=None):
dist = pdist(locs3d)
dist = squareform(dist)

for bad in picks_bad:
dists_to_bad = dist[bad]
# Ignore distances to self
dists_to_bad[dists_to_bad == 0] = np.inf
# Ignore distances to other bad channels
dists_to_bad[bads_mask] = np.inf
# Find closest remaining channels
closest_idx = np.where(dists_to_bad == np.amin(dists_to_bad))[0]
# Return the same frequency
closest_idx = closest_idx[bad % 2]
inst._data[bad] = inst._data[closest_idx]

inst.info['bads'] = []
if method is 'nearest':

for bad in picks_bad:
dists_to_bad = dist[bad]
# Ignore distances to self
dists_to_bad[dists_to_bad == 0] = np.inf
# Ignore distances to other bad channels
dists_to_bad[bads_mask] = np.inf
# Find closest remaining channels
closest_idx = np.where(dists_to_bad == np.amin(dists_to_bad))[0]
# Return the same frequency
closest_idx = closest_idx[bad % 2]
inst._data[bad] = inst._data[closest_idx]

inst.info['bads'] = []

else:
warn('No interpolation applied. Unknown NIRS interpolation '
'method: ' + method)

return inst

0 comments on commit 428c907

Please sign in to comment.