diff --git a/.lgtm.yml b/.lgtm.yml new file mode 100644 index 00000000000..25fa96359f2 --- /dev/null +++ b/.lgtm.yml @@ -0,0 +1,13 @@ +extraction: + python: + index: + filters: + - exclude: "mne/externals/*.py" + - exclude: "mne/externals/*/*.py" + javascript: + index: + filters: + - exclude: "**/*.js" +queries: + - exclude: py/missing-equals + - exclude: py/import-and-import-from 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/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 3439103e823..7899d12d555 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], @@ -673,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/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/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/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/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/datasets/sleep_physionet/_utils.py b/mne/datasets/sleep_physionet/_utils.py index a517f332760..a422a123310 100644 --- a/mne/datasets/sleep_physionet/_utils.py +++ b/mne/datasets/sleep_physionet/_utils.py @@ -1,10 +1,11 @@ +# -*- coding: utf-8 -*- # Authors: Alexandre Gramfort # Joan Massich # # License: BSD Style. import os -from os import path as op +import os.path as op import numpy as np from ...utils import _fetch_file, verbose, _TempDir, _check_pandas_installed @@ -108,7 +109,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/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/decoding/mixin.py b/mne/decoding/mixin.py index 6b25e1b8756..f3e084a7bf8 100644 --- a/mne/decoding/mixin.py +++ b/mne/decoding/mixin.py @@ -35,9 +35,15 @@ def fit_transform(self, X, y=None, **fit_params): class EstimatorMixin(object): """Mixin class for estimators.""" - def get_params(self): - """Get the estimator params.""" - pass + def get_params(self, deep=True): + """Get the estimator params. + + Parameters + ---------- + deep : bool + Deep. + """ + return def set_params(self, **params): """Set parameters (mimics sklearn API).""" diff --git a/mne/epochs.py b/mne/epochs.py index 0d50ee853a8..9fd5aa0bad3 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -675,9 +675,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..73700b8f3f2 100644 --- a/mne/evoked.py +++ b/mne/evoked.py @@ -42,9 +42,9 @@ str(FIFF.FIFFV_ASPECT_STD_ERR): 'standard_error'} -class Evoked(ProjMixin, ContainsMixin, UpdateChannelsMixin, - SetChannelsMixin, InterpolationMixin, FilterMixin, - ToDataFrameMixin, TimeMixin, SizeMixin): +class Evoked(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin, + InterpolationMixin, FilterMixin, ToDataFrameMixin, TimeMixin, + SizeMixin): """Evoked data. Parameters 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..d36e6a7c837 100644 --- a/mne/forward/_lead_dots.py +++ b/mne/forward/_lead_dots.py @@ -5,7 +5,7 @@ # License: BSD (3-clause) import os -from os import path as op +import os.path as op import numpy as np from numpy.polynomial import legendre @@ -21,12 +21,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 diff --git a/mne/forward/_make_forward.py b/mne/forward/_make_forward.py index a2bf70becdc..243f7aa2c87 100644 --- a/mne/forward/_make_forward.py +++ b/mne/forward/_make_forward.py @@ -8,7 +8,7 @@ from copy import deepcopy import contextlib import os -from os import path as op +import os.path as op import numpy as np diff --git a/mne/gui/_coreg_gui.py b/mne/gui/_coreg_gui.py index af58ed72dc6..7ebbe9a3435 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 + return self._get_processed_mri_points('high') @cached_property def _get_processed_low_res_mri_points(self): + 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 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/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/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 f9b1ecd8a0a..834995b6931 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -249,9 +249,8 @@ def _check_fun(fun, d, *args, **kwargs): return d -class BaseRaw(ProjMixin, ContainsMixin, UpdateChannelsMixin, - SetChannelsMixin, InterpolationMixin, ToDataFrameMixin, - TimeMixin, SizeMixin): +class BaseRaw(ProjMixin, ContainsMixin, UpdateChannelsMixin, SetChannelsMixin, + InterpolationMixin, ToDataFrameMixin, TimeMixin, SizeMixin): """Base class for Raw data. Parameters @@ -691,7 +690,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 @@ -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 @@ -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..28ecbb26d42 100644 --- a/mne/io/ctf/ctf.py +++ b/mne/io/ctf/ctf.py @@ -5,7 +5,7 @@ # License: BSD (3-clause) import os -from os import path as op +import os.path as op import numpy as np 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/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/label.py b/mne/label.py index 55d1d64ea27..14b6b9ccca5 100644 --- a/mne/label.py +++ b/mne/label.py @@ -6,8 +6,8 @@ from collections import defaultdict from colorsys import hsv_to_rgb, rgb_to_hsv -from os import path as op import os +import os.path as op import copy as cp import re @@ -1867,8 +1867,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 +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(os.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(os.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(os.linesep.join(overlap)) + issues.append('\n'.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/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..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] @@ -1270,13 +1262,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( @@ -1338,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/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/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/tests/test_ssp.py b/mne/preprocessing/tests/test_ssp.py index 2ee50f16050..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,6 +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 @testing.requires_testing_data def test_compute_proj_ctf(): """Test to show that projector code completes on CTF data.""" 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/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): """ 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/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/time_frequency/tfr.py b/mne/time_frequency/tfr.py index 9c1df2d0578..4b1da447b6b 100644 --- a/mne/time_frequency/tfr.py +++ b/mne/time_frequency/tfr.py @@ -2214,8 +2214,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/transforms.py b/mne/transforms.py index 9fed0c4abd4..24e1c7f5cd1 100644 --- a/mne/transforms.py +++ b/mne/transforms.py @@ -7,12 +7,11 @@ # License: BSD (3-clause) import os -from os import path as op +import os.path as op import glob import numpy as np from copy import deepcopy -from numpy import sin, cos from scipy import linalg from .fixes import einsum @@ -191,8 +190,7 @@ def _find_trans(subject, subjects_dir=None): 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)) @@ -247,12 +245,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 +273,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/utils/mixin.py b/mne/utils/mixin.py index b0a87997f01..89b92ddbe60 100644 --- a/mne/utils/mixin.py +++ b/mne/utils/mixin.py @@ -24,6 +24,21 @@ 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 def _size(self): """Estimate the object size.""" @@ -277,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 @@ -300,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) @@ -322,11 +333,7 @@ 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) + 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/_3d.py b/mne/viz/_3d.py index 62940955090..4b3e9605a65 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 @@ -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() @@ -2039,7 +2037,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/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/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/mne/viz/topomap.py b/mne/viz/topomap.py index 0fec5b8a5aa..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): @@ -965,13 +967,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) @@ -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}) diff --git a/mne/viz/utils.py b/mne/viz/utils.py index 91a13c1378a..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() @@ -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: diff --git a/setup.py b/setup.py index 55e1ae086c9..0e83d22e17a 100755 --- a/setup.py +++ b/setup.py @@ -1,17 +1,16 @@ #! /usr/bin/env python -# # Copyright (C) 2011-2017 Alexandre Gramfort # import os -from os import path as op +import os.path as op 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,14 +34,15 @@ 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 os.walk(op.join(path, pkgroot)) if '__init__.py' in i[2]] return sorted(subdirs) + if __name__ == "__main__": - if os.path.exists('MANIFEST'): + if op.exists('MANIFEST'): os.remove('MANIFEST') setup(name=DISTNAME, @@ -65,27 +65,30 @@ 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'), - 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']) 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 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 # -----------------------------------------------------