Record arbitrary sensors periodically in an asynchronous manner. Control their properties in real time from CLI. Graph/view tools to visualize live data/images are also provided.
Project description
About
Periodic REcording and Visualization of (sensor) Objects
This 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 (seeexamples/Record.ipynb
for examples) -
prevo.control
: control device properties, create pre-defined temporal evolutions of settings for sensors, devices and recording properties (seeexamples/Control.ipynb
for examples) -
prevo.plot
: plot numerical data in real time (regular plots, oscilloscope-like graphs, seeexamples/LiveGraph.ipynb
for examples) -
prevo.viewers
: live view of images from camera-like sensors (seeexamples/Viewers.ipynb
for examples) -
prevo.csv
: read / save data with CSV/TSV files -
prevo.parser
: parse command line arguments to trigger functions or class methods -
prevo.measurements
: additional tools to format measurements forRecord
-like classes. -
prevo.misc
: miscellaneous tools, including dummy sensors and devices.
See Jupyter notebooks in examples/
and docstrings for more help. Below is also an example showing the workflow for defining objects for periodic recording.
Install
pip install prevo
Record sensors periodically
For using the package for asynchronous recording of data, three base classes must/can be subclassed:
SensorBase
(requires subclassing)RecordingBase
(requires subclassing)RecordBase
(can be used as is or be subclassed)
A minimal example is provided below, to record pressure and temperature asynchronously, assuming the user already has classes (Temp
, Gauge
) to take single-point measurements (it could be functions as well). See examples/Record.ipynb
for an actual working example. Let's assume that the pressure measurement also has an averaging
parameter to smooth the data.
-
Define the sensors
from prevo.record import SensorBase, ControlledProperty class TemperatureSensor(SensorBase): name = 'T' def _read(self): """This method must have no arguments""" return Temp.read() class PressureSensor(SensorBase): name = 'P' def __init__(self): self.avg = 10 # default value def _read(self): return Gauge.read(averaging=self.avg)
-
Define the individual recordings
Note: subclassing can help significantly reduce the code below.
from prevo.record import RecordingBase class RecordingT(RecordingBase): """Recording temperature data periodically""" def __init__(self): super().__init__(Sensor=TemperatureSensor, dt=10) # by default, record every 10 sec self.file = 'Temperature.txt' def init_file(self, file): """Define if you want to write column titles etc. (assuming the file is already open) """ pass def format_measurement(self, data): """Define here how to format data from Sensor._read(). (e.g., add time information, etc.). Returns a 'measurement'.""" pass def save(self, measurement, file): """Define here how to save the measurement above into self.file. (assuming the file is already open) """ pass # For the pressure recording, one might want to also control the averaging # of the data in real time. In this case, a ControlledProperty object needs # to be defined with the attribute of the recording to be controlled, # a readable representation of the property, and shorctut commands to # interact with the property in the CLI averaging = ControlledProperty(attribute='sensor.avg', readable='Averaging', commands=('avg',)) class RecordingP(RecordingBase): """Recording pressure data periodically""" def __init__(self): """By default, the time interval and the active status (on/off) of the recording are controlled. Here we can also add control of the averaging in real time""" super().__init__(Sensor=PressureSensor, ctrl_ppties=(averaging,), dt=1) # by default, record every second self.file = 'Pressure.txt' def init_file(self, file): """same as above""" pass def format_measurement(self, data): """same as above""" pass def save(self): """same as above""" pass
-
Define and start asynchronous recording
from prevo.record import RecordBase class Record(RecordBase): """Options exist to add metadata saving or graphing""" pass # Keys must correspond to sensor names recordings = {'T': RecordingT(), 'P': RecordingP()} # Start recording. A CLI will appear; type '?' for help Record(recordings=recordings, properties=properties).start()
Note: context managers also possible (i.e. define __enter__
and __exit__
in Sensor
class) e.g. if sensors have to be opened once at the beginning and closed in the end; this is managed automatically by RecordBase
if a context manager is defined.
See docstrings for more help and Record.ipynb
for examples.
Misc. info
Module requirements
Packages outside of standard library
(installed automatically by pip if necessary)
- tqdm
- tzlocal < 3.0
- oclock >= 1.2.2 (timing tools)
- clivo >= 0.4.0 (command line interface)
- matplotlib >= 3.1 (due to
cache_frame_data
option inFuncAnimation
) - numpy
Optional packages
- pandas (optional, for csv loading methods)
- opencv-python (optional, for specific camera viewers)
Python requirements
Python : >= 3.6
Author
Olivier Vincent
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file prevo-0.13.1.tar.gz
.
File metadata
- Download URL: prevo-0.13.1.tar.gz
- Upload date:
- Size: 463.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9630b570d8ca0c48e7d0f7e88589bbafd7472da7f208139609816ac78c05ab7b |
|
MD5 | 5c5c9f0e6c6365e9b2843a462fb38f0d |
|
BLAKE2b-256 | 683d6cd6abca46c193eba309fc82eaadc4d1f9c645460fe6ac5bec3db7ce0c5c |
File details
Details for the file prevo-0.13.1-py3-none-any.whl
.
File metadata
- Download URL: prevo-0.13.1-py3-none-any.whl
- Upload date:
- Size: 63.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59586685eacb1ed3f2a3c209f7d57d5bf221402c327b5fd502354dfde9404e58 |
|
MD5 | cb73b8038a9f79ea9310d5d83cafb099 |
|
BLAKE2b-256 | 5e46b00cc2838b26d7d2ccdef70949c0ea3be255899985cf15f937e50aa27426 |