Package: prevo
AboutPeriodicREcording andVisualization of (sensor)ObjectsThis package provides classes to rapidly create interactive data recording for various applications (e.g. recording of temperature, time-lapses with cameras etc.).Sensors are read in an asynchronous fashion and can have different time intervals for data reading (or be continuous, i.e. as fast as possible). Synchronous recording is also possible (although not the main goal of this package) by defining a super-sensor object that reads all sensors (and which is itself probed at regular intervals).Tools for graphical visualizations of data during recording are also provided (updated numerical graphs, oscilloscope-like graphs, image viewers for cameras etc.)The package contains various modules:prevo.record: record sensors periodically, CLI interface, trigger GUI tools from CLI,prevo.control: control device properties, create pre-defined temporal evolutions of settings for sensors, devices and recording properties,prevo.plot: plot numerical data in real time (regular plots, oscilloscope-like graphs etc.),prevo.viewers: live view of images from camera-like sensors,prevo.csv: read / save data with CSV/TSV filesprevo.parser: parse command line arguments to trigger functions or class methodsprevo.measurements: additional tools to format measurements forRecord-like classes.prevo.misc: miscellaneous tools, including dummy sensors and devices.See Jupyter notebooks inexamples/and docstrings for more help.Below are also minimal examples showing implementation of periodic recording and image viewers.InstallpipinstallprevoRecord sensors periodicallyFor using the package for asynchronous recording of data, three base classes must/can be subclassed:SensorBaseRecordingBase(children:NumericalRecording,ImageRecording)Record(children:NumericalRecord,ImageRecord)A minimal example is provided below, to record pressure and temperature asynchronously into a CSV file, assuming the user already has classes (Temp,Gauge) to take single-point measurements (it could be functions as well). Seeexamples/Record.ipynbfor more detailed examples, including periodic recording of images from several cameras.Define the sensorsfromprevo.recordimportSensorBaseclassTemperatureSensor(SensorBase):name='T'def_get_data(self):returnTemp.read()classPressureSensor(SensorBase):name='P'def_get_data(self):returnGauge.read()Note: context managers also possible (i.e. define__enter__and__exit__inSensorclass) e.g. if sensors have to be opened once at the beginning and closed in the end.Define the individual recordingsfromprevo.record.numericalimportNumericalRecording# Because timestamp and time uncertaintyare added automatically in data# Can be renamed to have different time column titles in csv file.time_columns=('time (unix)','dt (s)')# Note: NumericalRecording can also be subclassed for simpler use# (see examples/Record.ipynb Jupyter notebook)recording_P=NumericalRecording(Sensor=PressureSensor,filename='Pressure.csv',column_names=time_columns+('P (mbar)',),)recording_T=NumericalRecording(Sensor=TemperatureSensor,filename='Temperature.csv',column_names=time_columns+('T (°C)',),)NOTE: the recordings are already usable as is if one does not need fancy functionality.
For example, one can start a periodic recording of pressure every two seconds withrecording.start(dt=2)And the following methods and attributes are available:# can be set to True or False to pause/resume recordingrecording.active# can be set to True or False to pause/resume saving to file# (e.g. to continue live view of data without saving)recording.saving# Equivalent to playing with .active:recording.pause()recording.resume()recording_P.stop()# After a stop(), it is possible to call start() again.# To change the time interval between data:recording.timer.interval=...# To record data as fast as possible:recording.continuous=TrueNOTE:recording.start()is non-blocking, so several independent recordings can be started at the same time, and can be changed in real time with the methods/attribute above. However, a convenient interface to manage several recordings simultaneously is provided by theRecordclass, see below.Recordinterface for managing simultaneous recordingsRecordprovides a real-time CLI to manage recordings properties in real time as well as live data visualization.fromprevo.record.numericalimportNumericalRecordrecordings=recording_P,recording_Trecord=NumericalRecord(recordings)record.start(dt=2)# time interval of 2 seconds for both sensorsMany other options and customizations exist See docstrings for more help andexamples/Record.ipynbfor examples.Live image viewerLet's assume one gets image data in a queue from a camera.
Individual elements from thecamera.queueare dictionaries with keysimage(numpy-like image array) andnum(image number, an integer). This formatting of elements in the queue is assumed by default, but others are possible (seeexamples/Viewers.ipynb).It is possible to view the images using eithertkinter,opencvormatplotlib. Here we will use tkinter.
One first has to define awindowin which to display the images, and then aviewerto operate and update the window.fromprevo.viewersimportTkWindow,TkViewer# The window will show the (display) fps and the image number in real timewindow=TkWindow(camera.queue,show_fps=True,show_num=True)# It is possible to run several windows in parallel from other image sources# Here we have just one.viewer=TkViewer(windows=(window,))viewer.start()Here again, various options and customizations are possible, see some example inexamples/Viewers.ipynb.Misc. infoModule requirementsPackages outside of standard library(installed automatically by pip if necessary)tqdmtzlocal < 3.0oclock >= 1.3.2 (timing tools)clivo >= 0.4.0 (command line interface)gittools >= 0.6.0 (metadata saving tools)matplotlib >= 3.1 (due tocache_frame_dataoption inFuncAnimation)numpyOptional packagespandas (optional, for csv loading methods)opencv-python (optional, for specific camera viewers)Python requirementsPython : >= 3.6AuthorOlivier Vincent(ovinc.py@gmail.com)