Skip to content

Commit 9975a52

Browse files
committed
Example for message parser
1 parent d263b59 commit 9975a52

3 files changed

Lines changed: 265 additions & 2 deletions

File tree

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
{
2+
"cells": [
3+
{
4+
"metadata": {},
5+
"cell_type": "markdown",
6+
"source": "# Example code for connecting a Sciospec EIT device",
7+
"id": "8e6ea1591f787a86"
8+
},
9+
{
10+
"metadata": {},
11+
"cell_type": "markdown",
12+
"source": [
13+
"This script gives an example how to use this updated version of sciopy. \n",
14+
" \n",
15+
"Central new feature is an automated USB messaage parser, that parses incoming messages immediately and upon request saves data frames while running. For burst measurements AND continuous measurements with burst_count = 0"
16+
],
17+
"id": "e443e180ad6c1dfd"
18+
},
19+
{
20+
"metadata": {},
21+
"cell_type": "code",
22+
"outputs": [],
23+
"execution_count": null,
24+
"source": [
25+
"# Initialization\n",
26+
"import matplotlib.pyplot as plt\n",
27+
"import numpy as np\n",
28+
"import time\n",
29+
"from sciopy.sciopy import EIT_16_32_64_128, EitMeasurementSetup, available_serial_ports\n",
30+
"from sciopy.sciopy import make_results_folder\n",
31+
"# create a 'sciospec' EIT device\n",
32+
"n_el = 16\n",
33+
"sciospec = EIT_16_32_64_128(n_el)\n",
34+
"# connect device via USB-FS port\n",
35+
"print(available_serial_ports())\n",
36+
"sciospec.connect_device_FS(\"COM3\")\n",
37+
"savepath = \"../../data/\""
38+
],
39+
"id": "91983d17281c7ff1"
40+
},
41+
{
42+
"metadata": {},
43+
"cell_type": "code",
44+
"outputs": [],
45+
"execution_count": null,
46+
"source": [
47+
"# read system message buffer\n",
48+
"sciospec.SystemMessageCallback()"
49+
],
50+
"id": "1a8832c9510b72c9"
51+
},
52+
{
53+
"metadata": {},
54+
"cell_type": "code",
55+
"outputs": [],
56+
"execution_count": null,
57+
"source": [
58+
"# create a measurement setup\n",
59+
"setup = EitMeasurementSetup(\n",
60+
" burst_count=4,\n",
61+
" n_el=n_el,\n",
62+
" exc_freq=125_000,\n",
63+
" framerate=3,\n",
64+
" amplitude=0.01,\n",
65+
" inj_skip=n_el // 2,\n",
66+
" gain=1,\n",
67+
" adc_range=1\n",
68+
")\n",
69+
"sciospec.SetMeasurementSetup(setup)\n",
70+
"# look inside the docstring of the function and manual\n",
71+
"sciospec.GetMeasurementSetup(2)"
72+
],
73+
"id": "c1dbc04960e403ab"
74+
},
75+
{
76+
"metadata": {},
77+
"cell_type": "markdown",
78+
"source": [
79+
"### Usage of the \"old\" measure data command \n",
80+
"\n",
81+
"Here, the message parser is not utilized, technically faster processing of incoming messages. Messages are solely appended and processed into EITFrames and bursts"
82+
],
83+
"id": "890b0096ca6b8bb"
84+
},
85+
{
86+
"metadata": {},
87+
"cell_type": "code",
88+
"outputs": [],
89+
"execution_count": null,
90+
"source": [
91+
"data = sciospec.StartStopMeasurementFast(return_as=\"hex\")\n",
92+
"print(data.shape)"
93+
],
94+
"id": "initial_id"
95+
},
96+
{
97+
"metadata": {},
98+
"cell_type": "markdown",
99+
"source": [
100+
"\n",
101+
"### New measure-data function\n"
102+
],
103+
"id": "3301812b2d53b956"
104+
},
105+
{
106+
"metadata": {},
107+
"cell_type": "code",
108+
"outputs": [],
109+
"execution_count": null,
110+
"source": [
111+
"# 1) With burstcount\n",
112+
"sciospec.update_BurstCount(3) \n",
113+
"data= sciospec.StartStopMeasurement(return_as=\"eitframe\", bSaveData=False, bDeleteData=False,\n",
114+
" sSavePath=savepath, bResultsFolder=False)\n",
115+
"print(data.shape)\n",
116+
"\n",
117+
"# 2) Continuous measurement\n",
118+
"sciospec.update_BurstCount(0)\n",
119+
"data= sciospec.StartStopMeasurement(timeout= 5,return_as=\"eitframe\", bSaveData=False, bDeleteData=False,\n",
120+
" sSavePath=savepath,bResultsFolder=False) # measured for five seconds\n",
121+
"print(data.shape)\n",
122+
"\n",
123+
"\n",
124+
"\n",
125+
"# 3) Save data in real time and create an additional folder for storage\n",
126+
"data= sciospec.StartStopMeasurement(timeout= 5,return_as=\"eitframe\", bSaveData=True, bDeleteData=False,\n",
127+
" sSavePath=savepath,bResultsFolder=True) # measured for five seconds\n",
128+
"print(data.shape)\n",
129+
"\n",
130+
"\n",
131+
"\n",
132+
"\n",
133+
"# 4) For continuous saving results in the same folder, create a folder before and then pass it along\n",
134+
"sCurrPath= make_results_folder(bCreateResultsFolder=True, bSaveData=True, sSavePath=savepath)\n",
135+
"sciospec.StartStopMeasurement(timeout= 5,return_as=\"eitframe\", bSaveData=True, bDeleteData=True,\n",
136+
" sSavePath=sCurrPath,bResultsFolder=False) # measured for five seconds\n",
137+
"time.sleep(3)\n",
138+
"sciospec.StartStopMeasurement(timeout= 5,return_as=\"eitframe\", bSaveData=True, bDeleteData=True,\n",
139+
" sSavePath=sCurrPath,bResultsFolder=False) # measured for five seconds\n",
140+
"time.sleep(3)\n",
141+
"sciospec.StartStopMeasurement(timeout= 5,return_as=\"eitframe\", bSaveData=True, bDeleteData=True,\n",
142+
" sSavePath=sCurrPath,bResultsFolder=False) # measured for five seconds\n",
143+
"\n",
144+
"\n",
145+
"\n",
146+
"# Arguments:\n",
147+
"# bDeleteData: Data is not returned but if bSaveData=True saved, and is deleted from an internal buffer. For False, data is returned according to return_as\n",
148+
"# bSaveData: if Data should be saved in-time with the measurements. Data is saved at sSavePath, \n"
149+
],
150+
"id": "143a513757acfe71"
151+
},
152+
{
153+
"metadata": {},
154+
"cell_type": "markdown",
155+
"source": [
156+
"### Example on how to change the measurement mode with boundary conditions is updated\n",
157+
"\n",
158+
"Recommended is for every change of the measurement mode\n",
159+
"1. Restart Device\n",
160+
"2. Set new measurement mode"
161+
],
162+
"id": "e48b23b1ed247a39"
163+
},
164+
{
165+
"metadata": {},
166+
"cell_type": "code",
167+
"outputs": [],
168+
"execution_count": null,
169+
"source": [
170+
"# Standard setting \"singleended\" -> potential measurement\n",
171+
"sciospec.GetMeasurementSetup(2)\n",
172+
"sciospec.update_BurstCount(3) \n",
173+
"data= sciospec.StartStopMeasurement(return_as=\"eitframe\", bSaveData=False, bDeleteData=False,\n",
174+
" sSavePath=savepath, bResultsFolder=False)\n",
175+
"data_pot=np.abs(data[2])\n",
176+
"\n"
177+
],
178+
"id": "5db0b9e7255bf10b"
179+
},
180+
{
181+
"metadata": {},
182+
"cell_type": "code",
183+
"outputs": [],
184+
"execution_count": null,
185+
"source": [
186+
"# For updated setting, restart device\n",
187+
"sciospec.SoftwareReset()\n",
188+
"sciospec = EIT_16_32_64_128(16)\n",
189+
"print(available_serial_ports())\n",
190+
"sciospec.connect_device_FS(\"COM3\")\n",
191+
"sciospec.SetMeasurementSetup(setup)\n",
192+
"sciospec.update_measurement_mode(\"skip4\", \"internal\")\n",
193+
"sciospec.GetMeasurementSetup(2)\n",
194+
"# look inside the docstring of the function and manual\n",
195+
"\n",
196+
"sciospec.update_BurstCount(3) \n",
197+
"data= sciospec.StartStopMeasurement(return_as=\"eitframe\", bSaveData=False, bDeleteData=False,\n",
198+
" sSavePath=savepath, bResultsFolder=False)\n",
199+
"data_skip4= np.abs(data[2])\n",
200+
"\n",
201+
"\n",
202+
"fig, ax = plt.subplots(ncols=2)\n",
203+
"ax[0].imshow(data_pot, cmap=\"viridis\")\n",
204+
"ax[0].set_title(\"Singleended\")\n",
205+
"ax[1].imshow(data_skip4, cmap=\"viridis\")\n",
206+
"ax[1].set_title(\"Skip4\")\n",
207+
"plt.tight_layout()\n",
208+
"plt.show()"
209+
],
210+
"id": "72e8b4e384c52b7"
211+
},
212+
{
213+
"metadata": {},
214+
"cell_type": "code",
215+
"outputs": [],
216+
"execution_count": null,
217+
"source": [
218+
"\n",
219+
"# Alternatively,\n",
220+
"setup = EitMeasurementSetup(\n",
221+
" burst_count=4,\n",
222+
" n_el=n_el,\n",
223+
" exc_freq=125_000,\n",
224+
" framerate=3,\n",
225+
" amplitude=0.01,\n",
226+
" inj_skip=n_el // 2,\n",
227+
" gain=1,\n",
228+
" adc_range=1,\n",
229+
" mea_mode=\"skip2\",\n",
230+
" mea_mode_boundary=\"external\"\n",
231+
")\n",
232+
"sciospec.SetMeasurementSetup(setup)\n",
233+
"\n",
234+
"\n",
235+
"\n"
236+
],
237+
"id": "a026d514146eb1f0"
238+
}
239+
],
240+
"metadata": {
241+
"kernelspec": {
242+
"display_name": "Python 3",
243+
"language": "python",
244+
"name": "python3"
245+
},
246+
"language_info": {
247+
"codemirror_mode": {
248+
"name": "ipython",
249+
"version": 2
250+
},
251+
"file_extension": ".py",
252+
"mimetype": "text/x-python",
253+
"name": "python",
254+
"nbconvert_exporter": "python",
255+
"pygments_lexer": "ipython2",
256+
"version": "2.7.6"
257+
}
258+
},
259+
"nbformat": 4,
260+
"nbformat_minor": 5
261+
}

sciopy/EIT_16_32_64_128.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,6 @@ def GetMeasurementSetup(self, setup_of: str):
555555
print("TBD: Translation")
556556
self.print_msg = False
557557

558-
# todo
559558
def StartStopMeasurementFast(self, return_as="pot_mat"):
560559
"""
561560
Starts and stops a measurement process using the configured serial protocol (HS or FS).
@@ -622,7 +621,8 @@ def StartStopMeasurement(
622621
bSaveData (bool): Specifies if the measured data is saved in NPZ format
623622
bDeleteData (bool): Specifies if the measured data is deleted out of memory after each EITframe, with
624623
bSaveData=True, measured data is saved and then removed from RAM
625-
sSavepath (str): Specifies the sPath where the measured data is saved.
624+
sSavePath (str): Specifies the sPath where the measured data is saved.
625+
bResultsFolder (bool): Specifies if additionally a folder in sSavePath is created to store the data in
626626
627627
Returns:
628628
list or matrix: The measurement data in the format specified by `return_as`.

sciopy/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from .EIT_16_32_64_128 import EIT_16_32_64_128, EitMeasurementSetup
88
from .ISX_3 import ISX_3, EisMeasurementSetup
9+
from .usb_message_parser import make_results_folder
910

1011

1112
__all__ = [
@@ -14,4 +15,5 @@
1415
"EitMeasurementSetup",
1516
"ISX_3",
1617
"EisMeasurementSetup",
18+
"make_results_folder",
1719
]

0 commit comments

Comments
 (0)