Skip to content

Commit

Permalink
MAINT: Update dataset and add constant test (mne-tools#7866)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Jun 5, 2020
1 parent 121364d commit 110b570
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 9 deletions.
11 changes: 8 additions & 3 deletions mne/beamformer/tests/test_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from mne.datasets import testing
from mne.beamformer import make_lcmv, apply_lcmv, apply_lcmv_cov
from mne.beamformer.tests.test_lcmv import _get_data
from mne.externals.pymatreader import read_mat
from mne.utils import run_tests_if_main


Expand Down Expand Up @@ -88,11 +89,15 @@ def test_lcmv_fieldtrip(_get_bf_data, bf_type, weight_norm, pick_ori, pwr):
stc_mne.data[:, :] = np.abs(stc_mne.data)

# load the FieldTrip output
ft_fname = op.join(ft_data_path, 'ft_source_' + bf_type + '-vol.stc')
stc_ft = mne.read_source_estimate(ft_fname)
ft_fname = op.join(ft_data_path, 'ft_source_' + bf_type + '-vol.mat')
stc_ft_data = read_mat(ft_fname)['stc']
if stc_ft_data.ndim == 3:
stc_ft_data = np.linalg.norm(stc_ft_data, axis=1)
else:
stc_ft_data = np.abs(stc_ft_data)

# calculate the Pearson correlation between the source solutions:
pearson = np.corrcoef(stc_mne.data.ravel(), stc_ft.data.ravel())[0, 1]
pearson = np.corrcoef(stc_mne.data.ravel(), stc_ft_data.ravel())[0, 1]
assert pearson >= 0.99


Expand Down
2 changes: 1 addition & 1 deletion mne/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def pytest_configure(config):
ignore:scipy\.gradient is deprecated.*:DeprecationWarning
ignore:sklearn\.externals\.joblib is deprecated.*:FutureWarning
ignore:The sklearn.*module.*deprecated.*:FutureWarning
ignore:.*TraitTuple.*trait.*handler.*deprecated.*:DeprecationWarning
ignore:.*trait.*handler.*deprecated.*:DeprecationWarning
ignore:.*rich_compare.*metadata.*deprecated.*:DeprecationWarning
ignore:.*In future, it will be an error for 'np.bool_'.*:DeprecationWarning
ignore:.*Converting `np\.character` to a dtype is deprecated.*:DeprecationWarning
Expand Down
4 changes: 2 additions & 2 deletions mne/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,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.87', misc='0.6')
releases = dict(testing='0.89', 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 @@ -326,7 +326,7 @@ def _data_path(path=None, force_update=False, update_path=True, download=True,
sample='12b75d1cb7df9dfb4ad73ed82f61094f',
somato='ea825966c0a1e9b2f84e3826c5500161',
spm='9f43f67150e3b694b523a21eb929ea75',
testing='a6e18de6405d84599c6d4dfb4c1d2b14',
testing='33c0ed664923acb2fee4737db6d02781',
multimodal='26ec847ae9ab80f58f204d09e2c08367',
fnirs_motor='c4935d19ddab35422a69f3326a01fef8',
opm='370ad1dcfd5c47e029e692c85358a374',
Expand Down
7 changes: 6 additions & 1 deletion mne/gui/_coreg_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
FileDialog, GUI)
from traits.api import (Bool, Button, cached_property, DelegatesTo, Directory,
Enum, Float, HasTraits, HasPrivateTraits, Instance,
Int, on_trait_change, Property, Str, List, RGBColor)
Int, on_trait_change, Property, Str, List)
from traitsui.api import (View, Item, Group, HGroup, VGroup, VGrid, EnumEditor,
Handler, Label, Spring, InstanceEditor, StatusItem,
UIInfo)
Expand Down Expand Up @@ -101,6 +101,11 @@
laggy_float_editor_scale, laggy_float_editor_deg,
laggy_float_editor_mm, laggy_float_editor_weight)

try:
from traitsui.api import RGBColor
except ImportError:
from traits.api import RGBColor

defaults = DEFAULTS['coreg']


Expand Down
7 changes: 5 additions & 2 deletions mne/gui/_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from mayavi.tools.mlab_scene_model import MlabSceneModel
from traits.api import (HasTraits, HasPrivateTraits, on_trait_change,
Instance, Array, Bool, Button, Enum, Float, Int, List,
Range, Str, RGBColor, Property, cached_property,
ArrayOrNone)
Range, Str, Property, cached_property, ArrayOrNone)
from traitsui.api import (View, Item, HGroup, VGrid, VGroup, Spring,
TextEditor)
from tvtk.api import tvtk
Expand All @@ -27,6 +26,10 @@
from ..viz.backends._pysurfer_mayavi import (_create_mesh_surf,
_toggle_mlab_render)

try:
from traitsui.api import RGBColor
except ImportError:
from traits.api import RGBColor

headview_borders = VGroup(Item('headview', style='custom', show_label=False),
show_border=True, label='View')
Expand Down
62 changes: 62 additions & 0 deletions mne/tests/test_defaults.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from copy import deepcopy

import numpy as np
from numpy.testing import assert_allclose
from mne.defaults import _handle_default


Expand All @@ -18,3 +20,63 @@ def test_handle_default():
assert x[key] != z[key]
else:
assert x[key] == z[key]


def test_si_units():
"""Test that our scalings actually produce SI units."""
scalings = _handle_default('scalings', None)
units = _handle_default('units', None)
# Add a bad one to test that we actually detect it
assert 'csd_bad' not in scalings
scalings['csd_bad'] = 1e5
units['csd_bad'] = 'V/m²'
assert set(scalings) == set(units)
known_prefixes = {
'': 1,
'm': 1e-3,
'c': 1e-2,
'µ': 1e-6,
'n': 1e-9,
'f': 1e-15,
}
known_SI = {'V', 'T', 'Am', 'm', 'M',
'AU', 'GOF'} # not really SI but we tolerate them
powers = '²'

def _split_si(x):
if x == 'nAm':
prefix, si = 'n', 'Am'
elif x == 'GOF':
prefix, si = '', 'GOF'
elif x == 'AU':
prefix, si = '', 'AU'
elif len(x) == 2:
if x[1] in powers:
prefix, si = '', x
else:
prefix, si = x
else:
assert len(x) in (0, 1), x
prefix, si = '', x
return prefix, si

for key, scale in scalings.items():
unit = units[key]
try:
num, denom = unit.split('/')
except ValueError: # not enough to unpack
num, denom = unit, ''
# check the numerator and denominator
num_prefix, num_SI = _split_si(num)
assert num_prefix in known_prefixes
assert num_SI in known_SI
den_prefix, den_SI = _split_si(denom)
assert den_prefix in known_prefixes
if not (den_SI == den_prefix == ''):
assert den_SI.strip(powers) in known_SI
# reconstruct the scale factor
want_scale = known_prefixes[den_prefix] / known_prefixes[num_prefix]
if key in ('csd_bad', 'csd'): # XXX CSD is wrong...
assert not np.isclose(scale, want_scale, rtol=10)
else:
assert_allclose(scale, want_scale, rtol=1e-12)

0 comments on commit 110b570

Please sign in to comment.