You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
raise error in interpolate_bads if no sensor positions are provided #13363
I'm adding some sensors that were missing during recording as empty channels to then interpolate them. However, the resulting channel is interpolated as nan, probably because I did not supply positions to the new channel.
I only found out about that by accident. I think there should be a warning if interpolation of a channel is attempted and fails, and/or if some sensors don't have positions while interpolating
Steps to reproduce
raw=mne.io.read_raw('file.fif', preload=True)
empty_ch=np.zeros_like(raw.get_data('MEG1633'))
info=mne.create_info(ch_names=['MEG2112'], sfreq=raw.info['sfreq'], ch_types=['grad'])
raw_ch=mne.io.RawArray(data=empty_ch, info=info, first_samp=raw.first_samp)
raw.add_channels([raw_ch], force_update_info=True)
raw.info['bads'] += ['MEG2112']
raw.interpolate_bads()
# -> channel will be nan
Makes sense to me, at least in cases where method is something that actually uses the positions (which is true for MEG sensors by default, but wouldn't be for method="nan" for example). Would you be up for making a PR? I think it's likely we'll want a new kwarg on_no_position="warn" to control this behavior (using the internal _on_missing(...) to raise an error, emit a warning, or ignore the issue).
I'm working on a fix. Should I add warnings in the:
add_channels() logic, something like: Warning: Channel 'MEG2112' was added without valid sensor position (loc) information. Interpolation or spatial filtering will fail silently or raise an error unless position data is manually supplied.
Or
For interpolate_bads(): ValueError: Cannot interpolate channel 'MEG2112'. Sensor position information (raw.info['chs'][...]['loc']) is missing or invalid. Please supply 3D coordinates before proceeding.
Activity
larsoner commentedon Aug 8, 2025
Makes sense to me, at least in cases where
methodis something that actually uses the positions (which is true for MEG sensors by default, but wouldn't be formethod="nan"for example). Would you be up for making a PR? I think it's likely we'll want a new kwargon_no_position="warn"to control this behavior (using the internal_on_missing(...)to raise an error, emit a warning, or ignore the issue).1himan commentedon Dec 1, 2025
I'm working on a fix. Should I add warnings in the:
add_channels() logic, something like: Warning: Channel 'MEG2112' was added without valid sensor position (loc) information. Interpolation or spatial filtering will fail silently or raise an error unless position data is manually supplied.
Or
For interpolate_bads(): ValueError: Cannot interpolate channel 'MEG2112'. Sensor position information (raw.info['chs'][...]['loc']) is missing or invalid. Please supply 3D coordinates before proceeding.
or both?