""" run this before using this library: ipython -i prctrl_interactive.py """ version = "0.1" import numpy as np import matplotlib.pyplot as plt from datetime import datetime as dtime from os import path, makedirs import threading as mt import multiprocessing as mp import argparse if __name__ == "__main__": import sys if __package__ is None: # make relative imports work as described here: https://peps.python.org/pep-0366/#proposed-change __package__ = "prsctrl" from os import path filepath = path.realpath(path.abspath(__file__)) sys.path.insert(0, path.dirname(path.dirname(filepath))) # import device modules from .devices import shutter as mod_shutter from .devices import lock_in as mod_lock_in from .devices import lamp as mod_lamp from .devices import monochromator as mod_monochromator # import base classes from .devices.lock_in import Lock_In_Amp from .devices.shutter import Shutter from .devices.lamp import Lamp from .devices.monochromator import Monochromator # from .measurement import measure as _measure from .utility.data_collector import PrsDataCollector from .utility.config_file import ConfigFile from .utility.device_select import select_device_interactive, connect_device_from_config_or_interactive from .update_funcs import Monitor import logging log = logging.getLogger(__name__) # CONFIGURATION _runtime_vars = { "last-measurement": "" } # defaults, these may be overridden by a config file settings = { "datadir": path.expanduser("~/Desktop/PR/data"), "name": "interactive-test", "flush_after": 3000, "use_buffer": False, } cfilename: str = "photoreflectance.yaml" config_path: str = "" config_file: ConfigFile = ConfigFile("") test = False # DEVICES # global variable for the instrument/client returned by pyvisa/bleak lockin: Lock_In_Amp|None = None shutter: Shutter|None = None lamp: Lamp|None = None mcm: Monochromator|None = None data_collector = PrsDataCollector(data_path=settings["datadir"], data_name="interactive", dirname="interactive_test", add_number_if_dir_exists=True) t0 = 0 data = None md = None from .test_measurement import _measure_both_sim def measure_both_sim(**kwargs): return _measure_both_sim(mcm, lockin, shutter, **kwargs) 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, stop_on_script_end: bool=False, max_points_shown=None): """ Monitor the voltage with matplotlib. - 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 "_