Skip to content

Commit 01f79b5

Browse files
committed
Black formatting
1 parent 4a0bdb8 commit 01f79b5

File tree

6 files changed

+212
-81
lines changed

6 files changed

+212
-81
lines changed

sciopy/EIT_16_32_64_128.py

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929
}
3030

3131
from .sciopy_dataclasses import EitMeasurementSetup
32-
from sciopydev.sciopy.usb_message_parser import (MessageParser, make_eitframes_hex, get_data_as_matrix,
33-
make_results_folder)
32+
from sciopydev.sciopy.usb_message_parser import (
33+
MessageParser,
34+
make_eitframes_hex,
35+
get_data_as_matrix,
36+
make_results_folder,
37+
)
3438

3539

3640
class EIT_16_32_64_128:
@@ -152,7 +156,6 @@ def disconnect_device(self):
152156
"""
153157
self.device.close()
154158

155-
156159
def send_message(self, message):
157160
"""
158161
Wrapper function to send a byte array to the device. Communication method is based on the defined serial
@@ -166,7 +169,6 @@ def send_message(self, message):
166169
elif self.serial_protocol == "FS":
167170
self.device.write(message)
168171

169-
170172
def read_message(self):
171173
"""
172174
Wrapper function to read single bytes from the device. Communication method is based on the defined serial
@@ -253,7 +255,9 @@ def write_command_string(self, command):
253255
"""
254256
self.cMessageParser.bPrintMessages = self.print_msg
255257
self.send_message(command)
256-
self.cMessageParser.read_usb_till_timeout(bSaveData=False, bDeleteDataFrame=True)
258+
self.cMessageParser.read_usb_till_timeout(
259+
bSaveData=False, bDeleteDataFrame=True
260+
)
257261

258262
# --- sciospec device commands
259263

@@ -482,8 +486,9 @@ def ResetMeasurementSetup(self):
482486
self.write_command_string(bytearray([0xB0, 0x01, 0x01, 0xB0]))
483487
self.print_msg = False
484488

485-
486-
def update_measurement_mode(self, meamode: str = "skip4", boundary: str = "external"):
489+
def update_measurement_mode(
490+
self, meamode: str = "skip4", boundary: str = "external"
491+
):
487492
"""
488493
Updates the measurement modes out of the options "singleended", "skip0", "skip2" or "skip4"
489494
@@ -492,20 +497,27 @@ def update_measurement_mode(self, meamode: str = "skip4", boundary: str = "exter
492497
boundary (str): Return if the boundary for skip patterns is internal of a channel group or external for all
493498
optional channels
494499
"""
495-
meamodeoptions = {"singleended": 0x01, "skip0": 0x02, "skip2": 0x03, "skip4": 0x04}
500+
meamodeoptions = {
501+
"singleended": 0x01,
502+
"skip0": 0x02,
503+
"skip2": 0x03,
504+
"skip4": 0x04,
505+
}
496506
self.print_msg = True
497507
try:
498508
cmd = meamodeoptions[meamode]
499509
except:
500-
print("Option for measurement mode is unknown. Measurement mode ist set to single-ended.")
510+
print(
511+
"Option for measurement mode is unknown. Measurement mode ist set to single-ended."
512+
)
501513
cmd = 0x01
502514
if boundary == "external":
503515
bnd = 0x02
504516
else:
505517
bnd = 0x01
506518
self.write_command_string(bytearray([0xB0, 0x03, 0x08, cmd, bnd, 0xB0]))
507519
self.print_msg = False
508-
#todo read out ACK messages
520+
# todo read out ACK messages
509521

510522
def GetMeasurementSetup(self, setup_of: str):
511523
"""
@@ -542,7 +554,7 @@ def GetMeasurementSetup(self, setup_of: str):
542554
print("TBD: Translation")
543555
self.print_msg = False
544556

545-
#todo
557+
# todo
546558
def StartStopMeasurementFast(self, return_as="pot_mat"):
547559
"""
548560
Starts and stops a measurement process using the configured serial protocol (HS or FS).
@@ -582,9 +594,15 @@ def StartStopMeasurementFast(self, return_as="pot_mat"):
582594
elif return_as == "pot_mat":
583595
return self.get_data_as_matrix()
584596

585-
586-
def StartStopMeasurementNew(self, timeout:int=0, return_as="pot_mat", bSaveData:bool=False, bDeleteData:bool=False,
587-
sSavepath:str="C/", bResultsFolder=True):
597+
def StartStopMeasurementNew(
598+
self,
599+
timeout: int = 0,
600+
return_as="pot_mat",
601+
bSaveData: bool = False,
602+
bDeleteData: bool = False,
603+
sSavepath: str = "C/",
604+
bResultsFolder=True,
605+
):
588606
"""
589607
Starts and stops a measurement process using the configured serial protocol (HS or FS).
590608
Sends appropriate commands to the device to initiate and terminate measurement.
@@ -611,24 +629,40 @@ def StartStopMeasurementNew(self, timeout:int=0, return_as="pot_mat", bSaveData:
611629

612630
# Start measurement
613631
self.cMessageParser.clear_out_data()
614-
sCurrentPath= make_results_folder(bResultsFolder, bSaveData, sSavepath) # No new path is created if bResultsFolder=False
615-
632+
sCurrentPath = make_results_folder(
633+
bResultsFolder, bSaveData, sSavepath
634+
) # No new path is created if bResultsFolder=False
635+
616636
self.send_message(bytearray([0xB4, 0x01, 0x01, 0xB4]))
617637
self.cMessageParser.bPrintMessages = False
618638
if timeout != 0:
619-
self.cMessageParser.read_usb_for_seconds(timeout, bSaveData=bSaveData, bDeleteDataFrame=bDeleteData,
620-
sSavePath=sCurrentPath,bResultsFolder=False )
639+
self.cMessageParser.read_usb_for_seconds(
640+
timeout,
641+
bSaveData=bSaveData,
642+
bDeleteDataFrame=bDeleteData,
643+
sSavePath=sCurrentPath,
644+
bResultsFolder=False,
645+
)
621646
else:
622-
if self.setup.burst_count ==0:
647+
if self.setup.burst_count == 0:
623648
print("Burst count for this setup needs to be >=1")
624649
return
625-
self.cMessageParser.read_usb_till_timeout(bSaveData=bSaveData, bDeleteDataFrame=bDeleteData,sSavePath=sSavepath, bResultsFolder=False)
650+
self.cMessageParser.read_usb_till_timeout(
651+
bSaveData=bSaveData,
652+
bDeleteDataFrame=bDeleteData,
653+
sSavePath=sSavepath,
654+
bResultsFolder=False,
655+
)
626656

627657
# Stop measurement
628658
self.send_message(bytearray([0xB4, 0x01, 0x00, 0xB4]))
629659
# All data is returned if wanted
630-
data = self.cMessageParser.read_usb_till_timeout(bSaveData=bSaveData, bDeleteDataFrame=bDeleteData,
631-
sSavePath=sCurrentPath, bResultsFolder=False)
660+
data = self.cMessageParser.read_usb_till_timeout(
661+
bSaveData=bSaveData,
662+
bDeleteDataFrame=bDeleteData,
663+
sSavePath=sCurrentPath,
664+
bResultsFolder=False,
665+
)
632666

633667
if bDeleteData:
634668
return
@@ -639,8 +673,6 @@ def StartStopMeasurementNew(self, timeout:int=0, return_as="pot_mat", bSaveData:
639673
elif return_as == "eitframe":
640674
return data
641675

642-
643-
644676
def get_data_as_matrix(self):
645677
"""
646678
Converts the raw EIT data into a 3D matrix of potentials.

sciopy/com_util.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from glob import glob
1616
from .datatype_conversion import *
1717

18+
1819
def available_serial_ports() -> list:
1920
"""
2021
Lists serial port names.
@@ -66,7 +67,6 @@ def clTbt_dp(val: float) -> list:
6667
return [int(ele) for ele in struct.pack(">d", val)]
6768

6869

69-
7070
def reshape_full_message_in_bursts(lst: list, ssms: EitMeasurementSetup) -> np.ndarray:
7171
"""
7272
Takes the full message buffer and splits this message depeding on the measurement configuration into the
@@ -106,11 +106,10 @@ def length_correction(array: list) -> list:
106106
# split in burst count messages
107107
split_length = lst.shape[0] // ssms.burst_count
108108
for split in range(ssms.burst_count):
109-
split_list.append(lst[split * split_length: (split + 1) * split_length])
109+
split_list.append(lst[split * split_length : (split + 1) * split_length])
110110
return np.array(split_list)
111111

112112

113-
114113
def parse_single_frame(lst_ele: np.ndarray) -> SingleFrame:
115114
"""
116115
Parse single data to the class SingleFrame.
@@ -130,8 +129,8 @@ def parse_single_frame(lst_ele: np.ndarray) -> SingleFrame:
130129
for i in range(11, 135, 8):
131130
enum += 1
132131
channels[f"ch_{enum}"] = complex(
133-
bytesarray_to_float(lst_ele[i: i + 4]),
134-
bytesarray_to_float(lst_ele[i + 4: i + 8]),
132+
bytesarray_to_float(lst_ele[i : i + 4]),
133+
bytesarray_to_float(lst_ele[i + 4 : i + 8]),
135134
)
136135

137136
excitation_stgs = np.array([single_hex_to_int(ele) for ele in lst_ele[3:5]])
@@ -149,7 +148,7 @@ def parse_single_frame(lst_ele: np.ndarray) -> SingleFrame:
149148

150149

151150
def split_bursts_in_frames(
152-
split_list: np.ndarray, burst_count: int, channel_group: list
151+
split_list: np.ndarray, burst_count: int, channel_group: list
153152
) -> np.ndarray:
154153
"""
155154
Takes the splitted list from `reshape_full_message_in_bursts()` and parses the single frames.

sciopy/datatype_conversion.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
TWOPOWER16 = 65536
1414
TWOPOWER8 = 256
1515

16+
1617
# -------------------------------------------------------------------------------------------------------------------- #
1718
# -------------------------------------------------------------------------------------------------------------------- #
1819
def del_hex_in_list(lst: list) -> np.ndarray:
@@ -169,7 +170,12 @@ def four_byte_to_int(bytelist):
169170
int
170171
integer number
171172
"""
172-
return TWOPOWER24 * bytelist[0] + TWOPOWER16 * bytelist[1] + TWOPOWER8 * bytelist[2] + bytelist[3]
173+
return (
174+
TWOPOWER24 * bytelist[0]
175+
+ TWOPOWER16 * bytelist[1]
176+
+ TWOPOWER8 * bytelist[2]
177+
+ bytelist[3]
178+
)
173179

174180

175181
# -------------------------------------------------------------------------------------------------------------------- #

sciopy/device_interface.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Project :sciopy
3+
Directory: sciopy/sciopy
4+
File : device_interface.py
5+
Author :Patricia Fuchs
6+
Date :26.11.2025 14:04
7+
"""
8+
9+
try:
10+
import serial
11+
except ImportError:
12+
print("Could not import module: serial")
13+
14+
# -------------------------------------------------------------------------------------------------------------------- #
15+
# -------------------------------------------------------------------------------------------------------------------- #
16+
17+
18+
class DeviceInterface:
19+
def __init__(self):
20+
self.sProtocol = "None"
21+
22+
def send_data(self, data):
23+
pass
24+
25+
def read_data(self):
26+
return None
27+
28+
29+
import serial
30+
31+
32+
class USB_FS_Device(DeviceInterface):
33+
def __init__(self, port: str, baudrate: int = 9600, timeout: int = 9000):
34+
super().__init__()
35+
self.sProtocol = "FS"
36+
self.device = serial.Serial(
37+
port=port,
38+
baudrate=baudrate,
39+
timeout=timeout,
40+
parity=serial.PARITY_NONE,
41+
stopbits=serial.STOPBITS_ONE,
42+
bytesize=serial.EIGHTBITS,
43+
)
44+
self.name = self.device.name
45+
46+
def send_data(self, data):
47+
self.device.write(data)
48+
49+
def read_data(self):
50+
return self.device.read()
51+
52+
53+
class USB_HS_Device(DeviceInterface):
54+
def __init__(self, port: str, baudrate: int = 9600, timeout: int = 9000):
55+
super().__init__()

sciopy/sciopy_dataclasses.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import List, Tuple, Union
55
import numpy.typing as npt
66

7+
78
@dataclass
89
class EitMeasurementSetup:
910
"""
@@ -213,7 +214,6 @@ class PreperationConfig:
213214
n_samples: int
214215

215216

216-
217217
# -------------------------------------------------------------------------------------------------------------------- #
218218
@dataclass
219219
class EITFrame:
@@ -233,11 +233,10 @@ class EITFrame:
233233
for f in used frequency stages:
234234
for c in all used channels: -> insert complex value
235235
"""
236+
236237
n_el: int # Number of used electrodes
237238
excitation_stgs: npt.NDArray[int] # Num Excitation Settings X 2
238239
frequency_stgs: npt.NDArray[int] # List of Frequency-Sweep Settings,
239240
timestamp1: int # [ms]
240241
timestamp2: int
241242
ppcData: npt.NDArray[complex] # Channels 1-(64) all channel groups combined
242-
243-

0 commit comments

Comments
 (0)