Asammdf初次接触
Asammdf 官方地址
asammdf是ASAM(自动化和测量系统的标准化协会)MDF(测量数据格式)文件的快速解析器/编辑器。
asammdf支持MDF版本2(.dat),3(.mdf)和4(.mf4)。
asammdf可在Python> = 3.6上运行(对于Python 2.7、3.4和3.5,请参见4.xy版本)
注: 学习这个是因为工作需要, 主要用于数据提取和可视化展示, 使用起来相当的方便.
构件环境
首先需要确定你所使用的PYTHON 环境符合你的要求,
当前asammdf要求python版本不低于3.6, 如果版本过低请注意更换版本
使用pip 安装asammdf包
pip install asammdf
也可以使用gui进行安装
pip install asammdf[gui]
或者使用anaconda进行安装
conda install -c conda-forge asammdf
初次使用
from asammdf import MDF m = MDF('001.MF4')
打开一个MF4文件
基础代码示例
from asammdf import MDF, Signal >>> import numpy as np >>> t = np.arange(5) >>> s = np.ones(5) >>> mdf = MDF(version='4.10') >>> for i in range(4): ... sigs = [Signal(s*(i*10+j), t, name='Sig') for j in range(1, 4)] ... mdf.append(sigs) ... >>> # first group and channel index of the specified channel name ... >>> mdf.get('Sig') UserWarning: Multiple occurances for channel "Sig". Using first occurance from data group 4. Provide both "group" and "index" arguments to select another data group <Signal Sig: samples=[ 1. 1. 1. 1. 1.] timestamps=[0 1 2 3 4] unit="" info=None comment=""> >>> # first channel index in the specified group ... >>> mdf.get('Sig', 1) <Signal Sig: samples=[ 11. 11. 11. 11. 11.] timestamps=[0 1 2 3 4] unit="" info=None comment=""> >>> # channel named Sig from group 1 channel index 2 ... >>> mdf.get('Sig', 1, 2) <Signal Sig: samples=[ 12. 12. 12. 12. 12.] timestamps=[0 1 2 3 4] unit="" info=None comment=""> >>> # channel index 1 or group 2 ... >>> mdf.get(None, 2, 1) <Signal Sig: samples=[ 21. 21. 21. 21. 21.] timestamps=[0 1 2 3 4] unit="" info=None comment=""> >>> mdf.get(group=2, index=1) <Signal Sig: samples=[ 21. 21. 21. 21. 21.] timestamps=[0 1 2 3 4] unit="" info=None comment=""> >>> # validation using source name ... >>> mdf.get('Sig', source='VN7060') <Signal Sig: samples=[ 12. 12. 12. 12. 12.] timestamps=[0 1 2 3 4] unit="" info=None comment="">