From d9d6531687a666c83604cf27b6fd913725c5f25b Mon Sep 17 00:00:00 2001 From: Robert Luke <748691+rob-luke@users.noreply.github.com> Date: Tue, 24 Mar 2020 10:15:02 +1100 Subject: [PATCH] Add test that NIRS naming matches stored frequency --- mne/preprocessing/nirs/nirs.py | 12 ++++++++++++ mne/preprocessing/tests/test_beer_lambert_law.py | 10 ++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/mne/preprocessing/nirs/nirs.py b/mne/preprocessing/nirs/nirs.py index cddd60d15a6..bb82eecdb59 100644 --- a/mne/preprocessing/nirs/nirs.py +++ b/mne/preprocessing/nirs/nirs.py @@ -81,6 +81,18 @@ def _check_channels_ordered(raw, freqs): ch2_name_info = re.match(r'S(\d+)_D(\d+) (\d+)', raw.info['chs'][ii + 1]['ch_name']) + if raw.info['chs'][ii]['loc'][9] != \ + float(ch1_name_info.groups()[2]) or \ + raw.info['chs'][ii + 1]['loc'][9] != \ + float(ch2_name_info.groups()[2]): + raise ValueError( + 'NIRS channels not ordered correctly. Channel name and NIRS' + ' frequency do not match: %s -> %s & %s -> %s' + % (raw.info['chs'][ii]['ch_name'], + raw.info['chs'][ii]['loc'][9], + raw.info['chs'][ii + 1]['ch_name'], + raw.info['chs'][ii + 1]['loc'][9])) + if (ch1_name_info.groups()[0] != ch2_name_info.groups()[0]) or \ (ch1_name_info.groups()[1] != ch2_name_info.groups()[1]) or \ (int(ch1_name_info.groups()[2]) != freqs[0]) or \ diff --git a/mne/preprocessing/tests/test_beer_lambert_law.py b/mne/preprocessing/tests/test_beer_lambert_law.py index 7740b52c8b7..1adf55008ee 100644 --- a/mne/preprocessing/tests/test_beer_lambert_law.py +++ b/mne/preprocessing/tests/test_beer_lambert_law.py @@ -59,10 +59,16 @@ def test_beer_lambert_unordered_errors(): with pytest.raises(ValueError, match='ordered'): beer_lambert_law(raw_od) - # Test that an error is thrown if inconsistent frequencies used in data + # Test that an error is thrown if channel naming frequency doesnt match + # what is stored in loc[9], which should hold the light frequency too. raw_od = optical_density(raw) raw_od.rename_channels({'S2_D2 760': 'S2_D2 770'}) - with pytest.raises(ValueError, match='ordered'): + with pytest.raises(ValueError, match='frequency do not match'): + beer_lambert_law(raw_od) + + # Test that an error is thrown if inconsistent frequencies used in data + raw_od.info['chs'][2]['loc'][9] = 770.0 + with pytest.raises(ValueError, match='pairs with frequencies'): beer_lambert_law(raw_od)