Skip to content

Commit d54144f

Browse files
agramfortlarsoner
authored andcommitted
MRG: fix issues raised by LGTM.com (mne-tools#5914)
* fix issues raised by LGTM.com * ENH: Skip JS tests * FIX: LGTM fixes * FIX: Exclude * FIX: Exclude * FIX: Really this time * FIX: More fixes * FIX: More * FIX: Fix bug * FIX: __iter__ should return self, __next__ raise StopIteration * FIX: Realtime * FIX: Ref * FIX: Try a different skip * FIX: Try another way * FIX: Change config * FIX: Revert froms
1 parent ec4844e commit d54144f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+217
-218
lines changed

.lgtm.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extraction:
2+
python:
3+
index:
4+
filters:
5+
- exclude: "mne/externals/*.py"
6+
- exclude: "mne/externals/*/*.py"
7+
javascript:
8+
index:
9+
filters:
10+
- exclude: "**/*.js"
11+
queries:
12+
- exclude: py/missing-equals
13+
- exclude: py/import-and-import-from

examples/visualization/plot_evoked_topomap.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""
23
========================================
34
Plotting topographic maps of evoked data

logo/generate_mne_logos.py

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from matplotlib.text import TextPath
2020
from matplotlib.patches import PathPatch
2121
from matplotlib.colors import LinearSegmentedColormap
22-
from matplotlib.transforms import Bbox
2322

2423
# manually set values
2524
dpi = 72.

mne/annotations.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import re
99
from copy import deepcopy
1010
from itertools import takewhile
11-
from collections import OrderedDict
1211
import collections
1312

1413
import numpy as np
@@ -223,7 +222,7 @@ def __getitem__(self, key):
223222
out_keys = ('onset', 'duration', 'description', 'orig_time')
224223
out_vals = (self.onset[key], self.duration[key],
225224
self.description[key], self.orig_time)
226-
return OrderedDict(zip(out_keys, out_vals))
225+
return collections.OrderedDict(zip(out_keys, out_vals))
227226
else:
228227
key = list(key) if isinstance(key, tuple) else key
229228
return Annotations(onset=self.onset[key],
@@ -673,7 +672,6 @@ def get_duration_from_times(t):
673672

674673

675674
def _is_iso8601(candidate_str):
676-
import re
677675
ISO8601 = r'^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}\.\d{6}$'
678676
return re.compile(ISO8601).match(candidate_str) is not None
679677

mne/beamformer/_dics.py

-2
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,6 @@ def tf_dics(epochs, forward, noise_csds, tmin, tmax, tstep, win_lengths,
853853
'window %d to %d ms, in frequency range %d to %d Hz' %
854854
(win_tmin * 1e3, win_tmax * 1e3, fmin, fmax)
855855
)
856-
win_tmin = win_tmin
857-
win_tmax = win_tmax
858856

859857
# Calculating data CSD in current time window
860858
if mode == 'fourier':

mne/bem.py

-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ def _surfaces_to_bem(surfs, ids, sigmas, ico=None, rescale=True,
475475
len(sigmas)):
476476
raise ValueError('surfs, ids, and sigmas must all have the same '
477477
'number of elements (1 or 3)')
478-
surf = list(surfs)
479478
for si, surf in enumerate(surfs):
480479
if isinstance(surf, str):
481480
surfs[si] = read_surface(surf, return_dict=True)[-1]

mne/coreg.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from functools import reduce
1818

1919
import numpy as np
20-
from numpy import dot
2120

2221
from .io import read_fiducials, write_fiducials, read_info
2322
from .io.constants import FIFF
@@ -288,7 +287,7 @@ def _trans_from_params(param_info, params):
288287
x, y, z = params[i:i + 3]
289288
trans.append(scaling(x, y, z))
290289

291-
trans = reduce(dot, trans)
290+
trans = reduce(np.dot, trans)
292291
return trans
293292

294293

@@ -362,7 +361,7 @@ def fit_matched_points(src_pts, tgt_pts, rotate=True, translate=True,
362361
def error(x):
363362
rx, ry, rz = x
364363
trans = rotation3d(rx, ry, rz)
365-
est = dot(src_pts, trans.T)
364+
est = np.dot(src_pts, trans.T)
366365
d = tgt_pts - est
367366
if weights is not None:
368367
d *= weights
@@ -372,8 +371,8 @@ def error(x):
372371
elif param_info == (True, True, 0):
373372
def error(x):
374373
rx, ry, rz, tx, ty, tz = x
375-
trans = dot(translation(tx, ty, tz), rotation(rx, ry, rz))
376-
est = dot(src_pts, trans.T)[:, :3]
374+
trans = np.dot(translation(tx, ty, tz), rotation(rx, ry, rz))
375+
est = np.dot(src_pts, trans.T)[:, :3]
377376
d = tgt_pts - est
378377
if weights is not None:
379378
d *= weights
@@ -383,9 +382,10 @@ def error(x):
383382
elif param_info == (True, True, 1):
384383
def error(x):
385384
rx, ry, rz, tx, ty, tz, s = x
386-
trans = reduce(dot, (translation(tx, ty, tz), rotation(rx, ry, rz),
387-
scaling(s, s, s)))
388-
est = dot(src_pts, trans.T)[:, :3]
385+
trans = reduce(np.dot, (translation(tx, ty, tz),
386+
rotation(rx, ry, rz),
387+
scaling(s, s, s)))
388+
est = np.dot(src_pts, trans.T)[:, :3]
389389
d = tgt_pts - est
390390
if weights is not None:
391391
d *= weights
@@ -395,9 +395,10 @@ def error(x):
395395
elif param_info == (True, True, 3):
396396
def error(x):
397397
rx, ry, rz, tx, ty, tz, sx, sy, sz = x
398-
trans = reduce(dot, (translation(tx, ty, tz), rotation(rx, ry, rz),
399-
scaling(sx, sy, sz)))
400-
est = dot(src_pts, trans.T)[:, :3]
398+
trans = reduce(np.dot, (translation(tx, ty, tz),
399+
rotation(rx, ry, rz),
400+
scaling(sx, sy, sz)))
401+
est = np.dot(src_pts, trans.T)[:, :3]
401402
d = tgt_pts - est
402403
if weights is not None:
403404
d *= weights
@@ -419,7 +420,7 @@ def error(x):
419420
if tol is not None:
420421
if not translate:
421422
src_pts = np.hstack((src_pts, np.ones((len(src_pts), 1))))
422-
est_pts = dot(src_pts, trans.T)[:, :3]
423+
est_pts = np.dot(src_pts, trans.T)[:, :3]
423424
err = np.sqrt(np.sum((est_pts - tgt_pts) ** 2, axis=1))
424425
if np.any(err > tol):
425426
raise RuntimeError("Error exceeds tolerance. Error = %r" % err)

mne/cov.py

-3
Original file line numberDiff line numberDiff line change
@@ -1095,9 +1095,6 @@ def _compute_covariance_auto(data, method, info, method_params, cv,
10951095
name = method_.__name__ if callable(method_) else method_
10961096
out[name] = dict(loglik=loglik, data=cov, estimator=estimator)
10971097
out[name].update(runtime_info)
1098-
# undo scaling
1099-
if eigvec is not None:
1100-
data = np.dot(data, eigvec)
11011098

11021099
return out
11031100

mne/datasets/hf_sef/hf_sef.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ def data_path(dataset='evoked', path=None, force_update=False,
9595

9696
os.remove(archive)
9797

98-
path = _do_path_update(path, update_path, key, name)
98+
_do_path_update(path, update_path, key, name)
9999
return destdir

mne/datasets/megsim/megsim.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def data_path(url, path=None, force_update=False, update_path=None,
9696
z.close()
9797
destinations = [op.join(decomp_dir, f) for f in files]
9898

99-
path = _do_path_update(path, update_path, key, name)
99+
_do_path_update(path, update_path, key, name)
100100
return destinations
101101

102102

mne/datasets/sleep_physionet/_utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
# -*- coding: utf-8 -*-
12
# Authors: Alexandre Gramfort <alexandre.gramfort@inria.fr>
23
# Joan Massich <mailsik@gmail.com>
34
#
45
# License: BSD Style.
56

67
import os
7-
from os import path as op
8+
import os.path as op
89
import numpy as np
910

1011
from ...utils import _fetch_file, verbose, _TempDir, _check_pandas_installed
@@ -108,7 +109,7 @@ def _update_sleep_temazepam_records(fname=TEMAZEPAM_SLEEP_RECORDS):
108109
data.columns.names = [None, None]
109110
data = (data.set_index([('Subject - age - sex', 'Age'),
110111
('Subject - age - sex', 'M1/F2')], append=True)
111-
.stack(level=0).reset_index())
112+
.stack(level=0).reset_index())
112113

113114
data = data.rename(columns={('Subject - age - sex', 'Age'): 'age',
114115
('Subject - age - sex', 'M1/F2'): 'sex',

mne/datasets/sleep_physionet/age.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
# Authors: Alexandre Gramfort <alexandre.gramfort@inria.fr>
23
# Joan Massich <mailsik@gmail.com>
34
#

mne/datasets/sleep_physionet/temazepam.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
# Authors: Alexandre Gramfort <alexandre.gramfort@inria.fr>
23
# Joan Massich <mailsik@gmail.com>
34
#

mne/decoding/mixin.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ def fit_transform(self, X, y=None, **fit_params):
3535
class EstimatorMixin(object):
3636
"""Mixin class for estimators."""
3737

38-
def get_params(self):
39-
"""Get the estimator params."""
40-
pass
38+
def get_params(self, deep=True):
39+
"""Get the estimator params.
40+
41+
Parameters
42+
----------
43+
deep : bool
44+
Deep.
45+
"""
46+
return
4147

4248
def set_params(self, **params):
4349
"""Set parameters (mimics sklearn API)."""

mne/epochs.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,10 @@ def iter_evoked(self):
689689
self._current = 0
690690

691691
while True:
692-
out = self.next(True)
693-
if out is None:
694-
return # properly signal the end of iteration
692+
try:
693+
out = self.__next__(True)
694+
except StopIteration:
695+
break
695696
data, event_id = out
696697
tmin = self.times[0]
697698
info = deepcopy(self.info)

mne/evoked.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
str(FIFF.FIFFV_ASPECT_STD_ERR): 'standard_error'}
4343

4444

45-
class Evoked(ProjMixin, ContainsMixin, UpdateChannelsMixin,
46-
SetChannelsMixin, InterpolationMixin, FilterMixin,
47-
ToDataFrameMixin, TimeMixin, SizeMixin):
45+
class Evoked(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin,
46+
InterpolationMixin, FilterMixin, ToDataFrameMixin, TimeMixin,
47+
SizeMixin):
4848
"""Evoked data.
4949
5050
Parameters

mne/fixes.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,6 @@ class BaseEstimator(object):
638638
@classmethod
639639
def _get_param_names(cls):
640640
"""Get parameter names for the estimator"""
641-
try:
642-
from inspect import signature
643-
except ImportError:
644-
from .externals.funcsigs import signature
645641
# fetch the constructor or the original constructor before
646642
# deprecation wrapping if any
647643
init = getattr(cls.__init__, 'deprecated_original', cls.__init__)
@@ -651,7 +647,7 @@ def _get_param_names(cls):
651647

652648
# introspect the constructor arguments to find the model parameters
653649
# to represent
654-
init_signature = signature(init)
650+
init_signature = inspect.signature(init)
655651
# Consider the constructor parameters excluding 'self'
656652
parameters = [p for p in init_signature.parameters.values()
657653
if p.name != 'self' and p.kind != p.VAR_KEYWORD]

mne/forward/_lead_dots.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# License: BSD (3-clause)
66

77
import os
8-
from os import path as op
8+
import os.path as op
99

1010
import numpy as np
1111
from numpy.polynomial import legendre
@@ -21,12 +21,11 @@
2121
def _next_legen_der(n, x, p0, p01, p0d, p0dd):
2222
"""Compute the next Legendre polynomial and its derivatives."""
2323
# only good for n > 1 !
24-
help_ = p0
25-
helpd = p0d
26-
p0 = ((2 * n - 1) * x * help_ - (n - 1) * p01) / n
27-
p0d = n * help_ + x * helpd
28-
p0dd = (n + 1) * helpd + x * p0dd
29-
p01 = help_
24+
old_p0 = p0
25+
old_p0d = p0d
26+
p0 = ((2 * n - 1) * x * old_p0 - (n - 1) * p01) / n
27+
p0d = n * old_p0 + x * old_p0d
28+
p0dd = (n + 1) * old_p0d + x * p0dd
3029
return p0, p0d, p0dd
3130

3231

mne/forward/_make_forward.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from copy import deepcopy
99
import contextlib
1010
import os
11-
from os import path as op
11+
import os.path as op
1212

1313
import numpy as np
1414

mne/gui/_coreg_gui.py

+9-19
Original file line numberDiff line numberDiff line change
@@ -391,37 +391,27 @@ def _get_head_mri_t(self):
391391

392392
@cached_property
393393
def _get_processed_high_res_mri_points(self):
394-
if self.grow_hair:
395-
if len(self.mri.bem_high_res.surf.nn):
396-
scaled_hair_dist = (1e-3 * self.grow_hair /
397-
np.array(self.parameters[6:9]))
398-
points = self.mri.bem_high_res.surf.rr.copy()
399-
hair = points[:, 2] > points[:, 1]
400-
points[hair] += (self.mri.bem_high_res.surf.nn[hair] *
401-
scaled_hair_dist)
402-
return points
403-
else:
404-
error(None, "Norms missing from bem, can't grow hair")
405-
self.grow_hair = 0
406-
else:
407-
return self.mri.bem_high_res.surf.rr
394+
return self._get_processed_mri_points('high')
408395

409396
@cached_property
410397
def _get_processed_low_res_mri_points(self):
398+
return self._get_processed_mri_points('low')
399+
400+
def _get_processed_mri_points(self, res):
401+
bem = self.mri.bem_low_res if res == 'low' else self.mri.bem_high_res
411402
if self.grow_hair:
412-
if len(self.mri.bem_low_res.surf.nn):
403+
if len(bem.surf.nn):
413404
scaled_hair_dist = (1e-3 * self.grow_hair /
414405
np.array(self.parameters[6:9]))
415-
points = self.mri.bem_low_res.surf.rr.copy()
406+
points = bem.surf.rr.copy()
416407
hair = points[:, 2] > points[:, 1]
417-
points[hair] += (self.mri.bem_low_res.surf.nn[hair] *
418-
scaled_hair_dist)
408+
points[hair] += bem.surf.nn[hair] * scaled_hair_dist
419409
return points
420410
else:
421411
error(None, "Norms missing from bem, can't grow hair")
422412
self.grow_hair = 0
423413
else:
424-
return self.mri.bem_low_res.surf.rr
414+
return bem.surf.rr
425415

426416
@cached_property
427417
def _get_mri_trans(self):

mne/gui/_fiducials_gui.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def round_(x):
389389
elif i in idxs:
390390
line += " (<- also MRI mesh)"
391391
msg.append(line)
392-
logger.debug(os.linesep.join(msg))
392+
logger.debug('\n'.join(msg))
393393

394394
if self.set == 'Nasion':
395395
self.nasion = pt

mne/inverse_sparse/mxne_optim.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ def _mixed_norm_solver_cd(M, G, alpha, lipschitz_constant, maxit=10000,
296296
"""Solve L21 inverse problem with coordinate descent."""
297297
from sklearn.linear_model.coordinate_descent import MultiTaskLasso
298298

299-
n_sensors, n_times = M.shape
300-
n_sensors, n_sources = G.shape
299+
assert M.ndim == G.ndim and M.shape[0] == G.shape[0]
301300

302301
clf = MultiTaskLasso(alpha=alpha / len(M), tol=tol / sum_squared(M),
303302
normalize=False, fit_intercept=False, max_iter=maxit,

0 commit comments

Comments
 (0)