Skip to content

Commit

Permalink
ENH: Speed up a couple of tests (#5348)
Browse files Browse the repository at this point in the history
* ENH: Speed up a couple of tests

* FIX: Combine runs
  • Loading branch information
larsoner committed Jul 18, 2018
1 parent 512fafc commit 5389a45
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 38 deletions.
28 changes: 2 additions & 26 deletions .travis.yml
Expand Up @@ -22,54 +22,29 @@ matrix:
# Linux
- os: linux
env: CONDA_ENVIRONMENT="environment.yml"
SPLIT=0
- os: linux
env: CONDA_ENVIRONMENT="environment.yml"
SPLIT=1

# OSX conda
- os: osx
env: CONDA_ENVIRONMENT="environment.yml"
SPLIT=0
- os: osx
env: CONDA_ENVIRONMENT="environment.yml"
SPLIT=1

# PIP + non-default stim channel
# OPENBLAS_NUM_THREADS=1 avoid slowdowns:
# https://github.com/xianyi/OpenBLAS/issues/731
- os: linux
env: MNE_STIM_CHANNEL=STI101
OPENBLAS_NUM_THREADS=1
SPLIT=0
language: python
python: "3.6"
- os: linux
env: MNE_STIM_CHANNEL=STI101
OPENBLAS_NUM_THREADS=1
SPLIT=1
language: python
python: "3.6"

# 2.7 Old dependencies
- os: linux
env: PYTHON_VERSION=2.7
CONDA_DEPENDENCIES="numpy=1.8 scipy=0.12 matplotlib=1.3 pandas=0.13 scikit-learn=0.15 pytest pytest-cov"
SPLIT=0
- os: linux
env: PYTHON_VERSION=2.7
CONDA_DEPENDENCIES="numpy=1.8 scipy=0.12 matplotlib=1.3 pandas=0.13 scikit-learn=0.15 pytest pytest-cov"
SPLIT=1

# Minimal
- os: linux
env: DEPS=minimial
CONDA_DEPENDENCIES="numpy scipy matplotlib pytest pytest-cov"
SPLIT=0
- os: linux
env: DEPS=minimial
CONDA_DEPENDENCIES="numpy scipy matplotlib pytest pytest-cov"
SPLIT=1

# Setup anaconda
before_install:
Expand Down Expand Up @@ -167,7 +142,8 @@ script:
CONDITION='not ultraslowtest';
fi;
- python -c "import mne; print(mne.sys_info())"
# Determine directories to test
# Determine directories to test (could use SPLIT=0 SPLIT=1 but currently
# we are fast enough, so disable it)
- if [ -z ${SPLIT} ]; then
USE_DIRS="mne/";
else
Expand Down
2 changes: 1 addition & 1 deletion mne/io/bti/bti.py
Expand Up @@ -1016,7 +1016,7 @@ class RawBTi(BaseRaw):
and :ref:`Logging documentation <tut_logging>` for more).
"""

@verbose
# @verbose
def __init__(self, pdf_fname, config_fname='config',
head_shape_fname='hs_file', rotation_x=0.,
translation=(0.0, 0.02, 0.11), convert=True,
Expand Down
3 changes: 2 additions & 1 deletion mne/io/bti/tests/test_bti.py
Expand Up @@ -114,7 +114,8 @@ def test_raw():
assert_equal(ex.ch_names[:NCH], ra.ch_names[:NCH])
assert_array_almost_equal(ex.info['dev_head_t']['trans'],
ra.info['dev_head_t']['trans'], 7)
assert_dig_allclose(ex.info, ra.info)
assert len(ex.info['dig']) in (3563, 5154)
assert_dig_allclose(ex.info, ra.info, limit=100)
coil1, coil2 = [np.concatenate([d['loc'].flatten()
for d in r_.info['chs'][:NCH]])
for r_ in (ra, ex)]
Expand Down
15 changes: 8 additions & 7 deletions mne/preprocessing/tests/test_ica.py
Expand Up @@ -333,15 +333,16 @@ def test_ica_additional(method):
tempdir = _TempDir()
stop2 = 500
raw = read_raw_fif(raw_fname).crop(1.5, stop).load_data()
raw.del_proj() # avoid warnings
raw.annotations = Annotations([0.5], [0.5], ['BAD'])
# XXX This breaks the tests :(
# raw.info['bads'] = [raw.ch_names[1]]
test_cov = read_cov(test_cov_name)
events = read_events(event_name)
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')
eog=False, exclude='bads')[1::2]
epochs = Epochs(raw, events, None, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
baseline=(None, 0), preload=True, proj=False)
epochs.decimate(3, verbose='error')
assert len(epochs) == 4

Expand All @@ -351,10 +352,10 @@ def test_ica_additional(method):
with warnings.catch_warnings(record=True):
ica.fit(epochs)
# for testing eog functionality
picks2 = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=True, exclude='bads')
picks2 = np.concatenate([picks, pick_types(raw.info, False, eog=True)])
epochs_eog = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks2,
baseline=(None, 0), preload=True)
del picks2

test_cov2 = test_cov.copy()
ica = ICA(noise_cov=test_cov2, n_components=3, max_pca_components=4,
Expand Down Expand Up @@ -413,7 +414,7 @@ def test_ica_additional(method):
raw_.append(raw_)
n_samples = raw_._data.shape[1]
with warnings.catch_warnings(record=True):
ica.fit(raw, picks=None, decim=3)
ica.fit(raw, picks=picks[:5], decim=3)
assert raw_._data.shape[1] == n_samples

# test expl var
Expand All @@ -440,11 +441,11 @@ def test_ica_additional(method):
ica = ICA(noise_cov=cov, n_components=2, max_pca_components=4,
n_pca_components=4, method=method, max_iter=1)
with warnings.catch_warnings(record=True): # ICA does not converge
ica.fit(raw, picks=picks, start=start, stop=stop2)
ica.fit(raw, picks=picks[:10], start=start, stop=stop2)
sources = ica.get_sources(epochs).get_data()
assert (ica.mixing_matrix_.shape == (2, 2))
assert (ica.unmixing_matrix_.shape == (2, 2))
assert (ica.pca_components_.shape == (4, len(picks)))
assert (ica.pca_components_.shape == (4, 10))
assert (sources.shape[1] == ica.n_components_)

for exclude in [[], [0], np.array([1, 2, 3])]:
Expand Down
6 changes: 3 additions & 3 deletions mne/tests/common.py
Expand Up @@ -84,13 +84,13 @@ def _dig_sort_key(dig):
return (dig['kind'], dig['ident'])


def assert_dig_allclose(info_py, info_bin):
def assert_dig_allclose(info_py, info_bin, limit=None):
"""Assert dig allclose."""
# test dig positions
dig_py = sorted(info_py['dig'], key=_dig_sort_key)
dig_bin = sorted(info_bin['dig'], key=_dig_sort_key)
assert_equal(len(dig_py), len(dig_bin))
for ii, (d_py, d_bin) in enumerate(zip(dig_py, dig_bin)):
assert len(dig_py) == len(dig_bin)
for ii, (d_py, d_bin) in enumerate(zip(dig_py[:limit], dig_bin[:limit])):
for key in ('ident', 'kind', 'coord_frame'):
assert_equal(d_py[key], d_bin[key])
assert_allclose(d_py['r'], d_bin['r'], rtol=1e-5, atol=1e-5,
Expand Down

0 comments on commit 5389a45

Please sign in to comment.