Skip to content

Commit

Permalink
MRG: Use new nirscout test data location (mne-tools#8122)
Browse files Browse the repository at this point in the history
* Use new nirscout test data location

* Add tests to viz

* Add support for nirstart 15.3

* Use latest testing data

* Update testing hash

* Update links to data creation
  • Loading branch information
rob-luke authored Aug 18, 2020
1 parent bfbdc83 commit 6d0b634
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 25 deletions.
2 changes: 1 addition & 1 deletion mne/channels/tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_interpolation_ctf_comp():
def test_interpolation_nirs():
"""Test interpolating bad nirs channels."""
fname = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording_w_overlap')
'NIRx', 'nirscout', 'nirx_15_2_recording_w_overlap')
raw_intensity = read_raw_nirx(fname, preload=False)
raw_od = optical_density(raw_intensity)
sci = scalp_coupling_index(raw_od)
Expand Down
4 changes: 2 additions & 2 deletions mne/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _data_path(path=None, force_update=False, update_path=True, download=True,
path = _get_path(path, key, name)
# To update the testing or misc dataset, push commits, then make a new
# release on GitHub. Then update the "releases" variable:
releases = dict(testing='0.100', misc='0.6')
releases = dict(testing='0.103', misc='0.6')
# And also update the "md5_hashes['testing']" variable below.

# To update any other dataset, update the data archive itself (upload
Expand Down Expand Up @@ -327,7 +327,7 @@ def _data_path(path=None, force_update=False, update_path=True, download=True,
sample='12b75d1cb7df9dfb4ad73ed82f61094f',
somato='ea825966c0a1e9b2f84e3826c5500161',
spm='9f43f67150e3b694b523a21eb929ea75',
testing='deb175669c3489c1fef582f72d3d6017',
testing='f7753da1b277d5ccf79da83b0854bcb7',
multimodal='26ec847ae9ab80f58f204d09e2c08367',
fnirs_motor='c4935d19ddab35422a69f3326a01fef8',
opm='370ad1dcfd5c47e029e692c85358a374',
Expand Down
5 changes: 2 additions & 3 deletions mne/io/nirx/nirx.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, fname, preload=False, verbose=None):
fname = op.dirname(op.abspath(fname))

if not op.isdir(fname):
raise RuntimeError('The path you specified does not exist.')
raise FileNotFoundError('The path you specified does not exist.')

# Check if required files exist and store names for later use
files = dict()
Expand Down Expand Up @@ -107,8 +107,7 @@ def __init__(self, fname, preload=False, verbose=None):
hdr.read_string(hdr_str)

# Check that the file format version is supported
if not any(item == hdr['GeneralInfo']['NIRStar'] for item in
["\"15.0\"", "\"15.2\""]):
if hdr['GeneralInfo']['NIRStar'] not in ['"15.0"', '"15.2"', '"15.3"']:
raise RuntimeError('MNE does not support this NIRStar version'
' (%s)' % (hdr['GeneralInfo']['NIRStar'],))
if "NIRScout" not in hdr['GeneralInfo']['Device']:
Expand Down
94 changes: 90 additions & 4 deletions mne/io/nirx/tests/test_nirx.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
from mne.io.constants import FIFF

fname_nirx_15_0 = op.join(data_path(download=False),
'NIRx', 'nirx_15_0_recording')
'NIRx', 'nirscout', 'nirx_15_0_recording')
fname_nirx_15_2 = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording')
'NIRx', 'nirscout', 'nirx_15_2_recording')
fname_nirx_15_2_short = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording_w_short')
'NIRx', 'nirscout',
'nirx_15_2_recording_w_short')
fname_nirx_15_3_short = op.join(data_path(download=False),
'NIRx', 'nirscout', 'nirx_15_3_recording')


@requires_testing_data
Expand All @@ -42,7 +45,7 @@ def test_nirx_hdr_load():
@requires_testing_data
def test_nirx_missing_warn():
"""Test reading NIRX files when missing data."""
with pytest.raises(RuntimeError, match='The path you'):
with pytest.raises(FileNotFoundError, match='The path you'):
read_raw_nirx(fname_nirx_15_2_short + "1", preload=True)


Expand Down Expand Up @@ -157,6 +160,89 @@ def test_nirx_15_2_short():
mni_locs[21], [0.0388, -0.0477, 0.0932], atol=allowed_dist_error)


@requires_testing_data
def test_nirx_15_3_short():
"""Test reading NIRX files."""
raw = read_raw_nirx(fname_nirx_15_3_short, preload=True)

# Test data import
assert raw._data.shape == (26, 220)
assert raw.info['sfreq'] == 12.5

# Test channel naming
assert raw.info['ch_names'][:4] == ["S1_D2 760", "S1_D2 850",
"S1_D9 760", "S1_D9 850"]
assert raw.info['ch_names'][24:26] == ["S5_D13 760", "S5_D13 850"]

# Test frequency encoding
assert raw.info['chs'][0]['loc'][9] == 760
assert raw.info['chs'][1]['loc'][9] == 850

# Test info import
assert raw.info['subject_info'] == dict(
sex=0, first_name="testMontage\\0ATestMontage")

# Test distance between optodes matches values from
# https://github.com/mne-tools/mne-testing-data/pull/72
allowed_distance_error = 0.001
distances = source_detector_distances(raw.info)
assert_allclose(distances[::2], [
0.0304, 0.0078, 0.0310, 0.0086, 0.0416,
0.0072, 0.0389, 0.0075, 0.0558, 0.0562,
0.0561, 0.0565, 0.0077], atol=allowed_distance_error)

# Test which channels are short
# These are the ones marked as red at
# https://github.com/mne-tools/mne-testing-data/pull/72
is_short = short_channels(raw.info)
assert_array_equal(is_short[:9:2], [False, True, False, True, False])
is_short = short_channels(raw.info, threshold=0.003)
assert_array_equal(is_short[:3:2], [False, False])
is_short = short_channels(raw.info, threshold=50)
assert_array_equal(is_short[:3:2], [True, True])

# Test trigger events
assert_array_equal(raw.annotations.description, ['4.0', '2.0', '1.0'])

# Test location of detectors
# The locations of detectors can be seen in the first
# figure on this page...
# https://github.com/mne-tools/mne-testing-data/pull/72
# And have been manually copied below
allowed_dist_error = 0.0002
locs = [ch['loc'][6:9] for ch in raw.info['chs']]
head_mri_t, _ = _get_trans('fsaverage', 'head', 'mri')
mni_locs = apply_trans(head_mri_t, locs)

assert raw.info['ch_names'][0][3:5] == 'D2'
assert_allclose(
mni_locs[0], [-0.0841, -0.0464, -0.0129], atol=allowed_dist_error)

assert raw.info['ch_names'][4][3:5] == 'D1'
assert_allclose(
mni_locs[4], [0.0846, -0.0142, -0.0156], atol=allowed_dist_error)

assert raw.info['ch_names'][8][3:5] == 'D3'
assert_allclose(
mni_locs[8], [0.0207, -0.1062, 0.0484], atol=allowed_dist_error)

assert raw.info['ch_names'][12][3:5] == 'D4'
assert_allclose(
mni_locs[12], [-0.0196, 0.0821, 0.0275], atol=allowed_dist_error)

assert raw.info['ch_names'][16][3:5] == 'D5'
assert_allclose(
mni_locs[16], [-0.0360, 0.0276, 0.0778], atol=allowed_dist_error)

assert raw.info['ch_names'][19][3:5] == 'D6'
assert_allclose(
mni_locs[19], [0.0388, -0.0477, 0.0932], atol=allowed_dist_error)

assert raw.info['ch_names'][21][3:5] == 'D7'
assert_allclose(
mni_locs[21], [-0.0394, -0.0483, 0.0928], atol=allowed_dist_error)


@requires_testing_data
def test_encoding(tmpdir):
"""Test NIRx encoding."""
Expand Down
2 changes: 1 addition & 1 deletion mne/io/snirf/tests/test_snirf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'snirf_1_3_nirx_15_2_recording_w_short.snirf')

fname_original = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording_w_short')
'NIRx', 'nirscout', 'nirx_15_2_recording_w_short')


@requires_testing_data
Expand Down
10 changes: 6 additions & 4 deletions mne/preprocessing/tests/test_beer_lambert_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@


fname_nirx_15_0 = op.join(data_path(download=False),
'NIRx', 'nirx_15_0_recording')
'NIRx', 'nirscout', 'nirx_15_0_recording')
fname_nirx_15_2 = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording')
'NIRx', 'nirscout', 'nirx_15_2_recording')
fname_nirx_15_2_short = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording_w_short')
'NIRx', 'nirscout',
'nirx_15_2_recording_w_short')


@testing.requires_testing_data
Expand Down Expand Up @@ -88,7 +89,8 @@ def test_beer_lambert_v_matlab():
raw._data *= 1e6 # Scale to uM for comparison to MATLAB

matlab_fname = op.join(data_path(download=False),
'NIRx', 'validation', 'nirx_15_0_recording_bl.mat')
'NIRx', 'nirscout', 'validation',
'nirx_15_0_recording_bl.mat')
matlab_data = read_mat(matlab_fname)

for idx in range(raw.get_data().shape[0]):
Expand Down
7 changes: 4 additions & 3 deletions mne/preprocessing/tests/test_nirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
from mne.datasets import testing

fname_nirx_15_0 = op.join(data_path(download=False),
'NIRx', 'nirx_15_0_recording')
'NIRx', 'nirscout', 'nirx_15_0_recording')
fname_nirx_15_2 = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording')
'NIRx', 'nirscout', 'nirx_15_2_recording')
fname_nirx_15_2_short = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording_w_short')
'NIRx', 'nirscout',
'nirx_15_2_recording_w_short')


@testing.requires_testing_data
Expand Down
2 changes: 1 addition & 1 deletion mne/preprocessing/tests/test_optical_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


fname_nirx = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording_w_short')
'NIRx', 'nirscout', 'nirx_15_2_recording_w_short')


@testing.requires_testing_data
Expand Down
7 changes: 4 additions & 3 deletions mne/preprocessing/tests/test_scalp_coupling_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
from mne.datasets import testing

fname_nirx_15_0 = op.join(data_path(download=False),
'NIRx', 'nirx_15_0_recording')
'NIRx', 'nirscout', 'nirx_15_0_recording')
fname_nirx_15_2 = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording')
'NIRx', 'nirscout', 'nirx_15_2_recording')
fname_nirx_15_2_short = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording_w_short')
'NIRx', 'nirscout',
'nirx_15_2_recording_w_short')


@testing.requires_testing_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


fname_nirx_15_2 = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording')
'NIRx', 'nirscout', 'nirx_15_2_recording')


@testing.requires_testing_data
Expand Down
2 changes: 1 addition & 1 deletion mne/viz/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def fnirs_evoked():
def fnirs_epochs():
"""Create an fnirs epoch structure."""
fname = op.join(data_path(download=False),
'NIRx', 'nirx_15_2_recording_w_overlap')
'NIRx', 'nirscout', 'nirx_15_2_recording_w_overlap')
raw_intensity = read_raw_nirx(fname, preload=False)
raw_od = optical_density(raw_intensity)
raw_haemo = beer_lambert_law(raw_od)
Expand Down
3 changes: 2 additions & 1 deletion mne/viz/tests/test_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
'sample-oct-6-src.fif')
dip_fname = op.join(data_dir, 'MEG', 'sample', 'sample_audvis_trunc_set1.dip')
ctf_fname = op.join(data_dir, 'CTF', 'testdata_ctf.ds')
nirx_fname = op.join(data_dir, 'NIRx', 'nirx_15_2_recording_w_short')
nirx_fname = op.join(data_dir, 'NIRx', 'nirscout',
'nirx_15_2_recording_w_short')

io_dir = op.join(op.abspath(op.dirname(__file__)), '..', '..', 'io')
base_dir = op.join(io_dir, 'tests', 'data')
Expand Down

0 comments on commit 6d0b634

Please sign in to comment.