Python包装了dewesoftdwdatareaderlib共享库中的函数
dwdat2p的Python项目详细描述
一家生产数据采集硬件的公司DEWESoft也提供 用于处理由 硬件。文件采用其专有格式,如.d7d、.d7z 或.dxd。使用类似于 Python首先需要将它们转换为可移植格式,例如 作为文本。为了避开这一额外的步骤,DEWESoft提供了一个共享的 名为DWDataReaderLib的库。在
dwdat2py是一个python包,其中包含围绕所提供函数的包装器 在DWDataReaderLib中。在
安装
使用pip
pip install dwdat2py
从源安装
用git clone https://github.com/tomnor/dwdat2py.git,cd克隆repo 进入dwdat2py目录(包含setup.py文件的目录)并说
^{pr2}$或者做
pip install .
获取库文件并准备使用
库文件由DEWESoft作为非自由二进制blob提供 而且它们没有安装dwdat2py。这个 图书馆礼包可在 https://download.dewesoft.com/list/developers你必须 注册一个帐户来获得它。登录后,找到一个按钮 “Dewesoft数据阅读器库”,允许下载zip文件 (DWDataReader.zip)和图书馆在一起。在
打开该归档文件并将系统的库文件放入 目录的选择,可能在你工作的机器上。有 只需要一个文件,例如DWDataReaderLib64.so或 DWDataReaderLib64.dll。有很多重复的树 档案如下:
DWDataReader_v4_2_0_11 ├── DWDataReaderv.doc ├── DWDataReaderv.doc.txt ├── EULA-DWDataReader.pdf ├── Linux32&64 C │ ├── DWDataReaderExample.c │ ├── DWDataReaderLib64.so │ ├── DWDataReaderLib.so │ ├── DWLoadLib.c │ ├── DWLoadLib.h │ └── Red Hat 5 ├── Win32&64 C │ ├── DReader_c_win.exe │ ├── DReader_c_win.vcxproj │ ├── DWDataReaderExample.c │ ├── DWDataReaderLib64.dll │ ├── DWDataReaderLib.dll │ ├── DWLoadLib.c │ └── DWLoadLib.h ...
后面是一些其他语言的示例目录。然而, 所有的DWDataReaderLib64.dll文件似乎都是副本,所以 如果在Windows上,请选择其中一个,否则选择一个.so文件。在
有三种方法可以告诉dwdat2py库的位置:
- 将环境变量DEWELIBDIR设置到 库文件被放入。在
- 将名为dewelibdir的配置文件与 扩展名.txt或.pth。在其中输入一条指向 库目录。空行或以#开头的行是 忽略。将其放入~/.config(Gnu/Linux)或~on 窗户。无论如何,os.path.expanduser操作系统()用于计算 ~的位置。在
- 或者最后通过设置dwdat2py.DEWELIBDIR指向 目录(在导入dwdat2py.wrappers之前)
有一个名为dwdatareader的“竞争”包提供 库文件及其分发,因此也可以获取库 或者也可以尝试这个包[1]。在
使用
fromdwdat2pyimportwrappersasdwdw.init()dw.open_data_file('dat1')# ... other functions to get at data in dat1 ...dw.close_data_file()dw.open_data_file('dat2')# ... other functions to get at data in dat2 ...dw.close_data_file()# work is done for nowdw.de_init()# optionally init() again for a new session.
调用init()和de_init()必须先调用后调用 分别。请确保之前成功调用了open_data_file(...)close_data_file(...),否则不要调用close_data_文件。在
目前,本软件包的最高级别功能是:
defchannel_reduced(channel,reduction,encoding=None):"""Return a flat list of data for channel reduced to reduction. Parameters ---------- channel : int or str Either the channel index or the channel name. reduction : int One of the following time_stamp = 0 ave = 1 min = 2 max = 3 rms = 4 encoding : str encoding to pass to `get_channel_list()`, which see. Wraps: Nothing explicit. This is a support function to simplify getting reduced data from a channel. """
如果你碰巧知道频道的索引或名称,这个函数 应该足够一个通道一个通道地获取数据。否则你需要 首先调用一些helper函数来准备这个调用。在
可以选择将对包装器模块的访问作为上下文管理器提供:
@contextmanagerdefwrappersimport(fn,fsencoding=None):"""Provide context access to the wrappers module. Return a handle to the wrappers module in a context manager and file `fn` (str) opened for operations (a .dxd file for example). Initialization and deinitialization is provided by this context manager, as well as opening and closing the file. The file information resulting from opening the file is available as a module level variable `fileinfo`, (`handle.fileinfo`). The function that `wrappers.open_data_file` wraps require bytes as file name. `fsencoding` is used in the call to `wrappers.open_data_file` but is hopefully not necessary to specify since os.fsencode() is used by default. Example usage: >>> import dwdat2py >>> with dwdat2py.wrappersimport(fn) as wi: ... print(wi.fileinfo) ... chlist = wi.get_channel_list(encoding='latin1') ... for chinfo in chlist: ... # print the average values from each channel (1) ... print(wi.channel_reduced(chinfo.index, 1, encoding='latin1')) ... # get the "time stamps" (0) ... time = wi.channel_reduced(chlist[0].index, 0, encoding='latin1') As with importing the wrappers module in the standard way, this will fail if the shared library is not found. """
贡献
请报告错误并向作者发送建议或补丁。或者 在Github的回购主页上发出问题或拉取请求
[1] | dwdatareader solves the same problem but with higher level of abstraction to the library functions. |
- 项目
标签: