Skip to content

Commit 1ab9fdc

Browse files
committed
RUFF: ruff check --fix; ruff format
1 parent b80468f commit 1ab9fdc

19 files changed

+61
-39
lines changed

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Configure sphinx."""
2+
23
import os
34
import sys
45
from datetime import datetime
@@ -17,7 +18,7 @@
1718
# -- Project information -----------------------------------------------------
1819
project = "pyprep"
1920
author = "PyPREP developers"
20-
copyright = f"2018, {author}. Last updated {datetime.now().isoformat()}"
21+
copyright = f"2018, {author}. Last updated {datetime.now().isoformat()}" # noqa: A001
2122

2223
# The short X.Y version
2324
version = pyprep.__version__

docs/sphinxext/gh_substitutions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
https://doughellmann.com/blog/2010/05/09/defining-custom-roles-in-sphinx/
77
88
"""
9+
910
from docutils.nodes import reference
1011
from docutils.parsers.rst.roles import set_classes
1112

examples/run_full_prep.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
# First we import what we need for this example.
3232
from pathlib import Path
3333

34+
import matplotlib.pyplot as plt
3435
import mne
3536
import numpy as np
3637
import scipy.io as sio
37-
import matplotlib.pyplot as plt
3838

3939
from pyprep.prep_pipeline import PrepPipeline
4040

@@ -103,9 +103,9 @@
103103
#
104104
# You can check the detected bad channels in each step of PREP.
105105

106-
print("Bad channels: {}".format(prep.interpolated_channels))
107-
print("Bad channels original: {}".format(prep.noisy_channels_original["bad_all"]))
108-
print("Bad channels after interpolation: {}".format(prep.still_noisy_channels))
106+
print(f"Bad channels: {prep.interpolated_channels}")
107+
print(f"Bad channels original: {prep.noisy_channels_original['bad_all']}")
108+
print(f"Bad channels after interpolation: {prep.still_noisy_channels}")
109109

110110
# Matlab's results
111111
# ----------------
@@ -164,7 +164,7 @@
164164
axs[0, 1].set_title("Original EEG", fontsize=14)
165165
# axs[0, 0].set_ylabel('Channel Number', fontsize=14)
166166
cb = fig.colorbar(im, ax=axs, fraction=0.05, pad=0.04)
167-
cb.set_label("\u03BCVolt", fontsize=14)
167+
cb.set_label("\u03bcVolt", fontsize=14)
168168

169169
EEG_new_matlab = sio.loadmat(fname_mat2)
170170
EEG_new_matlab = EEG_new_matlab["save_data"]
@@ -307,11 +307,11 @@
307307
###############################################################################
308308
# Mean square error of each step:
309309

310-
print("Raw data MSE: {}".format(EEG_raw_mse))
311-
print("Filtered data MSE: {}".format(EEG_new_mse))
312-
print("Line-noise removed data MSE: {}".format(EEG_mse))
313-
print("Referenced data MSE: {}".format(EEG_ref_mse))
314-
print("Interpolated data MSE: {}".format(EEG_final_mse))
310+
print(f"Raw data MSE: {EEG_raw_mse}")
311+
print(f"Filtered data MSE: {EEG_new_mse}")
312+
print(f"Line-noise removed data MSE: {EEG_mse}")
313+
print(f"Referenced data MSE: {EEG_ref_mse}")
314+
print(f"Interpolated data MSE: {EEG_final_mse}")
315315

316316
###############################################################################
317317
# Discussion

examples/run_ransac.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
###############################################################################
1818
# First we import what we need for this example.
19-
import numpy as np
19+
from time import perf_counter
20+
2021
import mne
22+
import numpy as np
2123
from scipy import signal as signal
22-
from time import perf_counter
2324

2425
from pyprep.find_noisy_channels import NoisyChannels
2526

pyprep/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Initialize PyPREP."""
2+
23
import pyprep.ransac as ransac # noqa: F401
34
from pyprep.find_noisy_channels import NoisyChannels # noqa: F401
45
from pyprep.prep_pipeline import PrepPipeline # noqa: F401

pyprep/find_noisy_channels.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""finds bad channels."""
2+
23
import mne
34
import numpy as np
45
from mne.utils import check_random_state, logger

pyprep/prep_pipeline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Module for PREP pipeline."""
2+
23
import mne
34
from mne.utils import check_random_state
45

pyprep/ransac.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""RANSAC bad channel identification."""
2+
23
import mne
34
import numpy as np
45
from mne.channels.interpolation import _make_interpolation_matrix
@@ -125,8 +126,9 @@ def find_bad_by_ransac(
125126

126127
# First, check that the argument types are valid
127128
if not isinstance(n_samples, int):
128-
err = "Argument 'n_samples' must be an int (got {0})"
129-
raise TypeError(err.format(type(n_samples).__name__))
129+
raise TypeError(
130+
f"Argument 'n_samples' must be an int (got {type(n_samples).__name__})"
131+
)
130132

131133
complete_chn_labs = np.asarray(complete_chn_labs)
132134

@@ -144,13 +146,17 @@ def find_bad_by_ransac(
144146

145147
if n_pred_chns <= 3:
146148
sample_pct = int(sample_prop * 100)
147-
e = "Too few channels in the original data to reliably perform RANSAC "
148-
e += "(minimum {0} for a sample size of {1}%)."
149-
raise IOError(e.format(int(np.floor(4.0 / sample_prop)), sample_pct))
149+
raise OSError(
150+
"Too few channels in the original data to reliably perform RANSAC"
151+
f"(minimum {int(np.floor(4.0 / sample_prop))} for a sample size "
152+
f"of {sample_pct}%)."
153+
)
150154
elif n_chans_good < (n_pred_chns + 1):
151-
e = "Too many noisy channels in the data to reliably perform RANSAC "
152-
e += "(only {0} good channels remaining, need at least {1})."
153-
raise IOError(e.format(n_chans_good, n_pred_chns + 1))
155+
raise OSError(
156+
"Too many noisy channels in the data to reliably perform RANSAC "
157+
f"(only {n_chans_good} good channels remaining, "
158+
f"need at least {n_pred_chns + 1})."
159+
)
154160

155161
# Before running, make sure we have enough memory when using the
156162
# smallest possible chunk size

pyprep/reference.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""functions of referencing part of PREP."""
2+
23
import logging
34

45
import numpy as np
@@ -214,7 +215,7 @@ def robust_reference(self, max_iterations=4):
214215
noisy_detector.find_all_bads(**self.ransac_settings)
215216
self.noisy_channels_original = noisy_detector.get_bads(as_dict=True)
216217
self._extra_info["initial_bad"] = noisy_detector._extra_info
217-
logger.info("Bad channels: {}".format(self.noisy_channels_original))
218+
logger.info(f"Bad channels: {self.noisy_channels_original}")
218219

219220
# Determine channels to use/exclude from initial reference estimation
220221
self.unusable_channels = _union(
@@ -279,7 +280,7 @@ def robust_reference(self, max_iterations=4):
279280
if bad_type not in ignore:
280281
bad_chans.update(noisy[bad_type])
281282
noisy["bad_all"] = list(bad_chans)
282-
logger.info("Bad channels: {}".format(noisy))
283+
logger.info(f"Bad channels: {noisy}")
283284

284285
if (
285286
iterations > 1
@@ -313,7 +314,7 @@ def robust_reference(self, max_iterations=4):
313314
signal, self.reference_signal, reference_index
314315
)
315316
iterations = iterations + 1
316-
logger.info("Iterations: {}".format(iterations))
317+
logger.info(f"Iterations: {iterations}")
317318

318319
return self.noisy_channels, self.reference_signal
319320

@@ -356,9 +357,7 @@ def remove_reference(signal, reference, index=None):
356357
else:
357358
if not isinstance(index, list):
358359
raise TypeError(
359-
"RemoveReference: Expected type list, got {} instead".format(
360-
type(index)
361-
)
360+
f"RemoveReference: Expected type list, got {type(index)} instead"
362361
)
363362
signal_referenced = signal.copy()
364363
signal_referenced[np.asarray(index), :] = (

pyprep/removeTrend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""High-pass filter and locally detrend the EEG signal."""
2+
23
import logging
34

45
import mne

0 commit comments

Comments
 (0)