Skip to content

Commit

Permalink
MRG: Fix info (mne-tools#4871)
Browse files Browse the repository at this point in the history
* FIX: Fix info

* FIX: Fix failing tests

* FIX: Fix Windows and Linux
  • Loading branch information
larsoner authored and agramfort committed Jan 13, 2018
1 parent 1efbe92 commit 8a302bd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
17 changes: 14 additions & 3 deletions mne/io/eeglab/tests/test_eeglab.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
#
# License: BSD (3-clause)

from distutils.version import LooseVersion
import os.path as op
import shutil
from unittest import SkipTest

import warnings
from nose.tools import assert_raises, assert_equal, assert_true
import numpy as np
from numpy.testing import assert_array_equal, assert_array_almost_equal
from scipy import io

from mne import write_events, read_epochs_eeglab, Epochs, find_events
from mne.io import read_raw_eeglab
from mne.io.tests.test_raw import _test_raw_reader
from mne.io.eeglab.eeglab import read_events_eeglab
from mne.datasets import testing
from mne.utils import _TempDir, run_tests_if_main, requires_version
from mne.utils import _TempDir, run_tests_if_main

base_dir = op.join(testing.data_path(download=False), 'EEGLAB')
raw_fname = op.join(base_dir, 'test_raw.set')
Expand All @@ -28,11 +31,9 @@
warnings.simplefilter('always') # enable b/c these tests throw warnings


@requires_version('scipy', '0.12')
@testing.requires_testing_data
def test_io_set():
"""Test importing EEGLAB .set files."""
from scipy import io
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
# main tests, and test missing event_id
Expand Down Expand Up @@ -167,6 +168,11 @@ def test_io_set():
for fld in range(4):
chanlocs[ind][dt[fld][0]] = vals[fld]

if LooseVersion(np.__version__) == '1.14.0':
# There is a bug in 1.14.0 (or maybe with SciPy 1.0.0?) that causes
# this write to fail!
raise SkipTest('Need to fix bug in NumPy 1.14.0!')

# save set file
one_chanpos_fname = op.join(temp_dir, 'test_chanpos.set')
io.savemat(one_chanpos_fname, {'EEG':
Expand Down Expand Up @@ -223,7 +229,12 @@ def test_io_set():
assert_array_equal(raw.info['chs'][i]['loc'][:3],
np.array([0., 0., 0.]))


@testing.requires_testing_data
def test_degenerate():
"""Test some degenerate conditions."""
# test if .dat file raises an error
temp_dir = _TempDir()
eeg = io.loadmat(epochs_fname, struct_as_record=False,
squeeze_me=True)['EEG']
eeg.data = 'epochs_fname.dat'
Expand Down
6 changes: 4 additions & 2 deletions mne/minimum_norm/tests/test_inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,10 @@ def test_make_inverse_operator_vector():
stc_diff_vec = apply_inverse(diff, inv_1, method='MNE', pick_ori='vector')
stc_vec0 = apply_inverse(evoked0, inv_1, method='MNE', pick_ori='vector')
stc_vec1 = apply_inverse(evoked1, inv_1, method='MNE', pick_ori='vector')
assert_allclose(stc_diff_vec.data, (stc_vec0 - stc_vec1).data)
assert_allclose(stc_diff.data, (stc_vec0 - stc_vec1).magnitude().data)
assert_allclose(stc_diff_vec.data, (stc_vec0 - stc_vec1).data,
atol=1e-20)
assert_allclose(stc_diff.data, (stc_vec0 - stc_vec1).magnitude().data,
atol=1e-20)


@testing.requires_testing_data
Expand Down
15 changes: 5 additions & 10 deletions mne/source_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
write_float_matrix, write_int_matrix,
write_coord_trans, start_file, end_file, write_id)
from .bem import read_bem_surfaces, ConductorModel
from .fixes import _get_args
from .surface import (read_surface, _create_surf_spacing, _get_ico_surface,
_tessellate_sphere_surf, _get_surf_neighbors,
_normalize_vectors, _get_solids, _triangle_neighbors,
Expand All @@ -42,21 +41,17 @@ def _get_lut():
"""Get the FreeSurfer LUT."""
data_dir = op.join(op.dirname(__file__), 'data')
lut_fname = op.join(data_dir, 'FreeSurferColorLUT.txt')
kwargs = dict()
if 'encoding' in _get_args(np.genfromtxt):
kwargs['encoding'] = 'ascii'
return np.genfromtxt(lut_fname, dtype=None,
usecols=(0, 1, 2, 3, 4, 5),
names=['id', 'name', 'R', 'G', 'B', 'A'],
**kwargs)
dtype = [('id', '<i8'), ('name', 'U47'),
('R', '<i8'), ('G', '<i8'), ('B', '<i8'), ('A', '<i8')]
return np.genfromtxt(lut_fname, dtype=dtype)


def _get_lut_id(lut, label, use_lut):
"""Convert a label to a LUT ID number."""
if not use_lut:
return 1
assert isinstance(label, string_types)
mask = (lut['name'] == label.encode('utf-8'))
mask = (lut['name'] == label)
assert mask.sum() == 1
return lut['id'][mask]

Expand Down Expand Up @@ -2429,7 +2424,7 @@ def get_volume_labels_from_aseg(mgz_fname, return_colors=False):
# Get the unique label names
lut = _get_lut()

label_names = [lut[lut['id'] == ii]['name'][0].decode('utf-8')
label_names = [lut[lut['id'] == ii]['name'][0]
for ii in np.unique(mgz_data)]
label_colors = [[lut[lut['id'] == ii]['R'][0],
lut[lut['id'] == ii]['G'][0],
Expand Down
8 changes: 6 additions & 2 deletions mne/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2594,8 +2594,12 @@ def sys_info(fid=None, show_paths=False):
for li, line in enumerate(lines):
for key in ('lapack', 'blas'):
if line.startswith('%s_opt_info' % key):
libs += ['%s=' % key +
lines[li + 1].split('[')[1].split("'")[1]]
lib = lines[li + 1]
if 'NOT AVAILABLE' in lib:
lib = 'unknown'
else:
lib = lib.split('[')[1].split("'")[1]
libs += ['%s=%s' % (key, lib)]
libs = ', '.join(libs)
version_texts = dict(pycuda='VERSION_TEXT')
for mod_name in ('mne', 'numpy', 'scipy', 'matplotlib', '',
Expand Down

0 comments on commit 8a302bd

Please sign in to comment.