From 7b21b4e0380072652160b7bc77fb5674bab3ede8 Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Sun, 10 Feb 2019 18:53:34 +0100 Subject: [PATCH 01/16] fix issues raised by LGTM.com --- mne/annotations.py | 3 +-- mne/beamformer/_dics.py | 2 -- mne/coreg.py | 25 +++++++++++++------------ mne/decoding/mixin.py | 2 +- mne/io/base.py | 2 +- mne/io/proc_history.py | 2 +- mne/preprocessing/ctps_.py | 2 +- mne/preprocessing/ica.py | 5 +---- mne/preprocessing/maxfilter.py | 2 +- mne/transforms.py | 25 ++++++++++++------------- mne/viz/utils.py | 2 +- 11 files changed, 33 insertions(+), 39 deletions(-) diff --git a/mne/annotations.py b/mne/annotations.py index 3439103e823..d8e44a297b7 100644 --- a/mne/annotations.py +++ b/mne/annotations.py @@ -8,7 +8,6 @@ import re from copy import deepcopy from itertools import takewhile -from collections import OrderedDict import collections import numpy as np @@ -223,7 +222,7 @@ def __getitem__(self, key): out_keys = ('onset', 'duration', 'description', 'orig_time') out_vals = (self.onset[key], self.duration[key], self.description[key], self.orig_time) - return OrderedDict(zip(out_keys, out_vals)) + return collections.OrderedDict(zip(out_keys, out_vals)) else: key = list(key) if isinstance(key, tuple) else key return Annotations(onset=self.onset[key], diff --git a/mne/beamformer/_dics.py b/mne/beamformer/_dics.py index 3f083c6871c..344dfe8b50b 100644 --- a/mne/beamformer/_dics.py +++ b/mne/beamformer/_dics.py @@ -853,8 +853,6 @@ def tf_dics(epochs, forward, noise_csds, tmin, tmax, tstep, win_lengths, 'window %d to %d ms, in frequency range %d to %d Hz' % (win_tmin * 1e3, win_tmax * 1e3, fmin, fmax) ) - win_tmin = win_tmin - win_tmax = win_tmax # Calculating data CSD in current time window if mode == 'fourier': diff --git a/mne/coreg.py b/mne/coreg.py index c87734359be..b29cbf9af32 100644 --- a/mne/coreg.py +++ b/mne/coreg.py @@ -17,7 +17,6 @@ from functools import reduce import numpy as np -from numpy import dot from .io import read_fiducials, write_fiducials, read_info from .io.constants import FIFF @@ -288,7 +287,7 @@ def _trans_from_params(param_info, params): x, y, z = params[i:i + 3] trans.append(scaling(x, y, z)) - trans = reduce(dot, trans) + trans = reduce(np.dot, trans) return trans @@ -362,7 +361,7 @@ def fit_matched_points(src_pts, tgt_pts, rotate=True, translate=True, def error(x): rx, ry, rz = x trans = rotation3d(rx, ry, rz) - est = dot(src_pts, trans.T) + est = np.dot(src_pts, trans.T) d = tgt_pts - est if weights is not None: d *= weights @@ -372,8 +371,8 @@ def error(x): elif param_info == (True, True, 0): def error(x): rx, ry, rz, tx, ty, tz = x - trans = dot(translation(tx, ty, tz), rotation(rx, ry, rz)) - est = dot(src_pts, trans.T)[:, :3] + trans = np.dot(translation(tx, ty, tz), rotation(rx, ry, rz)) + est = np.dot(src_pts, trans.T)[:, :3] d = tgt_pts - est if weights is not None: d *= weights @@ -383,9 +382,10 @@ def error(x): elif param_info == (True, True, 1): def error(x): rx, ry, rz, tx, ty, tz, s = x - trans = reduce(dot, (translation(tx, ty, tz), rotation(rx, ry, rz), - scaling(s, s, s))) - est = dot(src_pts, trans.T)[:, :3] + trans = reduce(np.dot, (translation(tx, ty, tz), + rotation(rx, ry, rz), + scaling(s, s, s))) + est = np.dot(src_pts, trans.T)[:, :3] d = tgt_pts - est if weights is not None: d *= weights @@ -395,9 +395,10 @@ def error(x): elif param_info == (True, True, 3): def error(x): rx, ry, rz, tx, ty, tz, sx, sy, sz = x - trans = reduce(dot, (translation(tx, ty, tz), rotation(rx, ry, rz), - scaling(sx, sy, sz))) - est = dot(src_pts, trans.T)[:, :3] + trans = reduce(np.dot, (translation(tx, ty, tz), + rotation(rx, ry, rz), + scaling(sx, sy, sz))) + est = np.dot(src_pts, trans.T)[:, :3] d = tgt_pts - est if weights is not None: d *= weights @@ -419,7 +420,7 @@ def error(x): if tol is not None: if not translate: src_pts = np.hstack((src_pts, np.ones((len(src_pts), 1)))) - est_pts = dot(src_pts, trans.T)[:, :3] + est_pts = np.dot(src_pts, trans.T)[:, :3] err = np.sqrt(np.sum((est_pts - tgt_pts) ** 2, axis=1)) if np.any(err > tol): raise RuntimeError("Error exceeds tolerance. Error = %r" % err) diff --git a/mne/decoding/mixin.py b/mne/decoding/mixin.py index 6b25e1b8756..4ff3236a4cf 100644 --- a/mne/decoding/mixin.py +++ b/mne/decoding/mixin.py @@ -35,7 +35,7 @@ def fit_transform(self, X, y=None, **fit_params): class EstimatorMixin(object): """Mixin class for estimators.""" - def get_params(self): + def get_params(self, deep=True): """Get the estimator params.""" pass diff --git a/mne/io/base.py b/mne/io/base.py index f9b1ecd8a0a..70b162b4325 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -2278,7 +2278,7 @@ def _index_as_time(index, sfreq, first_samp=0, use_first_samp=False): return times / sfreq -class _RawShell(): +class _RawShell(object): """Create a temporary raw object.""" def __init__(self): # noqa: D102 diff --git a/mne/io/proc_history.py b/mne/io/proc_history.py index 8b46c61d40c..cb404cd3fbc 100644 --- a/mne/io/proc_history.py +++ b/mne/io/proc_history.py @@ -116,7 +116,7 @@ def _write_proc_history(fid, info): writer(fid, id_, record[key]) _write_maxfilter_record(fid, record['max_info']) if 'smartshield' in record: - for ss in record['smartshield']: + for _ in record['smartshield']: start_block(fid, FIFF.FIFFB_SMARTSHIELD) # XXX should eventually populate this end_block(fid, FIFF.FIFFB_SMARTSHIELD) diff --git a/mne/preprocessing/ctps_.py b/mne/preprocessing/ctps_.py index 5af631984f4..c70eff76940 100644 --- a/mne/preprocessing/ctps_.py +++ b/mne/preprocessing/ctps_.py @@ -58,7 +58,7 @@ def ctps(data, is_raw=True): Engineering, IEEE Transactions on 55 (10), 2353-2362. """ if not data.ndim == 3: - ValueError('Data must have 3 dimensions, not %i.' % data.ndim) + raise ValueError('Data must have 3 dimensions, not %i.' % data.ndim) if is_raw: phase_angles = _compute_normalized_phase(data) diff --git a/mne/preprocessing/ica.py b/mne/preprocessing/ica.py index 6c5b2bfaf7a..452b2a784f3 100644 --- a/mne/preprocessing/ica.py +++ b/mne/preprocessing/ica.py @@ -1270,13 +1270,10 @@ def find_bads_ref(self, inst, ch_name=None, threshold=3.0, start=None, -------- find_bads_ecg, find_bads_eog """ - if verbose is None: - verbose = self.verbose - if not ch_name: inds = pick_channels_regexp(inst.ch_names, "REF_ICA*") else: - inds = pick_channels(ch_name) + inds = pick_channels(inst.ch_names, ch_name) ref_chs = [inst.ch_names[k] for k in inds] self.labels_, scores = self._find_bads_ch( diff --git a/mne/preprocessing/maxfilter.py b/mne/preprocessing/maxfilter.py index f75f5d43e48..f5c90649d46 100644 --- a/mne/preprocessing/maxfilter.py +++ b/mne/preprocessing/maxfilter.py @@ -118,7 +118,7 @@ def apply_maxfilter(in_fname, out_fname, origin=None, frame='device', elif frame == 'device': origin = o_dev else: - RuntimeError('invalid frame for origin') + raise RuntimeError('invalid frame for origin') if not isinstance(origin, str): origin = '%0.1f %0.1f %0.1f' % (origin[0], origin[1], origin[2]) diff --git a/mne/transforms.py b/mne/transforms.py index 9fed0c4abd4..59f74c3aa7c 100644 --- a/mne/transforms.py +++ b/mne/transforms.py @@ -12,7 +12,6 @@ import numpy as np from copy import deepcopy -from numpy import sin, cos from scipy import linalg from .fixes import einsum @@ -247,12 +246,12 @@ def rotation(x=0, y=0, z=0): r : array, shape = (4, 4) The rotation matrix. """ - cos_x = cos(x) - cos_y = cos(y) - cos_z = cos(z) - sin_x = sin(x) - sin_y = sin(y) - sin_z = sin(z) + cos_x = np.cos(x) + cos_y = np.cos(y) + cos_z = np.cos(z) + sin_x = np.sin(x) + sin_y = np.sin(y) + sin_z = np.sin(z) r = np.array([[cos_y * cos_z, -cos_x * sin_z + sin_x * sin_y * cos_z, sin_x * sin_z + cos_x * sin_y * cos_z, 0], [cos_y * sin_z, cos_x * cos_z + sin_x * sin_y * sin_z, @@ -275,12 +274,12 @@ def rotation3d(x=0, y=0, z=0): r : array, shape = (3, 3) The rotation matrix. """ - cos_x = cos(x) - cos_y = cos(y) - cos_z = cos(z) - sin_x = sin(x) - sin_y = sin(y) - sin_z = sin(z) + cos_x = np.cos(x) + cos_y = np.cos(y) + cos_z = np.cos(z) + sin_x = np.sin(x) + sin_y = np.sin(y) + sin_z = np.sin(z) r = np.array([[cos_y * cos_z, -cos_x * sin_z + sin_x * sin_y * cos_z, sin_x * sin_z + cos_x * sin_y * cos_z], [cos_y * sin_z, cos_x * cos_z + sin_x * sin_y * sin_z, diff --git a/mne/viz/utils.py b/mne/viz/utils.py index 91a13c1378a..3507201d42f 100644 --- a/mne/viz/utils.py +++ b/mne/viz/utils.py @@ -2585,7 +2585,7 @@ def _check_time_unit(time_unit, times): if not isinstance(time_unit, str): raise TypeError('time_unit must be str, got %s' % (type(time_unit),)) if time_unit == 's': - times = times + pass elif time_unit == 'ms': times = 1e3 * times else: From 156298c1d0e7b54708c58c0e42ac16eb0ad3b107 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 10 Feb 2019 14:06:34 -0500 Subject: [PATCH 02/16] ENH: Skip JS tests --- .lgtm.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .lgtm.yml diff --git a/.lgtm.yml b/.lgtm.yml new file mode 100644 index 00000000000..5585247d22f --- /dev/null +++ b/.lgtm.yml @@ -0,0 +1,4 @@ +extraction: + javascript: + index: + exclude: ** From 33cbba78de90e477dab0ec24a665cbe276d1cad6 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 10 Feb 2019 14:18:19 -0500 Subject: [PATCH 03/16] FIX: LGTM fixes --- examples/visualization/plot_evoked_topomap.py | 1 + mne/datasets/sleep_physionet/_utils.py | 1 + mne/datasets/sleep_physionet/age.py | 1 + mne/datasets/sleep_physionet/temazepam.py | 1 + mne/preprocessing/ica.py | 15 ++------------- mne/tests/test_evoked.py | 5 +++-- mne/utils/mixin.py | 5 +++-- mne/viz/topomap.py | 4 ++-- setup.py | 4 +++- tutorials/plot_sleep.py | 2 ++ 10 files changed, 19 insertions(+), 20 deletions(-) diff --git a/examples/visualization/plot_evoked_topomap.py b/examples/visualization/plot_evoked_topomap.py index d7f658bb5f8..44c5a5bc851 100644 --- a/examples/visualization/plot_evoked_topomap.py +++ b/examples/visualization/plot_evoked_topomap.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ ======================================== Plotting topographic maps of evoked data diff --git a/mne/datasets/sleep_physionet/_utils.py b/mne/datasets/sleep_physionet/_utils.py index a517f332760..6fb08245835 100644 --- a/mne/datasets/sleep_physionet/_utils.py +++ b/mne/datasets/sleep_physionet/_utils.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Authors: Alexandre Gramfort # Joan Massich # diff --git a/mne/datasets/sleep_physionet/age.py b/mne/datasets/sleep_physionet/age.py index 7e22111005b..bd8e68b140f 100644 --- a/mne/datasets/sleep_physionet/age.py +++ b/mne/datasets/sleep_physionet/age.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Authors: Alexandre Gramfort # Joan Massich # diff --git a/mne/datasets/sleep_physionet/temazepam.py b/mne/datasets/sleep_physionet/temazepam.py index 1870320cee6..d5835a8da71 100644 --- a/mne/datasets/sleep_physionet/temazepam.py +++ b/mne/datasets/sleep_physionet/temazepam.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Authors: Alexandre Gramfort # Joan Massich # diff --git a/mne/preprocessing/ica.py b/mne/preprocessing/ica.py index 452b2a784f3..38397af19dc 100644 --- a/mne/preprocessing/ica.py +++ b/mne/preprocessing/ica.py @@ -999,11 +999,9 @@ def score_sources(self, inst, target=None, score_func='pearsonr', raise ValueError('Sources and target do not have the same' 'number of time slices.') # auto target selection - if verbose is None: - verbose = self.verbose if isinstance(inst, BaseRaw): sources, target = _band_pass_filter(self, sources, target, - l_freq, h_freq, verbose) + l_freq, h_freq) scores = _find_sources(sources, target, score_func) @@ -1160,17 +1158,11 @@ def find_bads_ecg(self, inst, ch_name=None, threshold=None, start=None, components of neuromagnetic recordings. Biomedical Engineering, IEEE Transactions on 55 (10), 2353-2362. """ - if verbose is None: - verbose = self.verbose - idx_ecg = _get_ecg_channel_index(ch_name, inst) if idx_ecg is None: - if verbose is not None: - verbose = self.verbose ecg, times = _make_ecg(inst, start, stop, - reject_by_annotation=reject_by_annotation, - verbose=verbose) + reject_by_annotation=reject_by_annotation) else: ecg = inst.ch_names[idx_ecg] @@ -1335,9 +1327,6 @@ def find_bads_eog(self, inst, ch_name=None, threshold=3.0, start=None, -------- find_bads_ecg, find_bads_ref """ - if verbose is None: - verbose = self.verbose - eog_inds = _get_eog_channel_index(ch_name, inst) if len(eog_inds) > 2: eog_inds = eog_inds[:1] diff --git a/mne/tests/test_evoked.py b/mne/tests/test_evoked.py index 96a171ea2b1..b7bc9d720d0 100644 --- a/mne/tests/test_evoked.py +++ b/mne/tests/test_evoked.py @@ -97,9 +97,10 @@ def test_hash_evoked(): """Test evoked hashing.""" ave = read_evokeds(fname, 0) ave_2 = read_evokeds(fname, 0) - assert_equal(hash(ave), hash(ave_2)) + assert hash(ave) == hash(ave_2) + assert ave == ave_2 # do NOT use assert_equal here, failing output is terrible - assert (pickle.dumps(ave) == pickle.dumps(ave_2)) + assert pickle.dumps(ave) == pickle.dumps(ave_2) ave_2.data[0, 0] -= 1 assert hash(ave) != hash(ave_2) diff --git a/mne/utils/mixin.py b/mne/utils/mixin.py index b0a87997f01..485db7663e5 100644 --- a/mne/utils/mixin.py +++ b/mne/utils/mixin.py @@ -24,6 +24,9 @@ class SizeMixin(object): """Estimate MNE object sizes.""" + def __eq__(self, other): + return isinstance(other, type(self)) and hash(self) == hash(other) + @property def _size(self): """Estimate the object size.""" @@ -322,8 +325,6 @@ def next(self, return_event_id=False): else: return epoch, self.events[self._current - 1][-1] - return epoch if not return_event_id else epoch, self.event_id - def __next__(self, *args, **kwargs): """Provide a wrapper for Py3k.""" return self.next(*args, **kwargs) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 0fec5b8a5aa..3d27bd44041 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -965,13 +965,13 @@ def _plot_ica_topomap(ica, idx=0, ch_type=None, res=64, layout=None, image_interp='bilinear', head_pos=None, axes=None, sensors=True, allow_ref_meg=False): """Plot single ica map to axes.""" - import matplotlib as mpl + from matplotlib.axes import Axes from ..channels import _get_ch_type if ica.info is None: raise RuntimeError('The ICA\'s measurement info is missing. Please ' 'fit the ICA or add the corresponding info object.') - if not isinstance(axes, mpl.axes.Axes): + if not isinstance(axes, Axes): raise ValueError('axis has to be an instance of matplotlib Axes, ' 'got %s instead.' % type(axes)) ch_type = _get_ch_type(ica, ch_type, allow_ref_meg=ica.allow_ref_meg) diff --git a/setup.py b/setup.py index 55e1ae086c9..a6a2a693b39 100755 --- a/setup.py +++ b/setup.py @@ -65,7 +65,9 @@ def package_tree(pkgroot): 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Operating System :: Unix', - 'Operating System :: MacOS'], + 'Operating System :: MacOS', + 'Programming Language :: Python :: 3', + ], platforms='any', packages=package_tree('mne'), package_data={'mne': [op.join('data', '*.sel'), diff --git a/tutorials/plot_sleep.py b/tutorials/plot_sleep.py index 17b7208b653..ac84254fa5d 100644 --- a/tutorials/plot_sleep.py +++ b/tutorials/plot_sleep.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ Sleep stage classification from polysomnography (PSG) data ========================================================== @@ -233,6 +234,7 @@ def eeg_power_band(epochs): return np.concatenate(X, axis=1) + ############################################################################## # Multiclass classification workflow using scikit-learn # ----------------------------------------------------- From e9eb5f6a58e99223940af44f55a82e46ce201dc5 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 10 Feb 2019 14:41:53 -0500 Subject: [PATCH 04/16] FIX: Exclude --- .lgtm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.lgtm.yml b/.lgtm.yml index 5585247d22f..65e46b52d23 100644 --- a/.lgtm.yml +++ b/.lgtm.yml @@ -1,4 +1,4 @@ extraction: javascript: index: - exclude: ** + - exclude: ** From 0ab1486241979fd4dc69bbe8c227483ab4119b74 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 10 Feb 2019 14:48:03 -0500 Subject: [PATCH 05/16] FIX: Exclude --- .lgtm.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.lgtm.yml b/.lgtm.yml index 65e46b52d23..c1a01bff38c 100644 --- a/.lgtm.yml +++ b/.lgtm.yml @@ -1,4 +1,5 @@ extraction: javascript: index: - - exclude: ** + filters: + - exclude: "**" From 23fac0e69a6d6c6baf6c399eda33655232362e32 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 10 Feb 2019 14:53:13 -0500 Subject: [PATCH 06/16] FIX: Really this time --- .lgtm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.lgtm.yml b/.lgtm.yml index c1a01bff38c..cb6f1b8d5f0 100644 --- a/.lgtm.yml +++ b/.lgtm.yml @@ -2,4 +2,4 @@ extraction: javascript: index: filters: - - exclude: "**" + - exclude: "**/*.js" From 78309c4e1fb747b375368cdbc7fb6e7dc55e1d88 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 10 Feb 2019 15:59:53 -0500 Subject: [PATCH 07/16] FIX: More fixes --- mne/decoding/mixin.py | 10 ++++++++-- mne/viz/_3d.py | 5 ++--- mne/viz/utils.py | 28 ++++++++++++++-------------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/mne/decoding/mixin.py b/mne/decoding/mixin.py index 4ff3236a4cf..f3e084a7bf8 100644 --- a/mne/decoding/mixin.py +++ b/mne/decoding/mixin.py @@ -36,8 +36,14 @@ class EstimatorMixin(object): """Mixin class for estimators.""" def get_params(self, deep=True): - """Get the estimator params.""" - pass + """Get the estimator params. + + Parameters + ---------- + deep : bool + Deep. + """ + return def set_params(self, **params): """Set parameters (mimics sklearn API).""" diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index 62940955090..fcca1a3ed24 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -301,9 +301,9 @@ def _pivot_kwargs(): if check_version('matplotlib', '1.5'): kwargs['pivot'] = 'tail' else: - import matplotlib + from matplotlib import __version__ warn('pivot cannot be set in matplotlib %s (need version 1.5+), ' - 'locations are approximate' % (matplotlib.__version__,)) + 'locations are approximate' % (__version__,)) return kwargs @@ -2039,7 +2039,6 @@ def _onclick(event, params): img = stc.as_volume(src, mri_resolution=False) - vmax = np.abs(stc.data).max() loc_idx, idx = np.unravel_index(np.abs(stc.data).argmax(), stc.data.shape) img_idx = index_img(img, idx) diff --git a/mne/viz/utils.py b/mne/viz/utils.py index 3507201d42f..7876dc55114 100644 --- a/mne/viz/utils.py +++ b/mne/viz/utils.py @@ -96,9 +96,9 @@ def plt_show(show=True, fig=None, **kwargs): **kwargs : dict Extra arguments for :func:`matplotlib.pyplot.show`. """ - import matplotlib + from matplotlib import get_backend import matplotlib.pyplot as plt - if show and matplotlib.get_backend() != 'agg': + if show and get_backend() != 'agg': (fig or plt).show(**kwargs) @@ -155,7 +155,7 @@ def _check_delayed_ssp(container): def _validate_if_list_of_axes(axes, obligatory_len=None): """Validate whether input is a list/array of axes.""" - import matplotlib as mpl + from matplotlib.axes import Axes if obligatory_len is not None and not isinstance(obligatory_len, int): raise ValueError('obligatory_len must be None or int, got %d', 'instead' % type(obligatory_len)) @@ -167,7 +167,7 @@ def _validate_if_list_of_axes(axes, obligatory_len=None): 'one-dimensional. The received numpy array has %d ' 'dimensions however. Try using ravel or flatten ' 'method of the array.' % axes.ndim) - is_correct_type = np.array([isinstance(x, mpl.axes.Axes) + is_correct_type = np.array([isinstance(x, Axes) for x in axes]) if not np.all(is_correct_type): first_bad = np.where(np.logical_not(is_correct_type))[0][0] @@ -833,7 +833,7 @@ def _plot_raw_onkey(event, params): def _setup_annotation_fig(params): """Initialize the annotation figure.""" - import matplotlib as mpl + from matplotlib import __version__ import matplotlib.pyplot as plt from matplotlib.widgets import RadioButtons, SpanSelector, Button if params['fig_annotation'] is not None: @@ -893,7 +893,7 @@ def _setup_annotation_fig(params): if len(labels) == 0: selector.active = False params['ax'].selector = selector - if LooseVersion(mpl.__version__) < LooseVersion('1.5'): + if LooseVersion(__version__) < LooseVersion('1.5'): # XXX: Hover event messes up callback ids in old mpl. warn('Modifying existing annotations is not possible for ' 'matplotlib versions < 1.4. Upgrade matplotlib.') @@ -1131,10 +1131,10 @@ class ClickableImage(object): def __init__(self, imdata, **kwargs): """Display the image for clicking.""" - from matplotlib.pyplot import figure + import matplotlib.pyplot as plt self.coords = [] self.imdata = imdata - self.fig = figure() + self.fig = plt.figure() self.ax = self.fig.add_subplot(111) self.ymax = self.imdata.shape[0] self.xmax = self.imdata.shape[1] @@ -1164,11 +1164,11 @@ def plot_clicks(self, **kwargs): **kwargs : dict Arguments are passed to imshow in displaying the bg image. """ - from matplotlib.pyplot import subplots + import matplotlib.pyplot as plt if len(self.coords) == 0: raise ValueError('No coordinates found, make sure you click ' 'on the image that is first shown.') - f, ax = subplots() + f, ax = plt.subplots() ax.imshow(self.imdata, extent=(0, self.xmax, 0, self.ymax), **kwargs) xlim, ylim = [ax.get_xlim(), ax.get_ylim()] xcoords, ycoords = zip(*self.coords) @@ -1819,8 +1819,8 @@ class SelectFromCollection(object): def __init__(self, ax, collection, ch_names, alpha_other=0.3): - import matplotlib as mpl - if LooseVersion(mpl.__version__) < LooseVersion('1.2.1'): + from matplotlib import __version__ + if LooseVersion(__version__) < LooseVersion('1.2.1'): raise ImportError('Interactive selection not possible for ' 'matplotlib versions < 1.2.1. Upgrade ' 'matplotlib.') @@ -1983,7 +1983,7 @@ def _setup_annotation_colors(params): def _annotations_closed(event, params): """Clean up on annotation dialog close.""" - import matplotlib as mpl + from matplotlib import __version__ import matplotlib.pyplot as plt plt.close(params['fig_annotation']) if params['ax'].selector is not None: @@ -1993,7 +1993,7 @@ def _annotations_closed(event, params): if params['segment_line'] is not None: params['segment_line'].remove() params['segment_line'] = None - if LooseVersion(mpl.__version__) >= LooseVersion('1.5'): + if LooseVersion(__version__) >= LooseVersion('1.5'): params['fig'].canvas.mpl_disconnect(params['hover_callback']) params['fig_annotation'] = None params['fig'].canvas.draw() From cbe41b52fc8a610f5d73b7ebbeeb17d85af563eb Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 10 Feb 2019 17:22:53 -0500 Subject: [PATCH 08/16] FIX: More --- .lgtm.yml | 4 ++++ logo/generate_mne_logos.py | 1 - mne/annotations.py | 1 - mne/bem.py | 1 - mne/cov.py | 3 --- mne/datasets/hf_sef/hf_sef.py | 2 +- mne/datasets/megsim/megsim.py | 2 +- mne/fixes.py | 6 +----- mne/forward/_lead_dots.py | 16 +++++++--------- mne/forward/_make_forward.py | 5 ++--- mne/gui/_coreg_gui.py | 28 +++++++++------------------- mne/inverse_sparse/mxne_optim.py | 3 +-- mne/io/base.py | 1 - mne/io/ctf/ctf.py | 5 ++--- mne/io/edf/edf.py | 3 ++- mne/io/egi/egimff.py | 6 ++++-- mne/io/kit/kit.py | 6 ++++-- mne/label.py | 14 ++++++-------- mne/minimum_norm/inverse.py | 2 -- mne/minimum_norm/time_frequency.py | 1 - mne/preprocessing/maxwell.py | 1 - mne/preprocessing/peak_finder.py | 2 +- mne/preprocessing/xdawn.py | 4 ++-- mne/source_space.py | 3 --- mne/transforms.py | 10 ++++------ mne/utils/mixin.py | 12 ++++++++++++ mne/viz/_3d.py | 4 +--- mne/viz/circle.py | 2 +- mne/viz/evoked.py | 2 +- mne/viz/topomap.py | 16 +++++++++------- 30 files changed, 75 insertions(+), 91 deletions(-) diff --git a/.lgtm.yml b/.lgtm.yml index cb6f1b8d5f0..9a892ff4ed3 100644 --- a/.lgtm.yml +++ b/.lgtm.yml @@ -1,4 +1,8 @@ extraction: + python: + index: + filters: + - exclude: "mne/externals/**.py" javascript: index: filters: diff --git a/logo/generate_mne_logos.py b/logo/generate_mne_logos.py index 062e7a06ada..373a41fda12 100644 --- a/logo/generate_mne_logos.py +++ b/logo/generate_mne_logos.py @@ -19,7 +19,6 @@ from matplotlib.text import TextPath from matplotlib.patches import PathPatch from matplotlib.colors import LinearSegmentedColormap -from matplotlib.transforms import Bbox # manually set values dpi = 72. diff --git a/mne/annotations.py b/mne/annotations.py index d8e44a297b7..7899d12d555 100644 --- a/mne/annotations.py +++ b/mne/annotations.py @@ -672,7 +672,6 @@ def get_duration_from_times(t): def _is_iso8601(candidate_str): - import re ISO8601 = r'^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}\.\d{6}$' return re.compile(ISO8601).match(candidate_str) is not None diff --git a/mne/bem.py b/mne/bem.py index de9e1a456ad..ed0ffe6af45 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -475,7 +475,6 @@ def _surfaces_to_bem(surfs, ids, sigmas, ico=None, rescale=True, len(sigmas)): raise ValueError('surfs, ids, and sigmas must all have the same ' 'number of elements (1 or 3)') - surf = list(surfs) for si, surf in enumerate(surfs): if isinstance(surf, str): surfs[si] = read_surface(surf, return_dict=True)[-1] diff --git a/mne/cov.py b/mne/cov.py index f5ab5eecabc..6ed4595207f 100644 --- a/mne/cov.py +++ b/mne/cov.py @@ -1095,9 +1095,6 @@ def _compute_covariance_auto(data, method, info, method_params, cv, name = method_.__name__ if callable(method_) else method_ out[name] = dict(loglik=loglik, data=cov, estimator=estimator) out[name].update(runtime_info) - # undo scaling - if eigvec is not None: - data = np.dot(data, eigvec) return out diff --git a/mne/datasets/hf_sef/hf_sef.py b/mne/datasets/hf_sef/hf_sef.py index fd44644646b..9af4ef63487 100644 --- a/mne/datasets/hf_sef/hf_sef.py +++ b/mne/datasets/hf_sef/hf_sef.py @@ -95,5 +95,5 @@ def data_path(dataset='evoked', path=None, force_update=False, os.remove(archive) - path = _do_path_update(path, update_path, key, name) + _do_path_update(path, update_path, key, name) return destdir diff --git a/mne/datasets/megsim/megsim.py b/mne/datasets/megsim/megsim.py index 006538ee084..575d30d4796 100644 --- a/mne/datasets/megsim/megsim.py +++ b/mne/datasets/megsim/megsim.py @@ -96,7 +96,7 @@ def data_path(url, path=None, force_update=False, update_path=None, z.close() destinations = [op.join(decomp_dir, f) for f in files] - path = _do_path_update(path, update_path, key, name) + _do_path_update(path, update_path, key, name) return destinations diff --git a/mne/fixes.py b/mne/fixes.py index 5a84d445bd6..83679176052 100644 --- a/mne/fixes.py +++ b/mne/fixes.py @@ -638,10 +638,6 @@ class BaseEstimator(object): @classmethod def _get_param_names(cls): """Get parameter names for the estimator""" - try: - from inspect import signature - except ImportError: - from .externals.funcsigs import signature # fetch the constructor or the original constructor before # deprecation wrapping if any init = getattr(cls.__init__, 'deprecated_original', cls.__init__) @@ -651,7 +647,7 @@ def _get_param_names(cls): # introspect the constructor arguments to find the model parameters # to represent - init_signature = signature(init) + init_signature = inspect.signature(init) # Consider the constructor parameters excluding 'self' parameters = [p for p in init_signature.parameters.values() if p.name != 'self' and p.kind != p.VAR_KEYWORD] diff --git a/mne/forward/_lead_dots.py b/mne/forward/_lead_dots.py index 75d39429ce1..e2a9da728ca 100644 --- a/mne/forward/_lead_dots.py +++ b/mne/forward/_lead_dots.py @@ -4,8 +4,7 @@ # # License: BSD (3-clause) -import os -from os import path as op +from os import path as op, makedirs import numpy as np from numpy.polynomial import legendre @@ -21,12 +20,11 @@ def _next_legen_der(n, x, p0, p01, p0d, p0dd): """Compute the next Legendre polynomial and its derivatives.""" # only good for n > 1 ! - help_ = p0 - helpd = p0d - p0 = ((2 * n - 1) * x * help_ - (n - 1) * p01) / n - p0d = n * help_ + x * helpd - p0dd = (n + 1) * helpd + x * p0dd - p01 = help_ + old_p0 = p0 + old_p0d = p0d + p0 = ((2 * n - 1) * x * old_p0 - (n - 1) * p01) / n + p0d = n * old_p0 + x * old_p0d + p0dd = (n + 1) * old_p0d + x * p0dd return p0, p0d, p0dd @@ -58,7 +56,7 @@ def _get_legen_table(ch_type, volume_integral=False, n_coeff=100, fname = op.join(_get_extra_data_path(), 'tables') if not op.isdir(fname): # Updated due to API chang (GH 1167) - os.makedirs(fname) + makedirs(fname) if ch_type == 'meg': fname = op.join(fname, 'legder_%s_%s.bin' % (n_coeff, n_interp)) leg_fun = _get_legen_der diff --git a/mne/forward/_make_forward.py b/mne/forward/_make_forward.py index a2bf70becdc..7396d792e47 100644 --- a/mne/forward/_make_forward.py +++ b/mne/forward/_make_forward.py @@ -7,8 +7,7 @@ from copy import deepcopy import contextlib -import os -from os import path as op +from os import path as op, getcwd import numpy as np @@ -449,7 +448,7 @@ def _prepare_for_forward(src, mri_head_t, info, bem, mindist, n_jobs, info = Info(chs=info['chs'], comps=info['comps'], dev_head_t=info['dev_head_t'], mri_file=trans, mri_id=mri_id, - meas_file=info_extra, meas_id=None, working_dir=os.getcwd(), + meas_file=info_extra, meas_id=None, working_dir=getcwd(), command_line=cmd, bads=info['bads'], mri_head_t=mri_head_t) info._update_redundant() info._check_consistency() diff --git a/mne/gui/_coreg_gui.py b/mne/gui/_coreg_gui.py index af58ed72dc6..000bef778c1 100644 --- a/mne/gui/_coreg_gui.py +++ b/mne/gui/_coreg_gui.py @@ -391,37 +391,27 @@ def _get_head_mri_t(self): @cached_property def _get_processed_high_res_mri_points(self): - if self.grow_hair: - if len(self.mri.bem_high_res.surf.nn): - scaled_hair_dist = (1e-3 * self.grow_hair / - np.array(self.parameters[6:9])) - points = self.mri.bem_high_res.surf.rr.copy() - hair = points[:, 2] > points[:, 1] - points[hair] += (self.mri.bem_high_res.surf.nn[hair] * - scaled_hair_dist) - return points - else: - error(None, "Norms missing from bem, can't grow hair") - self.grow_hair = 0 - else: - return self.mri.bem_high_res.surf.rr + self._get_processed_mri_points(self, 'high') @cached_property def _get_processed_low_res_mri_points(self): + self._get_processed_mri_points(self, 'low') + + def _get_processed_mri_points(self, res): + bem = self.mri.bem_low_res if res == 'low' else self.mri.bem_high_res if self.grow_hair: - if len(self.mri.bem_low_res.surf.nn): + if len(bem.surf.nn): scaled_hair_dist = (1e-3 * self.grow_hair / np.array(self.parameters[6:9])) - points = self.mri.bem_low_res.surf.rr.copy() + points = bem.surf.rr.copy() hair = points[:, 2] > points[:, 1] - points[hair] += (self.mri.bem_low_res.surf.nn[hair] * - scaled_hair_dist) + points[hair] += bem.surf.nn[hair] * scaled_hair_dist return points else: error(None, "Norms missing from bem, can't grow hair") self.grow_hair = 0 else: - return self.mri.bem_low_res.surf.rr + return bem.surf.rr @cached_property def _get_mri_trans(self): diff --git a/mne/inverse_sparse/mxne_optim.py b/mne/inverse_sparse/mxne_optim.py index a5e70e380ba..939afbb3cca 100644 --- a/mne/inverse_sparse/mxne_optim.py +++ b/mne/inverse_sparse/mxne_optim.py @@ -296,8 +296,7 @@ def _mixed_norm_solver_cd(M, G, alpha, lipschitz_constant, maxit=10000, """Solve L21 inverse problem with coordinate descent.""" from sklearn.linear_model.coordinate_descent import MultiTaskLasso - n_sensors, n_times = M.shape - n_sensors, n_sources = G.shape + assert M.ndim == G.ndim and M.shape[0] == G.shape[0] clf = MultiTaskLasso(alpha=alpha / len(M), tol=tol / sum_squared(M), normalize=False, fit_intercept=False, max_iter=maxit, diff --git a/mne/io/base.py b/mne/io/base.py index 70b162b4325..fd14a3ce752 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -2707,7 +2707,6 @@ def _check_maxshield(allow_maxshield): if not (isinstance(allow_maxshield, str) and allow_maxshield == 'yes'): warn(msg) - allow_maxshield = 'yes' else: msg += (' Use allow_maxshield=True if you are sure you' ' want to load the data despite this warning.') diff --git a/mne/io/ctf/ctf.py b/mne/io/ctf/ctf.py index 635eb8350e8..245245b20b0 100644 --- a/mne/io/ctf/ctf.py +++ b/mne/io/ctf/ctf.py @@ -4,8 +4,7 @@ # # License: BSD (3-clause) -import os -from os import path as op +from os import path as op, SEEK_END import numpy as np @@ -204,7 +203,7 @@ def _get_sample_info(fname, res4, system_clock): clock_ch = k break with open(fname, 'rb') as fid: - fid.seek(0, os.SEEK_END) + fid.seek(0, SEEK_END) st_size = fid.tell() fid.seek(0, 0) if (st_size - CTF.HEADER_SIZE) % (4 * res4['nsamp'] * diff --git a/mne/io/edf/edf.py b/mne/io/edf/edf.py index 8550bb1b8e1..bc6170dc9f1 100644 --- a/mne/io/edf/edf.py +++ b/mne/io/edf/edf.py @@ -621,7 +621,8 @@ def _read_edf_header(fname, exclude): warn('Number of records from the header does not match the file ' 'size (perhaps the recording was not stopped before exiting).' ' Inferring from the file size.') - edf_info['n_records'] = n_records = read_records + edf_info['n_records'] = read_records + del n_records if subtype == 'bdf': edf_info['dtype_byte'] = 3 # 24-bit (3 byte) integers diff --git a/mne/io/egi/egimff.py b/mne/io/egi/egimff.py index 938d881ef54..dc7392e3df8 100644 --- a/mne/io/egi/egimff.py +++ b/mne/io/egi/egimff.py @@ -82,7 +82,8 @@ def _read_mff_header(filepath): pns_types = [] pns_units = [] for sensor in sensors: - sn = sensor.getElementsByTagName('number')[0].firstChild.data + # sensor number: + # sensor.getElementsByTagName('number')[0].firstChild.data name = sensor.getElementsByTagName('name')[0].firstChild.data unit_elem = sensor.getElementsByTagName('unit')[0].firstChild unit = '' @@ -578,7 +579,7 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult): if samples_to_read == 1 and fid.tell() == file_size: # We are in the presence of the EEG bug # fill with zeros and break the loop - data_view = data[n_data1_channels:, -1] = 0 + data[n_data1_channels:, -1] = 0 warn('This file has the EGI PSG sample bug') an_start = current_data_sample # XXX : use of _sync_onset should live in annotations @@ -615,5 +616,6 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult): _mult_cal_one(data_view, block_data[:n_pns_channels], pns_idx, cals[n_data1_channels:], mult) + del data_view samples_to_read = samples_to_read - samples_read current_data_sample = current_data_sample + samples_read diff --git a/mne/io/kit/kit.py b/mne/io/kit/kit.py index f9e51b69977..414b90ba353 100644 --- a/mne/io/kit/kit.py +++ b/mne/io/kit/kit.py @@ -652,7 +652,8 @@ def get_kit_info(rawfile, allow_unknown_format): }) elif channel_type in KIT.CHANNELS_MISC: channel_no, = unpack('i', fid.read(KIT.INT)) - name, = unpack('64s', fid.read(64)) + # name, = unpack('64s', fid.read(64)) + fid.seek(64, 1) channels.append({ 'type': channel_type, 'no': channel_no, @@ -710,7 +711,8 @@ def get_kit_info(rawfile, allow_unknown_format): sqd['acq_type'], = acq_type, = unpack('i', fid.read(KIT.INT)) sqd['sfreq'], = unpack('d', fid.read(KIT.DOUBLE)) if acq_type == KIT.CONTINUOUS: - samples_count, = unpack('i', fid.read(KIT.INT)) + # samples_count, = unpack('i', fid.read(KIT.INT)) + fid.seek(KIT.INT, 1) sqd['n_samples'], = unpack('i', fid.read(KIT.INT)) elif acq_type == KIT.EVOKED or acq_type == KIT.EPOCHS: sqd['frame_length'], = unpack('i', fid.read(KIT.INT)) diff --git a/mne/label.py b/mne/label.py index 55d1d64ea27..94eac0ddfaf 100644 --- a/mne/label.py +++ b/mne/label.py @@ -6,8 +6,7 @@ from collections import defaultdict from colorsys import hsv_to_rgb, rgb_to_hsv -from os import path as op -import os +from os import path as op, linesep, listdir import copy as cp import re @@ -1849,7 +1848,7 @@ def _read_annot(fname): if not op.isdir(dir_name): raise IOError('Directory for annotation does not exist: %s', fname) - cands = os.listdir(dir_name) + cands = listdir(dir_name) cands = [c for c in cands if '.annot' in c] if len(cands) == 0: raise IOError('No such file %s, no candidate parcellations ' @@ -1867,8 +1866,7 @@ def _read_annot(fname): n_entries = np.fromfile(fid, '>i4', 1)[0] if n_entries > 0: length = np.fromfile(fid, '>i4', 1)[0] - orig_tab = np.fromfile(fid, '>c', length) - orig_tab = orig_tab[:-1] + np.fromfile(fid, '>c', length) # discard orig_tab names = list() ctab = np.zeros((n_entries, 5), np.int) @@ -2434,18 +2432,18 @@ def write_labels_to_annot(labels, subject=None, parc=None, overwrite=False, msg = ("Some labels have the same color values (all labels in one " "hemisphere must have a unique color):") duplicate_colors.insert(0, msg) - issues.append(os.linesep.join(duplicate_colors)) + issues.append(linesep.join(duplicate_colors)) if invalid_colors: msg = ("Some labels have invalid color values (all colors should be " "RGBA tuples with values between 0 and 1)") invalid_colors.insert(0, msg) - issues.append(os.linesep.join(invalid_colors)) + issues.append(linesep.join(invalid_colors)) if overlap: msg = ("Some labels occupy vertices that are also occupied by one or " "more other labels. Each vertex can only be occupied by a " "single label in *.annot files.") overlap.insert(0, msg) - issues.append(os.linesep.join(overlap)) + issues.append(linesep.join(overlap)) if issues: raise ValueError('\n\n'.join(issues)) diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index 46ff390194c..e7f194b5d61 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -449,8 +449,6 @@ def combine_xyz(vec, square=False): raise ValueError('Input must be 2D') if (vec.shape[0] % 3) != 0: raise ValueError('Input must have 3N rows') - - n, p = vec.shape if np.iscomplexobj(vec): vec = np.abs(vec) comb = vec[0::3] ** 2 diff --git a/mne/minimum_norm/time_frequency.py b/mne/minimum_norm/time_frequency.py index c67beca17a5..895b42b5158 100644 --- a/mne/minimum_norm/time_frequency.py +++ b/mne/minimum_norm/time_frequency.py @@ -189,7 +189,6 @@ def _compute_pow_plv(data, K, sel, Ws, source_ori, use_fft, Vh, with_power, with_plv, pick_ori, decim, verbose=None): """Aux function for induced power and PLV.""" shape, is_free_ori = _prepare_tfr(data, decim, pick_ori, Ws, K, source_ori) - n_sources, n_times = shape[:2] power = np.zeros(shape, dtype=np.float) # power or raw TFR # phase lock plv = np.zeros(shape, dtype=np.complex) if with_plv else None diff --git a/mne/preprocessing/maxwell.py b/mne/preprocessing/maxwell.py index cb827ffa703..d2e188f123c 100644 --- a/mne/preprocessing/maxwell.py +++ b/mne/preprocessing/maxwell.py @@ -359,7 +359,6 @@ def maxwell_filter(raw, origin='auto', int_order=8, ext_order=3, orig_origin, orig_coord_frame = origin, coord_frame del origin, coord_frame origin_head.setflags(write=False) - n_in, n_out = _get_n_moments([int_order, ext_order]) # # Cross-talk processing diff --git a/mne/preprocessing/peak_finder.py b/mne/preprocessing/peak_finder.py index 66ad3bc18e7..022ffa2eb5c 100644 --- a/mne/preprocessing/peak_finder.py +++ b/mne/preprocessing/peak_finder.py @@ -71,6 +71,7 @@ def peak_finder(x0, thresh=None, extrema=1, verbose=None): # Include endpoints in potential peaks and valleys x = np.concatenate((x0[:1], x0[ind], x0[-1:])) ind = np.concatenate(([0], ind, [s - 1])) + del x0 # x only has the peaks, valleys, and endpoints length = x.size @@ -163,7 +164,6 @@ def peak_finder(x0, thresh=None, extrema=1, verbose=None): # Change sign of data if was finding minima if extrema < 0: peak_mags *= -1.0 - x0 = -x0 # ensure output type array if not isinstance(peak_inds, np.ndarray): diff --git a/mne/preprocessing/xdawn.py b/mne/preprocessing/xdawn.py index 14ca9f8094f..e184a9f9319 100644 --- a/mne/preprocessing/xdawn.py +++ b/mne/preprocessing/xdawn.py @@ -142,7 +142,8 @@ def _fit_xdawn(epochs_data, y, n_components, reg=None, signal_cov=None, evokeds : array, shape (n_class, n_components, n_times) The independent evoked responses per condition. """ - n_epochs, n_channels, n_times = epochs_data.shape + if not isinstance(epochs_data, np.ndarray) or epochs_data.ndim != 3: + raise ValueError('epochs_data must be 3D ndarray') classes = np.unique(y) @@ -317,7 +318,6 @@ def inverse_transform(self, X): """ # Check size X, _ = self._check_Xy(X) - n_components, n_channels = self.patterns_.shape n_epochs, n_comp, n_times = X.shape if n_comp != (self.n_components * len(self.classes_)): raise ValueError('X must have %i components, got %i instead' % ( diff --git a/mne/source_space.py b/mne/source_space.py index 13aafb3fc00..55cecdab2de 100644 --- a/mne/source_space.py +++ b/mne/source_space.py @@ -2530,9 +2530,6 @@ def get_volume_labels_from_src(src, subject, subjects_dir): List of Label of segmented volumes included in src space. """ - import os.path as op - import numpy as np - from . import Label from . import get_volume_labels_from_aseg diff --git a/mne/transforms.py b/mne/transforms.py index 59f74c3aa7c..0ef9664e483 100644 --- a/mne/transforms.py +++ b/mne/transforms.py @@ -6,8 +6,7 @@ # # License: BSD (3-clause) -import os -from os import path as op +from os import path as op, environ import glob import numpy as np @@ -185,13 +184,12 @@ def _print_coord_trans(t, prefix='Coordinate transformation: '): def _find_trans(subject, subjects_dir=None): if subject is None: - if 'SUBJECT' in os.environ: - subject = os.environ['SUBJECT'] + if 'SUBJECT' in environ: + subject = environ['SUBJECT'] else: raise ValueError('SUBJECT environment variable not set') - trans_fnames = glob.glob(os.path.join(subjects_dir, subject, - '*-trans.fif')) + trans_fnames = glob.glob(op.join(subjects_dir, subject, '*-trans.fif')) if len(trans_fnames) < 1: raise RuntimeError('Could not find the transformation for ' '{subject}'.format(subject=subject)) diff --git a/mne/utils/mixin.py b/mne/utils/mixin.py index 485db7663e5..64ec85177cb 100644 --- a/mne/utils/mixin.py +++ b/mne/utils/mixin.py @@ -25,6 +25,18 @@ class SizeMixin(object): """Estimate MNE object sizes.""" def __eq__(self, other): + """Compare self to other. + + Parameters + ---------- + other : object + The object to compare to. + + Returns + ------- + eq : bool + True if the two objects are equal. + """ return isinstance(other, type(self)) and hash(self) == hash(other) @property diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index fcca1a3ed24..4b3e9605a65 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -335,13 +335,12 @@ def plot_evoked_field(evoked, surf_maps, time=None, time_label='t = %0.0f ms', time_idx = None if time is None: time = np.mean([evoked.get_peak(ch_type=t)[1] for t in types]) + del types if not evoked.times[0] <= time <= evoked.times[-1]: raise ValueError('`time` (%0.3f) must be inside `evoked.times`' % time) time_idx = np.argmin(np.abs(evoked.times - time)) - types = [sm['kind'] for sm in surf_maps] - # Plot them mlab = _import_mlab() alphas = [1.0, 0.5] @@ -2013,7 +2012,6 @@ def _onclick(event, params): elif mode == 'glass_brain': cut_coords = _get_cut_coords_glass_brain(event, params) - x, y, z = cut_coords ax_x.clear() ax_y.clear() ax_z.clear() diff --git a/mne/viz/circle.py b/mne/viz/circle.py index e4c43c647a8..230f15d27a0 100644 --- a/mne/viz/circle.py +++ b/mne/viz/circle.py @@ -311,7 +311,7 @@ def plot_connectivity_circle(con, node_names, indices=None, n_lines=None, # now sort them sort_idx = np.argsort(con_abs) - con_abs = con_abs[sort_idx] + del con_abs con = con[sort_idx] indices = [ind[sort_idx] for ind in indices] diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index 76145d409d9..16f2bf3e449 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -1324,7 +1324,7 @@ def plot_evoked_joint(evoked, times="peaks", title='', picks=None, raise TypeError('ts_args must be dict or None, got type %s' % (type(ts_args),)) ts_args = dict() if ts_args is None else ts_args.copy() - ts_args['time_unit'], evoked_times = _check_time_unit( + ts_args['time_unit'], _ = _check_time_unit( ts_args.get('time_unit', 's'), evoked.times) if topomap_args is None: topomap_args = dict() diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 3d27bd44041..eb997519941 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -815,7 +815,7 @@ def _plot_topomap(data, pos, vmin=None, vmax=None, cmap=None, sensors=True, if _use_default_outlines: # prepare masking - pos = _autoshrink(outlines, pos, res) + _autoshrink(outlines, pos, res) mask_params = _handle_default('mask_params', mask_params) @@ -927,7 +927,10 @@ def _show_names(x): def _autoshrink(outlines, pos, res): - """Shrink channel positions until all are within the mask contour.""" + """Shrink channel positions until all are within the mask contour. + + Operates on `pos` inplace. + """ if outlines.get('autoshrink', False): mask_ = np.c_[outlines['mask_pos']] inside = _inside_contour(pos, mask_) @@ -938,7 +941,6 @@ def _autoshrink(outlines, pos, res): inside = _inside_contour(pos, mask_) outside = np.invert(inside) outlier_points = pos[outside] - return pos def _inside_contour(pos, contour): @@ -985,7 +987,7 @@ def _plot_ica_topomap(ica, idx=0, ch_type=None, res=64, layout=None, pos, outlines = _check_outlines(pos, outlines, head_pos) assert outlines is not None if outlines != 'head': - pos = _autoshrink(outlines, pos, res) + _autoshrink(outlines, pos, res) data = data[data_picks] @@ -1145,7 +1147,7 @@ def plot_ica_components(ica, picks=None, ch_type=None, res=64, layout) pos, outlines = _check_outlines(pos, outlines, head_pos) if outlines == 'head': - pos = _autoshrink(outlines, pos, res) + _autoshrink(outlines, pos, res) data = np.atleast_2d(data) data = data[:, data_picks] @@ -1726,7 +1728,7 @@ def plot_evoked_topomap(evoked, times="auto", ch_type=None, layout=None, pos, outlines = _check_outlines(pos, outlines, head_pos) assert outlines is not None - pos = _autoshrink(outlines, pos, res) + _autoshrink(outlines, pos, res) vlims = [_setup_vmin_vmax(data[:, i], vmin, vmax, norm=merge_grads) for i in range(len(times))] @@ -2279,7 +2281,7 @@ def _init_anim(ax, ax_line, ax_cbar, params, merge_grads): zi_min = np.nanmin(params['Zis']) zi_max = np.nanmax(params['Zis']) cont_lims = np.linspace(zi_min, zi_max, 7, endpoint=False)[1:] - pos = _autoshrink(outlines, pos, res) + _autoshrink(outlines, pos, res) params.update({'vmin': vmin, 'vmax': vmax, 'Xi': Xi, 'Yi': Yi, 'Zi': Zi, 'extent': (xmin, xmax, ymin, ymax), 'cmap': cmap, 'cont_lims': cont_lims}) From a10acb561dfde50377cd5fc24a1881d502545806 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 10 Feb 2019 21:22:11 -0500 Subject: [PATCH 09/16] FIX: Fix bug --- mne/gui/_coreg_gui.py | 4 +-- mne/io/base.py | 3 ++- setup.py | 58 +++++++++++++++++++++---------------------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/mne/gui/_coreg_gui.py b/mne/gui/_coreg_gui.py index 000bef778c1..7ebbe9a3435 100644 --- a/mne/gui/_coreg_gui.py +++ b/mne/gui/_coreg_gui.py @@ -391,11 +391,11 @@ def _get_head_mri_t(self): @cached_property def _get_processed_high_res_mri_points(self): - self._get_processed_mri_points(self, 'high') + return self._get_processed_mri_points('high') @cached_property def _get_processed_low_res_mri_points(self): - self._get_processed_mri_points(self, 'low') + return self._get_processed_mri_points('low') def _get_processed_mri_points(self, res): bem = self.mri.bem_low_res if res == 'low' else self.mri.bem_high_res diff --git a/mne/io/base.py b/mne/io/base.py index fd14a3ce752..834e7928c87 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -691,7 +691,8 @@ def last_samp(self): def _last_time(self): return self.last_samp / float(self.info['sfreq']) - def time_as_index(self, times, use_rounding=False, origin=None): + # "Overridden method signature does not match call..." in LGTM + def time_as_index(self, times, use_rounding=False, origin=None): # lgtm """Convert time to indices. Parameters diff --git a/setup.py b/setup.py index a6a2a693b39..e89ca4ad7a1 100755 --- a/setup.py +++ b/setup.py @@ -1,17 +1,15 @@ #! /usr/bin/env python -# # Copyright (C) 2011-2017 Alexandre Gramfort # -import os -from os import path as op +from os import path as op, remove, walk from setuptools import setup # get the version (don't import mne here, so dependencies are not needed) version = None -with open(os.path.join('mne', '__init__.py'), 'r') as fid: +with open(op.join('mne', '__init__.py'), 'r') as fid: for line in (line.strip() for line in fid): if line.startswith('__version__'): version = line.split('=')[1].strip().strip('\'') @@ -35,15 +33,16 @@ def package_tree(pkgroot): """Get the submodule list.""" # Adapted from VisPy - path = os.path.dirname(__file__) - subdirs = [os.path.relpath(i[0], path).replace(os.path.sep, '.') - for i in os.walk(os.path.join(path, pkgroot)) + path = op.dirname(__file__) + subdirs = [op.relpath(i[0], path).replace(op.sep, '.') + for i in walk(op.join(path, pkgroot)) if '__init__.py' in i[2]] return sorted(subdirs) + if __name__ == "__main__": - if os.path.exists('MANIFEST'): - os.remove('MANIFEST') + if op.exists('MANIFEST'): + remove('MANIFEST') setup(name=DISTNAME, maintainer=MAINTAINER, @@ -70,24 +69,25 @@ def package_tree(pkgroot): ], platforms='any', packages=package_tree('mne'), - package_data={'mne': [op.join('data', '*.sel'), - op.join('data', 'icos.fif.gz'), - op.join('data', 'coil_def*.dat'), - op.join('data', 'helmets', '*.fif.gz'), - op.join('data', 'FreeSurferColorLUT.txt'), - op.join('data', 'image', '*gif'), - op.join('data', 'image', '*lout'), - op.join('data', 'fsaverage', '*.fif'), - op.join('channels', 'data', 'layouts', '*.lout'), - op.join('channels', 'data', 'layouts', '*.lay'), - op.join('channels', 'data', 'montages', '*.sfp'), - op.join('channels', 'data', 'montages', '*.txt'), - op.join('channels', 'data', 'montages', '*.elc'), - op.join('channels', 'data', 'neighbors', '*.mat'), - op.join('gui', 'help', '*.json'), - op.join('html', '*.js'), - op.join('html', '*.css'), - op.join('io', 'artemis123', 'resources', '*.csv'), - op.join('io', 'edf', 'gdf_encodes.txt') - ]}, + package_data={'mne': [ + op.join('data', '*.sel'), + op.join('data', 'icos.fif.gz'), + op.join('data', 'coil_def*.dat'), + op.join('data', 'helmets', '*.fif.gz'), + op.join('data', 'FreeSurferColorLUT.txt'), + op.join('data', 'image', '*gif'), + op.join('data', 'image', '*lout'), + op.join('data', 'fsaverage', '*.fif'), + op.join('channels', 'data', 'layouts', '*.lout'), + op.join('channels', 'data', 'layouts', '*.lay'), + op.join('channels', 'data', 'montages', '*.sfp'), + op.join('channels', 'data', 'montages', '*.txt'), + op.join('channels', 'data', 'montages', '*.elc'), + op.join('channels', 'data', 'neighbors', '*.mat'), + op.join('gui', 'help', '*.json'), + op.join('html', '*.js'), + op.join('html', '*.css'), + op.join('io', 'artemis123', 'resources', '*.csv'), + op.join('io', 'edf', 'gdf_encodes.txt') + ]}, scripts=['bin/mne']) From d0af970a082c5fe744a945fabec8a9dd73a7fc15 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 10 Feb 2019 22:12:58 -0500 Subject: [PATCH 10/16] FIX: __iter__ should return self, __next__ raise StopIteration --- mne/epochs.py | 10 ++++++---- mne/evoked.py | 3 ++- mne/io/base.py | 2 +- mne/morph.py | 12 ++++++------ mne/preprocessing/tests/test_ssp.py | 1 + mne/time_frequency/tfr.py | 7 ++++--- mne/utils/mixin.py | 16 +++++----------- mne/viz/tests/test_3d.py | 1 + mne/viz/tests/test_topomap.py | 1 + tutorials/plot_info.py | 11 ++++++----- 10 files changed, 33 insertions(+), 31 deletions(-) diff --git a/mne/epochs.py b/mne/epochs.py index 0d50ee853a8..f5af27c4ef6 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -168,7 +168,8 @@ def _save_split(epochs, fname, part_idx, n_parts, fmt): class BaseEpochs(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin, InterpolationMixin, FilterMixin, - ToDataFrameMixin, TimeMixin, SizeMixin, GetEpochsMixin): + ToDataFrameMixin, TimeMixin, SizeMixin, + GetEpochsMixin): # lgtm[py/missing-equals] """Abstract base class for Epochs-type classes. This class provides basic functionality and should never be instantiated @@ -675,9 +676,10 @@ def iter_evoked(self): self._current = 0 while True: - out = self.next(True) - if out is None: - return # properly signal the end of iteration + try: + out = self.next(True) + except StopIteration: + break data, event_id = out tmin = self.times[0] info = deepcopy(self.info) diff --git a/mne/evoked.py b/mne/evoked.py index 202f433507d..a53e5fdc5cd 100644 --- a/mne/evoked.py +++ b/mne/evoked.py @@ -44,7 +44,8 @@ class Evoked(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin, InterpolationMixin, FilterMixin, - ToDataFrameMixin, TimeMixin, SizeMixin): + ToDataFrameMixin, TimeMixin, + SizeMixin): # lgtm[py/missing-equals] """Evoked data. Parameters diff --git a/mne/io/base.py b/mne/io/base.py index 834e7928c87..37724609f67 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -251,7 +251,7 @@ def _check_fun(fun, d, *args, **kwargs): class BaseRaw(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin, InterpolationMixin, ToDataFrameMixin, - TimeMixin, SizeMixin): + TimeMixin, SizeMixin): # lgtm[py/missing-equals] """Base class for Raw data. Parameters diff --git a/mne/morph.py b/mne/morph.py index 1e5e28d0618..deba52ec463 100644 --- a/mne/morph.py +++ b/mne/morph.py @@ -144,7 +144,7 @@ def compute_source_morph(src, subject_from=None, subject_to='fsaverage', _check_dep(nibabel='2.1.0', dipy=False) logger.info('volume source space inferred...') - import nibabel as nib + from nibabel import load # load moving MRI mri_subpath = op.join('mri', 'brain.mgz') @@ -152,7 +152,7 @@ def compute_source_morph(src, subject_from=None, subject_to='fsaverage', logger.info('loading %s as "from" volume' % mri_path_from) with warnings.catch_warnings(): - mri_from = nib.load(mri_path_from) + mri_from = load(mri_path_from) # eventually we could let this be some other volume, but for now # let's KISS and use `brain.mgz`, too @@ -161,7 +161,7 @@ def compute_source_morph(src, subject_from=None, subject_to='fsaverage', raise IOError('cannot read file: %s' % mri_path_to) logger.info('loading %s as "to" volume' % mri_path_to) with warnings.catch_warnings(): - mri_to = nib.load(mri_path_to) + mri_to = load(mri_path_to) # pre-compute non-linear morph shape, zooms, affine, pre_affine, sdr_morph = _compute_morph_sdr( @@ -694,7 +694,7 @@ def _compute_morph_sdr(mri_from, mri_to, niter_affine=(100, 100, 10), niter_sdr=(5, 5, 3), zooms=(5., 5., 5.)): """Get a matrix that morphs data from one subject to another.""" _check_dep(nibabel='2.1.0', dipy='0.10.1') - import nibabel as nib + from nibabel import Nifti1Image with np.testing.suppress_warnings(): from dipy.align import imaffine, imwarp, metrics, transforms from dipy.align.reslice import reslice @@ -717,7 +717,7 @@ def _compute_morph_sdr(mri_from, mri_to, niter_affine=(100, 100, 10), zooms) with warnings.catch_warnings(): # nibabel<->numpy warning - mri_from = nib.Nifti1Image(mri_from_res, mri_from_res_affine) + mri_from = Nifti1Image(mri_from_res, mri_from_res_affine) # reslice mri_to mri_to_res, mri_to_res_affine = reslice( @@ -725,7 +725,7 @@ def _compute_morph_sdr(mri_from, mri_to, niter_affine=(100, 100, 10), zooms) with warnings.catch_warnings(): # nibabel<->numpy warning - mri_to = nib.Nifti1Image(mri_to_res, mri_to_res_affine) + mri_to = Nifti1Image(mri_to_res, mri_to_res_affine) affine = mri_to.affine mri_to = np.array(mri_to.dataobj, float) # to ndarray diff --git a/mne/preprocessing/tests/test_ssp.py b/mne/preprocessing/tests/test_ssp.py index 2ee50f16050..ef132489c90 100644 --- a/mne/preprocessing/tests/test_ssp.py +++ b/mne/preprocessing/tests/test_ssp.py @@ -130,6 +130,7 @@ def _check_projs_for_expected_channels(projs, n_mags, n_grads, n_eegs): assert len(p['data']['col_names']) == n_eegs +@pytest.mark.slowtest # can be slow on OSX travis @testing.requires_testing_data def test_compute_proj_ctf(): """Test to show that projector code completes on CTF data.""" diff --git a/mne/time_frequency/tfr.py b/mne/time_frequency/tfr.py index 9c1df2d0578..954599e622b 100644 --- a/mne/time_frequency/tfr.py +++ b/mne/time_frequency/tfr.py @@ -871,7 +871,8 @@ def tfr_multitaper(inst, freqs, n_cycles, time_bandwidth=4.0, # TFR(s) class -class _BaseTFR(ContainsMixin, UpdateChannelsMixin, SizeMixin): +class _BaseTFR(ContainsMixin, UpdateChannelsMixin, + SizeMixin): # lgtm[py/missing-equals] """Base TFR class.""" @property @@ -2214,8 +2215,8 @@ def _check_decim(decim): if isinstance(decim, int): decim = slice(None, None, decim) elif not isinstance(decim, slice): - raise(TypeError, '`decim` must be int or slice, got %s instead' - % type(decim)) + raise TypeError('`decim` must be int or slice, got %s instead' + % type(decim)) return decim diff --git a/mne/utils/mixin.py b/mne/utils/mixin.py index 64ec85177cb..89b92ddbe60 100644 --- a/mne/utils/mixin.py +++ b/mne/utils/mixin.py @@ -292,13 +292,9 @@ def __iter__(self): :func:`mne.Epochs.next`. """ self._current = 0 - while True: - x = self.next() - if x is None: - return - yield x + return self - def next(self, return_event_id=False): + def __next__(self, return_event_id=False): """Iterate over epoch data. Parameters @@ -315,14 +311,14 @@ def next(self, return_event_id=False): """ if self.preload: if self._current >= len(self._data): - return # signal the end + raise StopIteration # signal the end epoch = self._data[self._current] self._current += 1 else: is_good = False while not is_good: if self._current >= len(self.events): - return # signal the end properly + raise StopIteration # signal the end properly epoch_noproj = self._get_epoch_from_raw(self._current) epoch_noproj = self._detrend_offset_decim(epoch_noproj) epoch = self._project_epoch(epoch_noproj) @@ -337,9 +333,7 @@ def next(self, return_event_id=False): else: return epoch, self.events[self._current - 1][-1] - def __next__(self, *args, **kwargs): - """Provide a wrapper for Py3k.""" - return self.next(*args, **kwargs) + next = __next__ # originally for Python2, now b/c public def _check_metadata(self, metadata=None, reset_index=False): """Check metadata consistency.""" diff --git a/mne/viz/tests/test_3d.py b/mne/viz/tests/test_3d.py index 30c226dde70..5373fa8ff36 100644 --- a/mne/viz/tests/test_3d.py +++ b/mne/viz/tests/test_3d.py @@ -416,6 +416,7 @@ def test_snapshot_brain_montage(): pytest.raises(TypeError, snapshot_brain_montage, fig, info) +@pytest.mark.slowtest # can be slow on OSX @testing.requires_testing_data @requires_nibabel() @requires_version('nilearn', '0.4') diff --git a/mne/viz/tests/test_topomap.py b/mne/viz/tests/test_topomap.py index 845147f3d71..f99a3b8e91e 100644 --- a/mne/viz/tests/test_topomap.py +++ b/mne/viz/tests/test_topomap.py @@ -434,6 +434,7 @@ def test_ctf_plotting(): evoked.plot_topomap() +@pytest.mark.slowtest # can be slow on OSX @testing.requires_testing_data def test_plot_arrowmap(): """Test arrowmap plotting.""" diff --git a/tutorials/plot_info.py b/tutorials/plot_info.py index 5f02c734c39..f212286eb5e 100644 --- a/tutorials/plot_info.py +++ b/tutorials/plot_info.py @@ -50,11 +50,12 @@ ############################################################################### # Get channel indices by name -channel_indices = mne.pick_channels(info['ch_names'], ['MEG 0312', 'EEG 005']) +channel_indices_two = mne.pick_channels( + info['ch_names'], ['MEG 0312', 'EEG 005']) ############################################################################### # Get channel indices by regular expression -channel_indices = mne.pick_channels_regexp(info['ch_names'], 'MEG *') +channel_indices_meg_re = mne.pick_channels_regexp(info['ch_names'], 'MEG *') ############################################################################### # Channel types @@ -80,12 +81,12 @@ # - syst : System status channel information (on Triux systems only). # # Get channel indices by type -channel_indices = mne.pick_types(info, meg=True) # MEG only -channel_indices = mne.pick_types(info, meg=False, eeg=True) # EEG only +channel_indices_meg = mne.pick_types(info, meg=True) # MEG only +channel_indices_eeg = mne.pick_types(info, meg=False, eeg=True) # EEG only ############################################################################### # MEG gradiometers and EEG channels -channel_indices = mne.pick_types(info, meg='grad', eeg=True) +channel_indices_grad_eeg = mne.pick_types(info, meg='grad', eeg=True) ############################################################################### # Get a dictionary of channel indices, grouped by channel type From 3afcc7b2ea0e49ad25ede22c6d3a894ed6516f07 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 10 Feb 2019 22:50:49 -0500 Subject: [PATCH 11/16] FIX: Realtime --- mne/epochs.py | 4 ++-- mne/realtime/epochs.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mne/epochs.py b/mne/epochs.py index f5af27c4ef6..e0984096076 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -677,7 +677,7 @@ def iter_evoked(self): while True: try: - out = self.next(True) + out = self.__next__(True) except StopIteration: break data, event_id = out @@ -1775,7 +1775,7 @@ class Epochs(BaseEpochs): :meth:`mne.Epochs.__getitem__`. All methods for iteration over objects (using :meth:`mne.Epochs.__iter__`, - :meth:`mne.Epochs.iter_evoked` or :meth:`mne.Epochs.next`) use the same + :meth:`mne.Epochs.iter_evoked` or :meth:`mne.Epochs.__next__`) use the same internal state. """ diff --git a/mne/realtime/epochs.py b/mne/realtime/epochs.py index 976bca6ae37..aeede77e1a6 100644 --- a/mne/realtime/epochs.py +++ b/mne/realtime/epochs.py @@ -312,7 +312,7 @@ def stop(self, stop_receive_thread=True, stop_measurement=False): self._client.stop_receive_thread(stop_measurement=stop_measurement) @verbose - def next(self, return_event_id=False, verbose=None): + def __next__(self, return_event_id=False, verbose=None): """Make iteration over epochs easy. Parameters @@ -342,7 +342,7 @@ def next(self, return_event_id=False, verbose=None): return (epoch, event_id) if return_event_id else epoch if current_time > (self._last_time + self.isi_max): logger.info('Time of %s seconds exceeded.' % self.isi_max) - return # signal the end properly + raise StopIteration # signal the end properly if self._started: if first: logger.info('Waiting for epoch %d' % (self._current + 1)) @@ -352,6 +352,8 @@ def next(self, return_event_id=False, verbose=None): raise RuntimeError('Not enough epochs in queue and currently ' 'not receiving epochs, cannot get epochs!') + next = __next__ + @verbose def _get_data(self, out=True, verbose=None): """ From 69b370f88b52bfd6becf81aff4c8e54ff79b68d0 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 10 Feb 2019 23:10:23 -0500 Subject: [PATCH 12/16] FIX: Ref --- mne/epochs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/epochs.py b/mne/epochs.py index e0984096076..0d57f2e2806 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -1775,7 +1775,7 @@ class Epochs(BaseEpochs): :meth:`mne.Epochs.__getitem__`. All methods for iteration over objects (using :meth:`mne.Epochs.__iter__`, - :meth:`mne.Epochs.iter_evoked` or :meth:`mne.Epochs.__next__`) use the same + :meth:`mne.Epochs.iter_evoked` or :meth:`mne.Epochs.next`) use the same internal state. """ From fd41864892510ff7d517aeb0ffb044fd98e55367 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 11 Feb 2019 08:26:09 -0500 Subject: [PATCH 13/16] FIX: Try a different skip --- .lgtm.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.lgtm.yml b/.lgtm.yml index 9a892ff4ed3..7aa154af400 100644 --- a/.lgtm.yml +++ b/.lgtm.yml @@ -2,7 +2,8 @@ extraction: python: index: filters: - - exclude: "mne/externals/**.py" + - exclude: "mne/externals/*.py" + - exclude: "mne/externals/*/*.py" javascript: index: filters: From ea8da7efbc2408935800ec696303c69d6b1819bc Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 11 Feb 2019 10:33:43 -0500 Subject: [PATCH 14/16] FIX: Try another way --- mne/datasets/sleep_physionet/_utils.py | 9 ++++----- mne/epochs.py | 2 +- mne/evoked.py | 7 +++---- mne/io/base.py | 6 +++--- mne/preprocessing/tests/test_ssp.py | 3 ++- mne/time_frequency/tfr.py | 2 +- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/mne/datasets/sleep_physionet/_utils.py b/mne/datasets/sleep_physionet/_utils.py index 6fb08245835..78afe37168a 100644 --- a/mne/datasets/sleep_physionet/_utils.py +++ b/mne/datasets/sleep_physionet/_utils.py @@ -4,8 +4,7 @@ # # License: BSD Style. -import os -from os import path as op +from os import path as op, remove, makedirs import numpy as np from ...utils import _fetch_file, verbose, _TempDir, _check_pandas_installed @@ -23,9 +22,9 @@ def _fetch_one(fname, hashsum, path, force_update): destination = op.join(path, fname) if not op.isfile(destination) or force_update: if op.isfile(destination): - os.remove(destination) + remove(destination) if not op.isdir(op.dirname(destination)): - os.makedirs(op.dirname(destination)) + makedirs(op.dirname(destination)) _fetch_file(url, destination, print_destination=False, hash_=hashsum, hash_type='sha1') return destination @@ -109,7 +108,7 @@ def _update_sleep_temazepam_records(fname=TEMAZEPAM_SLEEP_RECORDS): data.columns.names = [None, None] data = (data.set_index([('Subject - age - sex', 'Age'), ('Subject - age - sex', 'M1/F2')], append=True) - .stack(level=0).reset_index()) + .stack(level=0).reset_index()) data = data.rename(columns={('Subject - age - sex', 'Age'): 'age', ('Subject - age - sex', 'M1/F2'): 'sex', diff --git a/mne/epochs.py b/mne/epochs.py index 0d57f2e2806..a9e7f37c2ac 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -169,7 +169,7 @@ def _save_split(epochs, fname, part_idx, n_parts, fmt): class BaseEpochs(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin, InterpolationMixin, FilterMixin, ToDataFrameMixin, TimeMixin, SizeMixin, - GetEpochsMixin): # lgtm[py/missing-equals] + GetEpochsMixin): # lgtm [py/missing-equals] """Abstract base class for Epochs-type classes. This class provides basic functionality and should never be instantiated diff --git a/mne/evoked.py b/mne/evoked.py index a53e5fdc5cd..0031280a681 100644 --- a/mne/evoked.py +++ b/mne/evoked.py @@ -42,10 +42,9 @@ str(FIFF.FIFFV_ASPECT_STD_ERR): 'standard_error'} -class Evoked(ProjMixin, ContainsMixin, UpdateChannelsMixin, - SetChannelsMixin, InterpolationMixin, FilterMixin, - ToDataFrameMixin, TimeMixin, - SizeMixin): # lgtm[py/missing-equals] +class Evoked(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin, + InterpolationMixin, FilterMixin, ToDataFrameMixin, TimeMixin, + SizeMixin): # lgtm [py/missing-equals] """Evoked data. Parameters diff --git a/mne/io/base.py b/mne/io/base.py index 37724609f67..cca0bfd8536 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -249,9 +249,9 @@ def _check_fun(fun, d, *args, **kwargs): return d -class BaseRaw(ProjMixin, ContainsMixin, UpdateChannelsMixin, - SetChannelsMixin, InterpolationMixin, ToDataFrameMixin, - TimeMixin, SizeMixin): # lgtm[py/missing-equals] +class BaseRaw(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin, + InterpolationMixin, ToDataFrameMixin, TimeMixin, + SizeMixin): # lgtm [py/missing-equals] """Base class for Raw data. Parameters diff --git a/mne/preprocessing/tests/test_ssp.py b/mne/preprocessing/tests/test_ssp.py index ef132489c90..858e800e267 100644 --- a/mne/preprocessing/tests/test_ssp.py +++ b/mne/preprocessing/tests/test_ssp.py @@ -95,6 +95,7 @@ def test_compute_proj_eog(): assert projs is None +@pytest.mark.slowtest # can be slow on OSX def test_compute_proj_parallel(): """Test computation of ExG projectors using parallelization.""" raw_0 = read_raw_fif(raw_fname).crop(0, 10) @@ -130,7 +131,7 @@ def _check_projs_for_expected_channels(projs, n_mags, n_grads, n_eegs): assert len(p['data']['col_names']) == n_eegs -@pytest.mark.slowtest # can be slow on OSX travis +@pytest.mark.slowtest # can be slow on OSX @testing.requires_testing_data def test_compute_proj_ctf(): """Test to show that projector code completes on CTF data.""" diff --git a/mne/time_frequency/tfr.py b/mne/time_frequency/tfr.py index 954599e622b..471035cd7d0 100644 --- a/mne/time_frequency/tfr.py +++ b/mne/time_frequency/tfr.py @@ -872,7 +872,7 @@ def tfr_multitaper(inst, freqs, n_cycles, time_bandwidth=4.0, # TFR(s) class class _BaseTFR(ContainsMixin, UpdateChannelsMixin, - SizeMixin): # lgtm[py/missing-equals] + SizeMixin): # lgtm [py/missing-equals] """Base TFR class.""" @property From 64c08f4d7ed8bcb6474050b0066cf7c2e867ed96 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 11 Feb 2019 10:53:57 -0500 Subject: [PATCH 15/16] FIX: Change config --- .lgtm.yml | 3 +++ mne/epochs.py | 3 +-- mne/evoked.py | 2 +- mne/io/base.py | 3 +-- mne/time_frequency/tfr.py | 3 +-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.lgtm.yml b/.lgtm.yml index 7aa154af400..25fa96359f2 100644 --- a/.lgtm.yml +++ b/.lgtm.yml @@ -8,3 +8,6 @@ extraction: index: filters: - exclude: "**/*.js" +queries: + - exclude: py/missing-equals + - exclude: py/import-and-import-from diff --git a/mne/epochs.py b/mne/epochs.py index a9e7f37c2ac..9fd5aa0bad3 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -168,8 +168,7 @@ def _save_split(epochs, fname, part_idx, n_parts, fmt): class BaseEpochs(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin, InterpolationMixin, FilterMixin, - ToDataFrameMixin, TimeMixin, SizeMixin, - GetEpochsMixin): # lgtm [py/missing-equals] + ToDataFrameMixin, TimeMixin, SizeMixin, GetEpochsMixin): """Abstract base class for Epochs-type classes. This class provides basic functionality and should never be instantiated diff --git a/mne/evoked.py b/mne/evoked.py index 0031280a681..73700b8f3f2 100644 --- a/mne/evoked.py +++ b/mne/evoked.py @@ -44,7 +44,7 @@ class Evoked(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin, InterpolationMixin, FilterMixin, ToDataFrameMixin, TimeMixin, - SizeMixin): # lgtm [py/missing-equals] + SizeMixin): """Evoked data. Parameters diff --git a/mne/io/base.py b/mne/io/base.py index cca0bfd8536..834995b6931 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -250,8 +250,7 @@ def _check_fun(fun, d, *args, **kwargs): class BaseRaw(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin, - InterpolationMixin, ToDataFrameMixin, TimeMixin, - SizeMixin): # lgtm [py/missing-equals] + InterpolationMixin, ToDataFrameMixin, TimeMixin, SizeMixin): """Base class for Raw data. Parameters diff --git a/mne/time_frequency/tfr.py b/mne/time_frequency/tfr.py index 471035cd7d0..4b1da447b6b 100644 --- a/mne/time_frequency/tfr.py +++ b/mne/time_frequency/tfr.py @@ -871,8 +871,7 @@ def tfr_multitaper(inst, freqs, n_cycles, time_bandwidth=4.0, # TFR(s) class -class _BaseTFR(ContainsMixin, UpdateChannelsMixin, - SizeMixin): # lgtm [py/missing-equals] +class _BaseTFR(ContainsMixin, UpdateChannelsMixin, SizeMixin): """Base TFR class.""" @property From 28bfc346ce7018ddfbe6fbb92414cd30c7f08fbd Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Mon, 11 Feb 2019 11:20:51 -0500 Subject: [PATCH 16/16] FIX: Revert froms --- mne/datasets/sleep_physionet/_utils.py | 7 ++++--- mne/forward/_lead_dots.py | 5 +++-- mne/forward/_make_forward.py | 5 +++-- mne/gui/_fiducials_gui.py | 2 +- mne/io/ctf/ctf.py | 5 +++-- mne/label.py | 11 ++++++----- mne/morph.py | 12 ++++++------ mne/transforms.py | 7 ++++--- setup.py | 7 ++++--- 9 files changed, 34 insertions(+), 27 deletions(-) diff --git a/mne/datasets/sleep_physionet/_utils.py b/mne/datasets/sleep_physionet/_utils.py index 78afe37168a..a422a123310 100644 --- a/mne/datasets/sleep_physionet/_utils.py +++ b/mne/datasets/sleep_physionet/_utils.py @@ -4,7 +4,8 @@ # # License: BSD Style. -from os import path as op, remove, makedirs +import os +import os.path as op import numpy as np from ...utils import _fetch_file, verbose, _TempDir, _check_pandas_installed @@ -22,9 +23,9 @@ def _fetch_one(fname, hashsum, path, force_update): destination = op.join(path, fname) if not op.isfile(destination) or force_update: if op.isfile(destination): - remove(destination) + os.remove(destination) if not op.isdir(op.dirname(destination)): - makedirs(op.dirname(destination)) + os.makedirs(op.dirname(destination)) _fetch_file(url, destination, print_destination=False, hash_=hashsum, hash_type='sha1') return destination diff --git a/mne/forward/_lead_dots.py b/mne/forward/_lead_dots.py index e2a9da728ca..d36e6a7c837 100644 --- a/mne/forward/_lead_dots.py +++ b/mne/forward/_lead_dots.py @@ -4,7 +4,8 @@ # # License: BSD (3-clause) -from os import path as op, makedirs +import os +import os.path as op import numpy as np from numpy.polynomial import legendre @@ -56,7 +57,7 @@ def _get_legen_table(ch_type, volume_integral=False, n_coeff=100, fname = op.join(_get_extra_data_path(), 'tables') if not op.isdir(fname): # Updated due to API chang (GH 1167) - makedirs(fname) + os.makedirs(fname) if ch_type == 'meg': fname = op.join(fname, 'legder_%s_%s.bin' % (n_coeff, n_interp)) leg_fun = _get_legen_der diff --git a/mne/forward/_make_forward.py b/mne/forward/_make_forward.py index 7396d792e47..243f7aa2c87 100644 --- a/mne/forward/_make_forward.py +++ b/mne/forward/_make_forward.py @@ -7,7 +7,8 @@ from copy import deepcopy import contextlib -from os import path as op, getcwd +import os +import os.path as op import numpy as np @@ -448,7 +449,7 @@ def _prepare_for_forward(src, mri_head_t, info, bem, mindist, n_jobs, info = Info(chs=info['chs'], comps=info['comps'], dev_head_t=info['dev_head_t'], mri_file=trans, mri_id=mri_id, - meas_file=info_extra, meas_id=None, working_dir=getcwd(), + meas_file=info_extra, meas_id=None, working_dir=os.getcwd(), command_line=cmd, bads=info['bads'], mri_head_t=mri_head_t) info._update_redundant() info._check_consistency() diff --git a/mne/gui/_fiducials_gui.py b/mne/gui/_fiducials_gui.py index 6961c78026a..2f6e67e0796 100644 --- a/mne/gui/_fiducials_gui.py +++ b/mne/gui/_fiducials_gui.py @@ -389,7 +389,7 @@ def round_(x): elif i in idxs: line += " (<- also MRI mesh)" msg.append(line) - logger.debug(os.linesep.join(msg)) + logger.debug('\n'.join(msg)) if self.set == 'Nasion': self.nasion = pt diff --git a/mne/io/ctf/ctf.py b/mne/io/ctf/ctf.py index 245245b20b0..28ecbb26d42 100644 --- a/mne/io/ctf/ctf.py +++ b/mne/io/ctf/ctf.py @@ -4,7 +4,8 @@ # # License: BSD (3-clause) -from os import path as op, SEEK_END +import os +import os.path as op import numpy as np @@ -203,7 +204,7 @@ def _get_sample_info(fname, res4, system_clock): clock_ch = k break with open(fname, 'rb') as fid: - fid.seek(0, SEEK_END) + fid.seek(0, os.SEEK_END) st_size = fid.tell() fid.seek(0, 0) if (st_size - CTF.HEADER_SIZE) % (4 * res4['nsamp'] * diff --git a/mne/label.py b/mne/label.py index 94eac0ddfaf..14b6b9ccca5 100644 --- a/mne/label.py +++ b/mne/label.py @@ -6,7 +6,8 @@ from collections import defaultdict from colorsys import hsv_to_rgb, rgb_to_hsv -from os import path as op, linesep, listdir +import os +import os.path as op import copy as cp import re @@ -1848,7 +1849,7 @@ def _read_annot(fname): if not op.isdir(dir_name): raise IOError('Directory for annotation does not exist: %s', fname) - cands = listdir(dir_name) + cands = os.listdir(dir_name) cands = [c for c in cands if '.annot' in c] if len(cands) == 0: raise IOError('No such file %s, no candidate parcellations ' @@ -2432,18 +2433,18 @@ def write_labels_to_annot(labels, subject=None, parc=None, overwrite=False, msg = ("Some labels have the same color values (all labels in one " "hemisphere must have a unique color):") duplicate_colors.insert(0, msg) - issues.append(linesep.join(duplicate_colors)) + issues.append('\n'.join(duplicate_colors)) if invalid_colors: msg = ("Some labels have invalid color values (all colors should be " "RGBA tuples with values between 0 and 1)") invalid_colors.insert(0, msg) - issues.append(linesep.join(invalid_colors)) + issues.append('\n'.join(invalid_colors)) if overlap: msg = ("Some labels occupy vertices that are also occupied by one or " "more other labels. Each vertex can only be occupied by a " "single label in *.annot files.") overlap.insert(0, msg) - issues.append(linesep.join(overlap)) + issues.append('\n'.join(overlap)) if issues: raise ValueError('\n\n'.join(issues)) diff --git a/mne/morph.py b/mne/morph.py index deba52ec463..1e5e28d0618 100644 --- a/mne/morph.py +++ b/mne/morph.py @@ -144,7 +144,7 @@ def compute_source_morph(src, subject_from=None, subject_to='fsaverage', _check_dep(nibabel='2.1.0', dipy=False) logger.info('volume source space inferred...') - from nibabel import load + import nibabel as nib # load moving MRI mri_subpath = op.join('mri', 'brain.mgz') @@ -152,7 +152,7 @@ def compute_source_morph(src, subject_from=None, subject_to='fsaverage', logger.info('loading %s as "from" volume' % mri_path_from) with warnings.catch_warnings(): - mri_from = load(mri_path_from) + mri_from = nib.load(mri_path_from) # eventually we could let this be some other volume, but for now # let's KISS and use `brain.mgz`, too @@ -161,7 +161,7 @@ def compute_source_morph(src, subject_from=None, subject_to='fsaverage', raise IOError('cannot read file: %s' % mri_path_to) logger.info('loading %s as "to" volume' % mri_path_to) with warnings.catch_warnings(): - mri_to = load(mri_path_to) + mri_to = nib.load(mri_path_to) # pre-compute non-linear morph shape, zooms, affine, pre_affine, sdr_morph = _compute_morph_sdr( @@ -694,7 +694,7 @@ def _compute_morph_sdr(mri_from, mri_to, niter_affine=(100, 100, 10), niter_sdr=(5, 5, 3), zooms=(5., 5., 5.)): """Get a matrix that morphs data from one subject to another.""" _check_dep(nibabel='2.1.0', dipy='0.10.1') - from nibabel import Nifti1Image + import nibabel as nib with np.testing.suppress_warnings(): from dipy.align import imaffine, imwarp, metrics, transforms from dipy.align.reslice import reslice @@ -717,7 +717,7 @@ def _compute_morph_sdr(mri_from, mri_to, niter_affine=(100, 100, 10), zooms) with warnings.catch_warnings(): # nibabel<->numpy warning - mri_from = Nifti1Image(mri_from_res, mri_from_res_affine) + mri_from = nib.Nifti1Image(mri_from_res, mri_from_res_affine) # reslice mri_to mri_to_res, mri_to_res_affine = reslice( @@ -725,7 +725,7 @@ def _compute_morph_sdr(mri_from, mri_to, niter_affine=(100, 100, 10), zooms) with warnings.catch_warnings(): # nibabel<->numpy warning - mri_to = Nifti1Image(mri_to_res, mri_to_res_affine) + mri_to = nib.Nifti1Image(mri_to_res, mri_to_res_affine) affine = mri_to.affine mri_to = np.array(mri_to.dataobj, float) # to ndarray diff --git a/mne/transforms.py b/mne/transforms.py index 0ef9664e483..24e1c7f5cd1 100644 --- a/mne/transforms.py +++ b/mne/transforms.py @@ -6,7 +6,8 @@ # # License: BSD (3-clause) -from os import path as op, environ +import os +import os.path as op import glob import numpy as np @@ -184,8 +185,8 @@ def _print_coord_trans(t, prefix='Coordinate transformation: '): def _find_trans(subject, subjects_dir=None): if subject is None: - if 'SUBJECT' in environ: - subject = environ['SUBJECT'] + if 'SUBJECT' in os.environ: + subject = os.environ['SUBJECT'] else: raise ValueError('SUBJECT environment variable not set') diff --git a/setup.py b/setup.py index e89ca4ad7a1..0e83d22e17a 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,8 @@ # Copyright (C) 2011-2017 Alexandre Gramfort # -from os import path as op, remove, walk +import os +import os.path as op from setuptools import setup @@ -35,14 +36,14 @@ def package_tree(pkgroot): # Adapted from VisPy path = op.dirname(__file__) subdirs = [op.relpath(i[0], path).replace(op.sep, '.') - for i in walk(op.join(path, pkgroot)) + for i in os.walk(op.join(path, pkgroot)) if '__init__.py' in i[2]] return sorted(subdirs) if __name__ == "__main__": if op.exists('MANIFEST'): - remove('MANIFEST') + os.remove('MANIFEST') setup(name=DISTNAME, maintainer=MAINTAINER,