Skip to content

Commit

Permalink
Add test that NIRS naming matches stored frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-luke committed Mar 23, 2020
1 parent b884155 commit d9d6531
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions mne/preprocessing/nirs/nirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
10 changes: 8 additions & 2 deletions mne/preprocessing/tests/test_beer_lambert_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit d9d6531

Please sign in to comment.