Skip to content

Commit 7cabfc3

Browse files
committed
Linted code, sorted imports
1 parent ccf3e27 commit 7cabfc3

4 files changed

Lines changed: 45 additions & 30 deletions

File tree

src/explorepy/asr_processor.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1+
import logging
12
import math
23
import time
3-
from enum import Enum, auto
4+
from enum import (
5+
Enum,
6+
auto
7+
)
48

5-
from eegprep import clean_flatlines
69
import numpy as np
7-
import logging
8-
9-
from eegprep import clean_windows
10+
from eegprep import (
11+
clean_flatlines,
12+
clean_windows
13+
)
1014
from eegprep.utils import round_mat
11-
from eegprep.utils.asr import asr_calibrate, asr_process
15+
from eegprep.utils.asr import (
16+
asr_calibrate,
17+
asr_process
18+
)
1219

1320
from explorepy.filters import ExGFilter
1421

22+
1523
logger = logging.getLogger(__name__)
1624

1725

@@ -24,18 +32,20 @@ class State(Enum):
2432
def clean_calib_data(clean_data, sampling_rate):
2533
EEG = {'data': clean_data, 'srate': sampling_rate, 'xmin': 0}
2634
try:
27-
cleaned_windows = clean_windows(EEG) # throws index error
28-
logger.info(f"cleaned window shape: {cleaned_windows[0]['data'].shape} and original data shape: {clean_data.shape}")
35+
cleaned_windows = clean_windows(EEG) # throws index error
36+
logger.info(f"cleaned window shape: {cleaned_windows[0]['data'].shape} and "
37+
f"original data shape: {clean_data.shape}")
2938

3039
cleaned = clean_flatlines(cleaned_windows[0])
3140
if cleaned['data'].shape[0] != clean_data.shape[0]:
3241
logger.info(f"clean_data.shape: f{clean_data.shape} and cleaned['data'].shape: {cleaned['data'].shape}")
3342
raise IndexError
3443
return cleaned['data'], State.STABLE
3544
except IndexError:
36-
logger.info(f"Calibration error")
45+
logger.info("Calibration error")
3746
return None, State.CALIBRATION_ERROR
3847

48+
3949
def asr_pipeline(data_array, sampling_rate, n_chan, state, step_size=None, window_len=None, max_dims=0.66):
4050
"""This code is mostly taken from the eegprep implementation of clean_asr and adapted to work with a previously
4151
calculated state."""

src/explorepy/csv_client.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import time
21
import os
3-
from enum import Enum, auto
2+
import time
3+
from enum import (
4+
Enum,
5+
auto
6+
)
7+
48
import numpy as np
5-
from explorepy.packet import BleImpedancePacket, DeviceInfoBLE, OrientationV1, OrientationV2
69
from pylsl import local_clock
7-
from typing_extensions import override
10+
11+
from explorepy.packet import (
12+
BleImpedancePacket,
13+
DeviceInfoBLE,
14+
OrientationV2
15+
)
816

917

1018
class ClientState(Enum):
@@ -13,14 +21,16 @@ class ClientState(Enum):
1321
STREAMING = auto()
1422
STOPPED = auto()
1523

24+
1625
class PacketSize(Enum):
1726
EEG_8 = 40
1827
EEG_32 = 112
1928
ORN = 50
2029
DEVICE_INFO = 38
2130

31+
2232
class CsvClient:
23-
def __init__(self, channel_count, file_path: str=None):
33+
def __init__(self, channel_count, file_path: str = None):
2434
if file_path is None:
2535
self.file_name = "32channel_semidry_artefacts_ExG.csv"
2636
file_path = os.path.join("/Users/sonjastefani/Documents/dev/explore-desktop/test-data/", self.file_name)
@@ -31,10 +41,10 @@ def __init__(self, channel_count, file_path: str=None):
3141
raise FileNotFoundError(f"File not found: {file_path}")
3242

3343
self.server = CsvServer(
34-
channel_count=channel_count,
35-
csv_path=file_path,
36-
loop=True
37-
)
44+
channel_count=channel_count,
45+
csv_path=file_path,
46+
loop=True
47+
)
3848
self._state = ClientState.DISCONNECTED
3949

4050
def set_state(self, state: ClientState):
@@ -73,7 +83,6 @@ def read(self):
7383
device_info_packet.set_info(self.server.device_info)
7484
return device_info_packet
7585

76-
7786
self.server.tick += 1
7887
if self.server.tick % 5 == 0:
7988
orn_packet = OrientationMock(timestamp=self.server.ts, payload=None)
@@ -97,9 +106,6 @@ def read(self):
97106
def write(self, bytes):
98107
pass
99108

100-
import numpy as np
101-
from pylsl import local_clock
102-
103109

104110
class CsvServer:
105111
def __init__(self, channel_count: int, csv_path: str, loop: bool = True):
@@ -108,7 +114,7 @@ def __init__(self, channel_count: int, csv_path: str, loop: bool = True):
108114

109115
self.channel_count = channel_count
110116
self.loop = loop
111-
self.csv_data = np.loadtxt(csv_path, delimiter=',', skiprows=1) # skip row 0
117+
self.csv_data = np.loadtxt(csv_path, delimiter=',', skiprows=1) # skip row 0
112118

113119
self.csv_ts = self.csv_data[:, 0]
114120
self.csv_data = self.csv_data[:, 1:]
@@ -182,6 +188,7 @@ def read_sample(self):
182188
def read_device_info(self):
183189
return self.device_info
184190

191+
185192
class DeviceInfoMock(DeviceInfoBLE):
186193
def __init__(self, timestamp, payload, time_offset=0):
187194
self.timestamp = timestamp

src/explorepy/parser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
import os
32
"""Parser module"""
43
import asyncio
54
import binascii
@@ -83,8 +82,8 @@ def start_streaming(self, device_name, mac_address, file_path=None):
8382
self.stream_interface = MockBtClient(device_name=device_name, mac_address=mac_address)
8483
elif explorepy.get_bt_interface() == 'csv':
8584
from explorepy.csv_client import CsvClient
86-
device_id = str.split(device_name, '_')[1] # split by underscore and take second part
87-
ch_count = 32 if device_id[0] == 'D' else 8 #dynamic channel selection based on first character
85+
device_id = str.split(device_name, '_')[1] # split by underscore and take second part
86+
ch_count = 32 if device_id[0] == 'D' else 8 # dynamic channel selection based on first character
8887
self.stream_interface = CsvClient(ch_count, file_path=file_path)
8988
elif is_usb_mode():
9089
from explorepy.serial_client import SerialStream

src/explorepy/stream_processor.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
)
1515

1616
import numpy as np
17+
18+
from explorepy.asr_processor import AsrProcessor
1719
from explorepy.command import (
1820
DeviceConfiguration,
1921
ZMeasurementDisable,
@@ -22,10 +24,8 @@
2224
from explorepy.filters import ExGFilter
2325
from explorepy.packet import (
2426
EEG,
25-
CalibrationInfo,
26-
CalibrationInfo_USBC,
27-
CleanEEG,
2827
CalibrationInfoBase,
28+
CleanEEG,
2929
CommandRCV,
3030
CommandStatus,
3131
DeviceInfo,
@@ -45,7 +45,6 @@
4545
is_usb_mode
4646
)
4747

48-
from explorepy.asr_processor import AsrProcessor
4948

5049
TOPICS =\
5150
Enum('Topics', 'raw_ExG filtered_ExG asr_ExG device_info marker raw_orn cmd_ack env cmd_status imp packet_bin')

0 commit comments

Comments
 (0)