From 1e46aaa1766e5fa47a808d3685b263e32a8a4dea Mon Sep 17 00:00:00 2001 From: CPD Date: Fri, 7 Feb 2025 17:13:04 +0100 Subject: [PATCH] cleanup --- README.md | 14 +++ cpdctrl/cpdctrl-interactive.py | 137 +++++++++++++++++++---------- cpdctrl/led_control_device/base.py | 1 - cpdctrl/measurement.py | 4 +- cpdctrl/utility/data.py | 67 ++++++++------ pyproject.toml | 4 +- 6 files changed, 150 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index e5495f2..29b65d2 100644 --- a/README.md +++ b/README.md @@ -1 +1,15 @@ # CPDCTRL +A interactive command-line utility for measuring CPD (contact potential difference). + +To run it, launch **Powershell**, activate the python virtual environment and then run the script with `ipython` +```ps1 +cd cpdctrl +.\venv\Scripts\Activate.ps1 +ipython -i .\cpdctrl\cpdctrl\cpdctrl-interactive.py +``` + +## Devices +Currently requires +- *Keithley 2700 SMU* for measuring the voltage (CPD) +- *Arduino Nano* connected to a *Thorlabs LEDD1B* for controlling the light source (LED) + diff --git a/cpdctrl/cpdctrl-interactive.py b/cpdctrl/cpdctrl-interactive.py index e5d70aa..acf2b0e 100644 --- a/cpdctrl/cpdctrl-interactive.py +++ b/cpdctrl/cpdctrl-interactive.py @@ -52,9 +52,7 @@ from .led_script import LedScript from .measurement import measure as _measure from .utility.data import DataCollector - -from .utility import data as _data -from .utility.data import load_dataframe, plot_cpd_data +from .utility.data import plot_cpd_data as data_plot from .utility import file_io from .update_funcs import _Monitor, _update_print @@ -66,9 +64,11 @@ _runtime_vars = { settings = { "datadir": path.expanduser("~/data"), - "name": "measurement", - "interval": 0.02, - "beep": True, + "name": "interactive-test", + "led": "unkown", + "interval": 0.5, + "flush_after": 3000, + "use_buffer": False, } test = False @@ -76,33 +76,67 @@ test = False # global variable for the instrument/client returned by pyvisa/bleak dev: VoltageMeasurementDevice|None = None led: LedControlDevice|None = None -data = DataCollector(data_path=settings["datadir"], data_name="interactive", dirname="interactive_test", dir_exists_is_ok=True) +data_collector = DataCollector(data_path=settings["datadir"], data_name="interactive", dirname="interactive_test", dir_exists_is_ok=True) t0 = 0 +data = None +md = None -def monitor(script: str|int=0, interval=None, flush_after=None, use_buffer=False, max_measurements=None, max_points_shown=None): +def monitor(script: str|int=0, interval: float|None=None, metadata:dict={}, flush_after: int|None=None, use_buffer: bool|None=None, max_measurements=None, max_points_shown=None): """ Monitor the voltage with matplotlib. - - @details: - - Resets the buffers - - Opens a matplotlib window and takes measurements depending on settings["interval"] - - Waits for the user to press a key - Uses python's time.sleep() for waiting the interval, which is not very precise. Use measure_count for better precision. - You can take the data from the buffer afterwards, using save_csv. - @param max_points_shown : how many points should be shown at once. None means infinite - @param max_measurements : maximum number of measurements. None means infinite + - Opens a matplotlib window and takes measurements depending on settings["interval"] + - Waits for the user to press a key + + If use_buffer=False, uses python's time.sleep() for waiting the interval, which is not very precise. + With use_buffer=True, the timing of the voltage data readings will be very precise, however, + the led updates may deviate up to . + + The data is automatically saved to "_