Skip to main content

以异步方式定期记录任意传感器。从 CLI 实时控制它们的属性。还提供了可视化实时数据/图像的图形/视图工具。

项目描述

关于

(传感器)对象的定期RE记录和可视

这个包提供了类来快速创建各种应用程序的交互式数据记录(例如温度记录、相机延时等)。

传感器以异步方式读取,并且可以具有不同的数据读取时间间隔(或者是连续的,即尽可能快)。通过定义一个读取所有传感器的超级传感器对象(并且它本身定期探测),同步记录也是可能的(尽管不是这个包的主要目标)。

还提供了用于在记录期间对数据进行图形可视化的工具(更新的数字图表、类似示波器的图表、相机的图像查看器等)

该软件包包含各种模块:

  • prevo.record:定期记录传感器、CLI 界面、从 CLI 触发 GUI 工具(参见examples/Record.ipynb示例)
  • prevo.plot:实时绘制数值数据(常规绘图,类似示波器的图表,参见examples/LiveGraph.ipynb示例)
  • prevo.viewers:来自类似相机的传感器的实时图像(参见examples/Viewers.ipynb示例)
  • prevo.csv: 使用 CSV/TSV 文件读取/保存数据
  • prevo.parser: 解析命令行参数以触发函数或类方法
  • prevo.measurements:用于格式化Record类测量的附加工具。

examples/有关更多帮助,请参阅 Jupyter 笔记本和文档字符串。下面也是一个示例,显示了为定期记录定义对象的工作流程。

安装

pip install prevo

定期记录传感器

为了使用包进行数据的异步记录,三个基类必须/可以子类化:

  • SensorBase(需要子类化)
  • RecordingBase(需要子类化)
  • RecordBase(可以按原样使用或被子类化)

下面提供了一个最小示例,用于异步记录压力和温度,假设用户已经有类 ( Temp, Gauge) 来进行单点测量(它也可以是函数)。请参阅examples/Record.ipynb实际工作示例。让我们假设压力测量也有一个averaging参数来平滑数据。

  1. 定义传感器

    from prevo.record import SensorBase
    
    
    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)
    
  2. 定义单个记录

    注意:子类化可以帮助显着减少下面的代码。

    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'
            # Below, this allows the user to change time interval in real time
            self.controlled_properties = 'timer.interval',
    
        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
    
    
    class RecordingP(RecordingBase):
        """Recording pressure data periodically"""
    
        def __init__(self):
    
            super().__init__(Sensor=PressureSensor,
                             dt=1)  # by default, record every second
            self.file = 'Pressure.txt'
            # Here we can also control the averaging in real time
            self.controlled_properties = 'timer.interval', 'sensor.avg'
    
        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
    
  3. 定义并开始异步录制

    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()}
    
    # All properties that can be controlled by CLI
    # (keys must correspond to some controlled_properties)
    properties = {'timer.interval': {'repr': 'Δt (s)',
                                     'commands': ('dt',),
                                     },
                  'sensor.avg': {'repr': 'Averaging',
                                 'commands': ('avg',),
                                 }
                  }
    
    # Start recording. A CLI will appear; type '?' for help
    Record(recordings=recordings, properties=properties).start()
    

注意:上下文管理器也是可能的(即定义__enter____exit__Sensor类中),例如,如果传感器必须在开始时打开一次并在结束时关闭;RecordBase如果定义了上下文管理器,则会自动管理它。

请参阅文档字符串以获得更多帮助。

杂项。信息

模块要求

标准库之外的包

(必要时由 pip 自动安装)

  • tqdm
  • tzlocal < 3.0
  • oclock >= 1.2.2(计时工具)
  • clivo >= 0.3.0(命令行界面)
  • matplotlib >= 3.1(由于 中的cache_frame_data选项FuncAnimation
  • 麻木的

可选包

  • pandas(可选,用于 csv 加载方法)
  • opencv-python(可选,用于特定的摄像机查看器)

Python 要求

蟒蛇:> = 3.6

作者

奥利维尔文森特

( ovinc.py@gmail.com )

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

prevo-0.11.1.tar.gz (380.7 kB 查看哈希

已上传 source

内置分布

prevo-0.11.1-py3-none-any.whl (56.8 kB 查看哈希

已上传 py3