From f2a834426ae10dde3001982e2f70efffd562a52b Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Fri, 26 Feb 2016 15:44:29 +0100 Subject: [PATCH 1/2] ENH : better error message when unit is not known --- mne/channels/channels.py | 4 ++++ mne/channels/tests/test_channels.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/mne/channels/channels.py b/mne/channels/channels.py index 2a772e77491..b7012eb5933 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -286,6 +286,10 @@ def set_channel_types(self, mapping): _check_set(self.info['chs'][c_ind], self.info['projs'], ch_type) unit_old = self.info['chs'][c_ind]['unit'] unit_new = _human2unit[ch_type] + if unit_old not in _unit2human: + raise ValueError("Channel '%s' has unknown unit (%s). Please fix" + " the measurement info of your data." + % (ch_name, unit_old)) if unit_old != _human2unit[ch_type]: warn("The unit for channel %s has changed from %s to %s." % (ch_name, _unit2human[unit_old], _unit2human[unit_new])) diff --git a/mne/channels/tests/test_channels.py b/mne/channels/tests/test_channels.py index 32649951deb..660d15204da 100644 --- a/mne/channels/tests/test_channels.py +++ b/mne/channels/tests/test_channels.py @@ -106,6 +106,11 @@ def test_set_channel_types(): assert_true(info['chs'][idx]['unit'] == FIFF.FIFF_UNIT_V) assert_true(info['chs'][idx]['coil_type'] == FIFF.FIFFV_COIL_EEG) + # Test meaningful error when setting channel type with unknown unit + raw.info['chs'][0]['unit'] = 0. + ch_types = {raw.ch_names[0]: 'misc'} + assert_raises(ValueError, raw.set_channel_types, ch_types) + def test_read_ch_connectivity(): "Test reading channel connectivity templates" From 201117df8960fa0e6b7ded8d552d6dca0d1276be Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 26 Feb 2016 10:50:53 -0500 Subject: [PATCH 2/2] FIX: PEP8 --- mne/channels/channels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mne/channels/channels.py b/mne/channels/channels.py index b7012eb5933..aec1891d5b6 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -287,8 +287,8 @@ def set_channel_types(self, mapping): unit_old = self.info['chs'][c_ind]['unit'] unit_new = _human2unit[ch_type] if unit_old not in _unit2human: - raise ValueError("Channel '%s' has unknown unit (%s). Please fix" - " the measurement info of your data." + raise ValueError("Channel '%s' has unknown unit (%s). Please " + "fix the measurement info of your data." % (ch_name, unit_old)) if unit_old != _human2unit[ch_type]: warn("The unit for channel %s has changed from %s to %s."