Skip to content

Commit

Permalink
ENH: Smaller test dataset (150MB)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Sep 23, 2014
1 parent cfd7e50 commit cce5d78
Show file tree
Hide file tree
Showing 42 changed files with 433 additions and 516 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ memmap*.dat
tmp-*.w
tmtags
auto_examples
MNE-sample-data*
MNE-spm-face*
MNE-eegbci-data*
MNE-sample-data*
MNE-somato-data*
MNE-spm-face*
MNE-testing-data*
MEGSIM*
build
coverage
Expand Down
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ install:
fi;
- pip install -q coverage coveralls nose-timer > /dev/null
# Suppress the parallel outputs for logging cleanliness
- export MNE_LOGGING_LEVEL=warning
- export MNE_SKIP_SAMPLE_DATASET_TESTS=1
# Skip tests that require large downloads over the network to save bandwith
# usage as travis workers are stateless and therefore traditional local
# disk caching does not work.
Expand All @@ -49,6 +47,11 @@ install:
- for script in $myscripts; do mne $script --help >/dev/null; done;
- SRC_DIR=$(pwd)
- cd ~
# Trigger download of testing data
- python -c 'import mne; mne.datasets.testing.data_path()'
# Set up tests
- export MNE_LOGGING_LEVEL=warning
- export MNE_SKIP_SAMPLE_DATASET_TESTS=1
- MNE_DIR=$(python -c 'import mne;print(mne.__path__[0])')
- ln -s ${SRC_DIR}/mne/io/tests/data ${MNE_DIR}/io/tests/data
- ln -s ${SRC_DIR}/mne/io/bti/tests/data ${MNE_DIR}/io/bti/tests/data
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ inplace:
sample_data: $(CURDIR)/examples/MNE-sample-data/MEG/sample/sample_audvis_raw.fif
@echo "Target needs sample data"

testing_data:
@python -c "import mne; mne.datasets.testing.data_path(verbose=True);"

$(CURDIR)/examples/MNE-sample-data/MEG/sample/sample_audvis_raw.fif:
wget -c ftp://surfer.nmr.mgh.harvard.edu/pub/data/MNE-sample-data-processed.tar.gz
tar xvzf MNE-sample-data-processed.tar.gz
Expand All @@ -48,23 +51,23 @@ test-no-sample: in
$(NOSETESTS) mne


test-no-sample-with-coverage: in
test-no-sample-with-coverage: in testing_data
rm -rf coverage .coverage
@MNE_SKIP_SAMPLE_DATASET_TESTS=true \
$(NOSETESTS) --with-coverage --cover-package=mne --cover-html --cover-html-dir=coverage

test-doc: sample_data
test-doc: sample_data testing_data
$(NOSETESTS) --with-doctest --doctest-tests --doctest-extension=rst doc/ doc/source/

test-coverage: sample_data
test-coverage: sample_data testing_data
rm -rf coverage .coverage
$(NOSETESTS) --with-coverage --cover-package=mne --cover-html --cover-html-dir=coverage

test-profile: sample_data
test-profile: sample_data testing_data
$(NOSETESTS) --with-profile --profile-stats-file stats.pf mne
hotshot2dot stats.pf | dot -Tpng -o profile.png

test-mem: in sample_data
test-mem: in sample_data testing_data
ulimit -v 1097152 && $(NOSETESTS)

trailing-spaces:
Expand All @@ -91,3 +94,4 @@ manpages:
help2man -n "$$descr" --no-discard-stderr --no-info --version-string "$(uver)" ./$$f \
>| ../build/manpages/$$f.1; \
done

1 change: 1 addition & 0 deletions mne/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from . import spm_face
from . import eegbci
from . import somato
from . import testing
4 changes: 4 additions & 0 deletions mne/datasets/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""MNE sample dataset
"""

from ._testing import data_path
19 changes: 19 additions & 0 deletions mne/datasets/testing/_testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Authors: Alexandre Gramfort <[email protected]>
# Martin Luessi <[email protected]>
# Eric Larson <[email protected]>
# License: BSD Style.

from ...utils import verbose
from ..utils import _data_path, _doc


@verbose
def data_path(path=None, force_update=False, update_path=True,
download=True, verbose=None):
return _data_path(path=path, force_update=force_update,
update_path=update_path, name='testing',
download=download,
verbose=verbose)

data_path.__doc__ = _doc.format(name='testing',
conf='MNE_DATASETS_TESTING_PATH')
23 changes: 14 additions & 9 deletions mne/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def _data_path(path=None, force_update=False, update_path=True,
"""
key = {'sample': 'MNE_DATASETS_SAMPLE_PATH',
'spm': 'MNE_DATASETS_SPM_FACE_PATH',
'somato': 'MNE_DATASETS_SOMATO_PATH',}[name]
'somato': 'MNE_DATASETS_SOMATO_PATH',
'testing': 'MNE_DATASETS_TESTING_PATH',
}[name]

if path is None:
# use an intelligent guess if it's not defined
Expand All @@ -95,30 +97,33 @@ def _data_path(path=None, force_update=False, update_path=True,
os.mkdir(path)
except OSError:
raise OSError("User does not have write permissions "
"at '%s', try giving the path as an argument "
"to data_path() where user has write "
"at '%s', try giving the path as an argument"
" to data_path() where user has write "
"permissions, for ex:data_path"
"('/home/xyz/me2/')" % (path))

if not isinstance(path, string_types):
raise ValueError('path must be a string or None')
if name == 'sample':
archive_name = "MNE-sample-data-processed.tar.gz"
url = "ftp://surfer.nmr.mgh.harvard.edu/pub/data/MNE/" + archive_name
folder_name = "MNE-sample-data"
folder_path = op.join(path, folder_name)
url = "ftp://surfer.nmr.mgh.harvard.edu/pub/data/MNE/" + archive_name
elif name == 'spm':
archive_name = 'MNE-spm-face.tar.bz2'
url = 'ftp://surfer.nmr.mgh.harvard.edu/pub/data/MNE/' + archive_name
folder_name = "MNE-spm-face"
folder_path = op.join(path, folder_name)
url = 'ftp://surfer.nmr.mgh.harvard.edu/pub/data/MNE/' + archive_name
elif name == 'somato':
archive_name = 'MNE-somato-data.tar.gz'
url = 'ftp://surfer.nmr.mgh.harvard.edu/pub/data/MNE/' + archive_name
folder_name = "MNE-somato-data"
folder_path = op.join(path, folder_name)
url = 'ftp://surfer.nmr.mgh.harvard.edu/pub/data/MNE/' + archive_name
elif name == 'testing':
archive_name = 'MNE-testing-data.tar.gz'
folder_name = 'MNE-testing-data'
url = 'https://lester.ilabs.uw.edu/files/' + archive_name
else:
raise ValueError('Sorry, the dataset "%s" is not known.' % name)
folder_path = op.join(path, folder_name)

rm_archive = False
martinos_path = '/cluster/fusion/sample_data/' + archive_name
neurospin_path = '/neurospin/tmp/gramfort/' + archive_name
Expand Down
9 changes: 4 additions & 5 deletions mne/forward/tests/test_field_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from mne.forward import _make_surface_mapping, make_field_map
from mne.surface import get_meg_helmet_surf, get_head_surf
from mne.datasets import sample
from mne.datasets import testing
from mne.forward._lead_dots import (_comp_sum_eeg, _comp_sums_meg,
_get_legen_table,
_get_legen_lut_fast,
Expand All @@ -19,9 +19,9 @@
base_dir = op.join(op.dirname(__file__), '..', '..', 'io', 'tests', 'data')
evoked_fname = op.join(base_dir, 'test-ave.fif')

data_path = sample.data_path(download=False)
data_path = testing.data_path()
trans_fname = op.join(data_path, 'MEG', 'sample',
'sample_audvis_raw-trans.fif')
'sample_audvis_trunc-trans.fif')
subjects_dir = op.join(data_path, 'subjects')


Expand Down Expand Up @@ -90,7 +90,6 @@ def test_legendre_table():
assert_allclose(n_fact1, n_fact2)


@sample.requires_sample_data
def test_make_field_map_eeg():
"""Test interpolation of EEG field onto head
"""
Expand All @@ -111,7 +110,7 @@ def test_make_field_map_eeg():
fmd = make_field_map(evoked, trans_fname=trans_fname,
subject='sample', subjects_dir=subjects_dir)
assert_true(len(fmd) == 1)
assert_array_equal(fmd[0]['data'].shape, (2562, 59)) # maps data onto surf
assert_array_equal(fmd[0]['data'].shape, (162, 59)) # maps data onto surf
assert_true(len(fmd[0]['ch_names']), 59)


Expand Down
74 changes: 29 additions & 45 deletions mne/forward/tests/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from numpy.testing import (assert_array_almost_equal, assert_equal,
assert_array_equal, assert_allclose)

from mne.datasets import sample
from mne.datasets import testing
from mne.io import Raw
from mne import (read_forward_solution, apply_forward, apply_forward_raw,
average_forward_solutions, write_forward_solution,
Expand All @@ -18,17 +18,17 @@
from mne.forward import (restrict_forward_to_stc, restrict_forward_to_label,
Forward)

data_path = sample.data_path(download=False)
fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis-meg-oct-6-fwd.fif')
data_path = testing.data_path()
fname_meeg = op.join(data_path, 'MEG', 'sample',
'sample_audvis-meg-eeg-oct-6-fwd.fif')
'sample_audvis_trunc-meg-eeg-oct-4-fwd.fif')

fname_raw = op.join(op.dirname(__file__), '..', '..', 'io', 'tests', 'data',
'test_raw.fif')

fname_evoked = op.join(op.dirname(__file__), '..', '..', 'io', 'tests',
'data', 'test-ave.fif')
fname_mri = op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw-trans.fif')
fname_mri = op.join(data_path, 'MEG', 'sample',
'sample_audvis_trunc-trans.fif')
subjects_dir = os.path.join(data_path, 'subjects')
fname_src = op.join(subjects_dir, 'sample', 'bem', 'sample-oct-6-src.fif')
temp_dir = _TempDir()
Expand All @@ -52,7 +52,6 @@ def compare_forwards(f1, f2):
assert_equal(f1['surf_ori'], f2['surf_ori'])


@sample.requires_sample_data
def test_convert_forward():
"""Test converting forward solution between different representations
"""
Expand Down Expand Up @@ -83,61 +82,49 @@ def test_convert_forward():
compare_forwards(fwd, fwd_new)


@sample.requires_sample_data
def test_io_forward():
"""Test IO for forward solutions
"""
# test M/EEG
fwd_meeg = read_forward_solution(fname_meeg)
assert_true(isinstance(fwd_meeg, Forward))
leadfield = fwd_meeg['sol']['data']
assert_equal(leadfield.shape, (366, 22494))
assert_equal(len(fwd_meeg['sol']['row_names']), 366)
fname_temp = op.join(temp_dir, 'test-fwd.fif')
write_forward_solution(fname_temp, fwd_meeg, overwrite=True)

fwd_meeg = read_forward_solution(fname_temp)
assert_allclose(leadfield, fwd_meeg['sol']['data'])
assert_equal(len(fwd_meeg['sol']['row_names']), 366)

# now do extensive tests with MEG
fwd = read_forward_solution(fname)
fwd = read_forward_solution(fname, surf_ori=True)
# do extensive tests with MEEG
n_src = 1533
fwd = read_forward_solution(fname_meeg)
assert_true(isinstance(fwd, Forward))
fwd = read_forward_solution(fname_meeg, surf_ori=True)
leadfield = fwd['sol']['data']
assert_equal(leadfield.shape, (306, 22494))
assert_equal(len(fwd['sol']['row_names']), 306)
assert_equal(leadfield.shape, (366, n_src))
assert_equal(len(fwd['sol']['row_names']), 366)
fname_temp = op.join(temp_dir, 'test-fwd.fif')
write_forward_solution(fname_temp, fwd, overwrite=True)

fwd = read_forward_solution(fname, surf_ori=True)
fwd = read_forward_solution(fname_meeg, surf_ori=True)
fwd_read = read_forward_solution(fname_temp, surf_ori=True)
leadfield = fwd_read['sol']['data']
assert_equal(leadfield.shape, (306, 22494))
assert_equal(len(fwd_read['sol']['row_names']), 306)
assert_equal(len(fwd_read['info']['chs']), 306)
assert_equal(leadfield.shape, (366, n_src))
assert_equal(len(fwd_read['sol']['row_names']), 366)
assert_equal(len(fwd_read['info']['chs']), 366)
assert_true('dev_head_t' in fwd_read['info'])
assert_true('mri_head_t' in fwd_read)
assert_array_almost_equal(fwd['sol']['data'], fwd_read['sol']['data'])

fwd = read_forward_solution(fname, force_fixed=True)
fwd = read_forward_solution(fname_meeg, force_fixed=True)
leadfield = fwd['sol']['data']
assert_equal(leadfield.shape, (306, 22494 / 3))
assert_equal(len(fwd['sol']['row_names']), 306)
assert_equal(len(fwd['info']['chs']), 306)
assert_equal(leadfield.shape, (366, n_src / 3))
assert_equal(len(fwd['sol']['row_names']), 366)
assert_equal(len(fwd['info']['chs']), 366)
assert_true('dev_head_t' in fwd['info'])
assert_true('mri_head_t' in fwd)
assert_true(fwd['surf_ori'])

# test warnings on bad filenames
fwd = read_forward_solution(fname_meeg)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
fwd_badname = op.join(temp_dir, 'test-bad-name.fif.gz')
write_forward_solution(fwd_badname, fwd_meeg)
write_forward_solution(fwd_badname, fwd)
read_forward_solution(fwd_badname)
assert_true(len(w) == 2)


@sample.requires_sample_data
def test_apply_forward():
"""Test projection of source space data to sensor space
"""
Expand All @@ -147,7 +134,7 @@ def test_apply_forward():
sfreq = 10.0
t_start = 0.123

fwd = read_forward_solution(fname, force_fixed=True)
fwd = read_forward_solution(fname_meeg, force_fixed=True)
fwd = pick_types_forward(fwd, meg=True)
assert_true(isinstance(fwd, Forward))

Expand Down Expand Up @@ -183,7 +170,6 @@ def test_apply_forward():
assert_array_almost_equal(times[-1], t_start + (n_times - 1) / sfreq)


@sample.requires_sample_data
def test_restrict_forward_to_stc():
"""Test restriction of source space to source SourceEstimate
"""
Expand All @@ -193,7 +179,7 @@ def test_restrict_forward_to_stc():
sfreq = 10.0
t_start = 0.123

fwd = read_forward_solution(fname, force_fixed=True)
fwd = read_forward_solution(fname_meeg, force_fixed=True)
fwd = pick_types_forward(fwd, meg=True)

vertno = [fwd['src'][0]['vertno'][0:15], fwd['src'][1]['vertno'][0:5]]
Expand All @@ -209,7 +195,7 @@ def test_restrict_forward_to_stc():
assert_equal(fwd_out['src'][0]['vertno'], fwd['src'][0]['vertno'][0:15])
assert_equal(fwd_out['src'][1]['vertno'], fwd['src'][1]['vertno'][0:5])

fwd = read_forward_solution(fname, force_fixed=False)
fwd = read_forward_solution(fname_meeg, force_fixed=False)
fwd = pick_types_forward(fwd, meg=True)

vertno = [fwd['src'][0]['vertno'][0:15], fwd['src'][1]['vertno'][0:5]]
Expand All @@ -225,11 +211,10 @@ def test_restrict_forward_to_stc():
assert_equal(fwd_out['src'][1]['vertno'], fwd['src'][1]['vertno'][0:5])


@sample.requires_sample_data
def test_restrict_forward_to_label():
"""Test restriction of source space to label
"""
fwd = read_forward_solution(fname, force_fixed=True)
fwd = read_forward_solution(fname_meeg, force_fixed=True)
fwd = pick_types_forward(fwd, meg=True)

label_path = op.join(data_path, 'MEG', 'sample', 'labels')
Expand All @@ -252,7 +237,7 @@ def test_restrict_forward_to_label():
assert_equal(fwd_out['src'][0]['vertno'], src_sel_lh)
assert_equal(fwd_out['src'][1]['vertno'], src_sel_rh)

fwd = read_forward_solution(fname, force_fixed=False)
fwd = read_forward_solution(fname_meeg, force_fixed=False)
fwd = pick_types_forward(fwd, meg=True)

label_path = op.join(data_path, 'MEG', 'sample', 'labels')
Expand All @@ -277,12 +262,11 @@ def test_restrict_forward_to_label():
assert_equal(fwd_out['src'][1]['vertno'], src_sel_rh)


@sample.requires_sample_data
@requires_mne
def test_average_forward_solution():
"""Test averaging forward solutions
"""
fwd = read_forward_solution(fname)
fwd = read_forward_solution(fname_meeg)
# input not a list
assert_raises(TypeError, average_forward_solutions, 1)
# list is too short
Expand All @@ -305,7 +289,7 @@ def test_average_forward_solution():
fwd_copy['sol']['data'] *= 0.5
fname_copy = op.join(temp_dir, 'copy-fwd.fif')
write_forward_solution(fname_copy, fwd_copy, overwrite=True)
cmd = ('mne_average_forward_solutions', '--fwd', fname, '--fwd',
cmd = ('mne_average_forward_solutions', '--fwd', fname_meeg, '--fwd',
fname_copy, '--out', fname_copy)
run_subprocess(cmd)

Expand Down
Loading

0 comments on commit cce5d78

Please sign in to comment.