apply_inverse_raw() calls _check_reference() even though no EEG channels are used
This bug report is based on this discussion in the MNE group.
I am trying to compute the inverse solution for continuous raw data. I am only interested in MEG channels so I set eeg to False during the computation of the inverse operator. However, apply_inverse_raw() still calls _check_reference().
Unfortunately, the flag custom_ref_applied was set to True for the HCP data (see discussion for details), which caused _check_reference() to raise an error despite me not even using EEG channels.
apply_inverse_raw() should either only call _check_reference() if EEG channels are being used or _check_reference() should check whether EEG channels are being used before raising an error. Personally, I think the second option is better since this seems relevant for other methods calling _check_reference() as well. A solution could look like this:
def _check_reference(inst, ch_names=None):
"""Check for EEG ref."""
info = inst.info
if ch_names is not None:
picks = [ci for ci, ch_name in enumerate(info['ch_names'])
if ch_name in ch_names]
info = pick_info(info, sel=picks)
if 'eeg' not in info.get_channel_types():
return
if _needs_eeg_average_ref_proj(info):
raise ValueError(
'EEG average reference (using a projector) is mandatory for '
'modeling, use the method set_eeg_reference(projection=True)')
if info.get('custom_ref_applied', False):
raise ValueError('Custom EEG reference is not allowed for inverse '
'modeling.')
Also as a side question, why does apply_inverse_epochs() not call _check_reference()?