From bc6d96776287ac5f7a50f9a73df0bd335f4b9df7 Mon Sep 17 00:00:00 2001 From: JacobTh98 <62538704+JacobTh98@users.noreply.github.com> Date: Fri, 30 Aug 2024 12:40:24 +0200 Subject: [PATCH 1/2] Dev (#23) * new example * v=0.4.3 * inserted n_el 16 and 32 save dicts * updated example scripts * new example for converting measurement directorys to csv * first implementation of npz to csv * corrected plot angle * fixed position error of measurement * 0.4.4 * added logo * deleted section * new release of 0.4.2 * added 0.5.0 * linting * appended ScioSpecMeasurementConfig * update examples * linting * flake * Update README.md * updated docstring and resolved import error * linting * deleted old docs * added excitation frequency * Inserted exc_freq to dependent files. * v==0.5.2 * prep for pytest publish * pctr * updated picture * v==0.6.0 * changed logo * Update README.md * v==0.6.1 * Update README.md * angle correction * inserted daytime and temperature * docstring and data format * temperature visualization * linting * new visualization and black linting==23.1.0 * updated black==23.1.0 * pypitest==0.6.1.4 * pypi test == 0.6.1.5 * pypi test == 0.6.1.5 * v==0.6.2 * implemented visualization, not added to init * linting * linting#2 * linting #3 * meshing * inserted citation cff * added citation cff * zenodo doi * inserted absolute valued potential data * Implemented mesh generation * gitignore .vscode * inserted raw string for fixing error. * changed function names and inserted v computation * linting * docstring and function descriptions. * linting * skipping first measured value * changed absolute label at potential matrix * init. mesh for import * first try to use pyvista * pyvisa changes * changed prepare for ml routine * merge dev to 3d * updated function * added file in ignore * modified configurations and added an example for 32 electrodes measurement * modified burst count * deleted prototyping functions. * ignored .vsc settings * updated reqs * fixed npz to csv conversion error * changed names of example measurements * deleted unspecified measurement example. * Adjusting the configurations * Ready for test measurements using 32 electrodes. * Inserted Issue marker in npz_to_csv.npz * working example measurement scripts * updated setup_m * linting and ignore * linting and updates * new example script * pypi test release * new release v==0.6.4 * updated readme * Updated Readme TDB * preperations for Ethernet connection * new pytest version and typos * linting * updated and undo some changes from pytest 0.6.4.7 * release==0.6.4.8 * channel group repeated bug resolved. * Added further information, optimized the .gitignore. * fixed current computation configuration bug. * v0.6.5 * fixed data type error * enables multiple pattern measurements * added package function to readme * typo documentation * linting * SoftwareReset usb-hs * docstring update * fixed variable name error * updated example --- examples/custom_measurement.py | 74 ++++++++++++--------------------- examples/measurement_n_el_16.py | 71 ------------------------------- examples/measurement_n_el_32.py | 71 ------------------------------- sciopy/__init__.py | 7 ++++ sciopy/sciospec_hs.py | 21 ++++++++++ sciopy/usb_hs_handling.py | 17 ++++++++ setup.py | 2 +- 7 files changed, 72 insertions(+), 191 deletions(-) delete mode 100644 examples/measurement_n_el_16.py delete mode 100644 examples/measurement_n_el_32.py create mode 100644 sciopy/sciospec_hs.py diff --git a/examples/custom_measurement.py b/examples/custom_measurement.py index b6c8f77..6cc4063 100644 --- a/examples/custom_measurement.py +++ b/examples/custom_measurement.py @@ -2,69 +2,47 @@ from sciopy import ( SystemMessageCallback, - set_measurement_config, - connect_COM_port, - StartStopMeasurement, - reshape_full_message_in_bursts, - del_hex_in_list, - split_bursts_in_frames, + sciospec_measurement, + connect_COM_port_usb_hs, + set_measurement_config_usb_hs, + SystemMessageCallback_usb_hs, ) from sciopy.sciopy_dataclasses import ScioSpecMeasurementSetup s_path = "" -files_offset = 0 -sciospec_measurement_setup = ScioSpecMeasurementSetup( +Sciospec = connect_COM_port_usb_hs() + +ssms = ScioSpecMeasurementSetup( burst_count=1, # The number of measurements to be performed. - total_meas_num=10, # Repetitions of burst count - n_el=64, # Set 16, 32, 48 or 64 and do not forget to change the channel_group. + total_meas_num=1, # Repetitions of burst count + n_el=32, # Set 16, 32, 48 or 64 and do not forget to change the channel_group. channel_group=[ 1, 2, - 3, - 4, ], # Use [1] for n_el=16, [1,2] for n_el=32, [1,2,3] for n_el=48, and [1,2,3,4] for n_el=64 - exc_freq=10_000, # 10,000Hz = 10kHz - framerate=5, # Measurements per second + exc_freq=125_000, # 10,000Hz = 10kHz + framerate=10, # Measurements per second amplitude=0.01, # 0.01A = 10mA (maximum) - inj_skip=0, # injection electrode skip + inj_skip=16, # injection electrode skip gain=1, adc_range=1, # +/- 1V - notes="None", # add measurement information - configured=False, + notes="test measurement", # add measurement information + configured=True, ) -# Connect ScioSpec device -COM_ScioSpec = connect_COM_port(port="/dev/ttyACM0") - -# Send configuration -set_measurement_config(serial=COM_ScioSpec, ssms=sciospec_measurement_setup) - -# Read out system callback -SystemMessageCallback(COM_ScioSpec, prnt_msg=True) - -# Start and stop single measurement -measurement_data_hex = StartStopMeasurement(COM_ScioSpec) -# Delete hex in mesured buffer -measurement_data = del_hex_in_list(measurement_data_hex) -# Reshape the full mesaurement buffer. Depending on number of electrodes -split_measurement_data = reshape_full_message_in_bursts( - measurement_data, sciospec_measurement_setup -) -measurement_data = split_bursts_in_frames( - split_measurement_data, sciospec_measurement_setup -) +set_measurement_config_usb_hs(Sciospec, ssms) +SystemMessageCallback_usb_hs(Sciospec, prnt_msg=True) -# Set to "True" to save single measurement -save = True +sciospec_data = sciospec_measurement(Sciospec, ssms) -if save: - for bursts in measurement_data: - np.savez( - s_path + "sample_{0:06d}.npz".format(files_offset), - config=sciospec_measurement_setup, - data=bursts, - ) - files_offset += 1 - SystemMessageCallback(COM_ScioSpec, prnt_msg=False) +file_idx = 0 +for bursts in sciospec_data: + np.savez( + s_path + "sample_{0:06d}.npz".format(file_idx), + config=ssms, + data=bursts, + ) + file_idx += 1 +SystemMessageCallback(COM_ScioSpec, prnt_msg=False) diff --git a/examples/measurement_n_el_16.py b/examples/measurement_n_el_16.py deleted file mode 100644 index 97bce6b..0000000 --- a/examples/measurement_n_el_16.py +++ /dev/null @@ -1,71 +0,0 @@ -# Outdated but still usable. - -import numpy as np -from datetime import datetime - -from sciopy import ( - SystemMessageCallback, - conf_n_el_16_adjacent, - connect_COM_port, - StartStopMeasurement, - reshape_full_message_in_bursts, - del_hex_in_list, - split_bursts_in_frames, -) - -from sciopy.sciopy_dataclasses import ScioSpecMeasurementConfig - -scio_spec_measurement_config = ScioSpecMeasurementConfig( - com_port="/dev/ttyACM0", # substitute your com port - burst_count=10, - n_el=16, - channel_group=[1], - actual_sample=0, # start sample number - s_path="measurement_16/", - object="circle", - size=0.1, - material="PLA", - saline_conductivity=(0.0, "mS"), - temperature=20.0, - water_lvl=20.0, - exc_freq=10000.0, - datetime=datetime.now().strftime("%Y/%m/%d %H:%M:%S"), -) - -# Connect ScioSpec device -COM_ScioSpec = connect_COM_port(port=scio_spec_measurement_config.com_port) -# Send configuration -scio_spec_measurement_config = conf_n_el_16_adjacent( - COM_ScioSpec, scio_spec_measurement_config -) -# Read out system callback -SystemMessageCallback(COM_ScioSpec, prnt_msg=True) - -# Start and stop single measurement -measurement_data_hex = StartStopMeasurement(COM_ScioSpec) -# Delete hex in mesured buffer -measurement_data = del_hex_in_list(measurement_data_hex) -# Reshape the full mesaurement buffer. Depending on number of electrodes -split_measurement_data = reshape_full_message_in_bursts( - measurement_data, scio_spec_measurement_config -) -measurement_data = split_bursts_in_frames( - split_measurement_data, scio_spec_measurement_config -) - -# Set to "True" to save single measurement -save = True - -if save: - files_offset = scio_spec_measurement_config.actual_sample - for bursts in measurement_data: - np.savez( - scio_spec_measurement_config.s_path - + "sample_{0:06d}.npz".format(files_offset), - config=scio_spec_measurement_config, - data=bursts, - ) - files_offset += 1 - scio_spec_measurement_config.actual_sample = files_offset - - SystemMessageCallback(COM_ScioSpec, prnt_msg=False) diff --git a/examples/measurement_n_el_32.py b/examples/measurement_n_el_32.py deleted file mode 100644 index 38e20dc..0000000 --- a/examples/measurement_n_el_32.py +++ /dev/null @@ -1,71 +0,0 @@ -# Outdated but still usable. - -import numpy as np -from datetime import datetime - -from sciopy import ( - SystemMessageCallback, - conf_n_el_32_adjacent, - connect_COM_port, - StartStopMeasurement, - reshape_full_message_in_bursts, - del_hex_in_list, - split_bursts_in_frames, -) - -from sciopy.sciopy_dataclasses import ScioSpecMeasurementConfig - -scio_spec_measurement_config = ScioSpecMeasurementConfig( - com_port="/dev/ttyACM0", - burst_count=1, - n_el=32, - channel_group=[1, 2], - actual_sample=0, - s_path="measurement_32/", - object="circle", - size=0.1, - material="PLA", - saline_conductivity=(0.0, "mS"), - temperature=20.0, - water_lvl=20.0, - exc_freq=10000.0, - datetime=datetime.now().strftime("%Y/%m/%d %H:%M:%S"), -) - -# Connect ScioSpec device -COM_ScioSpec = connect_COM_port(port=scio_spec_measurement_config.com_port) -# Send configuration -scio_spec_measurement_config = conf_n_el_32_adjacent( - COM_ScioSpec, scio_spec_measurement_config -) -# Read out system callback -SystemMessageCallback(COM_ScioSpec, prnt_msg=True) - -# Start and stop single measurement -measurement_data_hex = StartStopMeasurement(COM_ScioSpec) -# Delete hex in mesured buffer -measurement_data = del_hex_in_list(measurement_data_hex)[4:] -# Reshape the full mesaurement buffer. Depending on number of electrodes -split_measurement_data = reshape_full_message_in_bursts( - measurement_data, scio_spec_measurement_config -) -measurement_data = split_bursts_in_frames( - split_measurement_data, scio_spec_measurement_config -) - -# Set to "True" to save single measurement -save = True - -if save: - files_offset = scio_spec_measurement_config.actual_sample - for bursts in measurement_data: - np.savez( - scio_spec_measurement_config.s_path - + "sample_{0:06d}.npz".format(files_offset), - config=scio_spec_measurement_config, - data=bursts, - ) - files_offset += 1 - scio_spec_measurement_config.actual_sample = files_offset - - SystemMessageCallback(COM_ScioSpec, prnt_msg=False) diff --git a/sciopy/__init__.py b/sciopy/__init__.py index 1c183a9..1e1cc2d 100644 --- a/sciopy/__init__.py +++ b/sciopy/__init__.py @@ -8,6 +8,7 @@ convert_fulldir_doteit_to_npz, ) + from .com_handling import ( available_serial_ports, connect_COM_port, @@ -20,6 +21,7 @@ set_measurement_config_usb_hs, SystemMessageCallback_usb_hs, StartStopMeasurement_usb_hs, + SoftwareReset_usb_hs, ) from .print_command_info import ( @@ -102,6 +104,8 @@ mesh_sample, ) +from .sciospec_hs import sciospec_measurement + # TBD from .configurations import configuration_01 __all__ = [ @@ -123,6 +127,7 @@ "set_measurement_config_usb_hs", "SystemMessageCallback_usb_hs", "StartStopMeasurement_usb_hs", + "SoftwareReset_usb_hs", # .print_command_info "print_syntax", "print_general_system_messages", @@ -190,4 +195,6 @@ "add_circle_anomaly", "plot_mesh", "mesh_sample", + # .sciospec_hs + "sciospec_measurement", ] diff --git a/sciopy/sciospec_hs.py b/sciopy/sciospec_hs.py new file mode 100644 index 0000000..f2195f5 --- /dev/null +++ b/sciopy/sciospec_hs.py @@ -0,0 +1,21 @@ +try: + import serial +except ImportError: + print("Could not import module: serial") + +from sciopy import ( + StartStopMeasurement_usb_hs, + del_hex_in_list, + reshape_full_message_in_bursts, + split_bursts_in_frames, +) + +from sciopy.sciopy_dataclasses import ScioSpecMeasurementSetup + + +def sciospec_measurement(COM_Sciospec, ssms: ScioSpecMeasurementSetup) -> None: + measurement_data_hex = StartStopMeasurement_usb_hs(COM_Sciospec) + measurement_data = del_hex_in_list(measurement_data_hex) + split_measurement_data = reshape_full_message_in_bursts(measurement_data, ssms) + measurement_data = split_bursts_in_frames(split_measurement_data, ssms) + return measurement_data diff --git a/sciopy/usb_hs_handling.py b/sciopy/usb_hs_handling.py index f1f1313..0fef609 100644 --- a/sciopy/usb_hs_handling.py +++ b/sciopy/usb_hs_handling.py @@ -1,5 +1,6 @@ from pyftdi.ftdi import Ftdi import struct +import time from typing import Union from sciopy.sciopy_dataclasses import ( ScioSpecMeasurementSetup, @@ -266,3 +267,19 @@ def StartStopMeasurement_usb_hs(serial: Ftdi, print_msg: bool = False) -> list: serial.write_data(bytearray([0xB4, 0x01, 0x00, 0xB4])) SystemMessageCallback_usb_hs(serial, prnt_msg=False, ret_hex_int="int") return measurement_data_hex + + +def SoftwareReset_usb_hs(serial: Ftdi, print_msg: bool = True) -> None: + """ + Reset the ScioSpec device. + + Parameters + ---------- + serial : Ftdi + USB-HS serial connection + print_msg : bool, optional + print the callback message, by default True + """ + serial.write_data(bytearray([0xA1, 0x00, 0xA1])) + time.sleep(5) + SystemMessageCallback_usb_hs(serial, print_msg) diff --git a/setup.py b/setup.py index c131c75..18e556b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setuptools.setup( name="sciopy", - version="0.7.1", + version="0.7.1.3", author="Jacob Peter Thönes", author_email="jacob.thoenes@uni-rostock.de", description="Python based interface module for communication with the Sciospec Electrical Impedance Tomography (EIT) device.", From b36c97c21d7e723ea66e88baff08e6caa0e6852a Mon Sep 17 00:00:00 2001 From: JacobTh98 <62538704+JacobTh98@users.noreply.github.com> Date: Mon, 2 Sep 2024 09:14:30 +0200 Subject: [PATCH 2/2] Update custom_measurement.py --- examples/custom_measurement.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/custom_measurement.py b/examples/custom_measurement.py index 6cc4063..16d5a7f 100644 --- a/examples/custom_measurement.py +++ b/examples/custom_measurement.py @@ -1,7 +1,6 @@ import numpy as np from sciopy import ( - SystemMessageCallback, sciospec_measurement, connect_COM_port_usb_hs, set_measurement_config_usb_hs, @@ -12,8 +11,10 @@ s_path = "" +# connect device Sciospec = connect_COM_port_usb_hs() +# configuration ssms = ScioSpecMeasurementSetup( burst_count=1, # The number of measurements to be performed. total_meas_num=1, # Repetitions of burst count @@ -31,10 +32,11 @@ notes="test measurement", # add measurement information configured=True, ) - +# write config to device set_measurement_config_usb_hs(Sciospec, ssms) SystemMessageCallback_usb_hs(Sciospec, prnt_msg=True) +# measurement sciospec_data = sciospec_measurement(Sciospec, ssms) file_idx = 0 @@ -45,4 +47,3 @@ data=bursts, ) file_idx += 1 -SystemMessageCallback(COM_ScioSpec, prnt_msg=False)