From 428c9070bac335a3b28d583d5384a39d41134253 Mon Sep 17 00:00:00 2001 From: Robert Luke <748691+rob-luke@users.noreply.github.com> Date: Fri, 3 Apr 2020 17:42:52 +1100 Subject: [PATCH] Change nirs interpolation method to nearest --- mne/channels/interpolation.py | 38 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/mne/channels/interpolation.py b/mne/channels/interpolation.py index 5a61e6ac874..03a278a76ed 100644 --- a/mne/channels/interpolation.py +++ b/mne/channels/interpolation.py @@ -216,7 +216,7 @@ 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 @@ -224,8 +224,8 @@ def _interpolate_bads_nirs(inst, method='closest', verbose=None): 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 @@ -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