用于读取和创建riscure检查器跟踪集文件(.trs)的库

trsfile的Python项目详细描述


python中的inspector跟踪集.trs文件支持

Build StatusDocumentation Status

riscure检查器使用.trs文件格式保存和读取磁盘上的跟踪。为了更好地帮助从第三方读取和写入跟踪集文件,riscure发布了这个python库。

快速启动

该库支持读取和写入^ {CD1>}文件,但它不支持(^ {EM1}$/EME>)支持修改现有的{{CD1>}文件。TraceSetTrace类都模拟了list的所有功能,所以切分您的心意吧!

安装

此库在PyPi上可用于python 3及更高版本。只需将trsfile添加到requirements.txt或通过命令行安装即可:

pip install trsfile

正在读取.trs文件

importtrsfilewithtrsfile.open('trace-set.trs','r')astraces:# Show all headersforheader,valueintrs_file.get_headers().items():print(header,'=',value)print()# Iterate over the first 25 tracesfori,traceinenumerate(trs_file[0:25]):print('Trace {0:d} contains {1:d} samples'.format(i,len(trace)))print('  - minimum value in trace: {0:f}'.format(min(trace)))print('  - maximum value in trace: {0:f}'.format(max(trace)))

创建.trs文件

importrandom,os,trsfilefromtrsfileimporttrs_open,Trace,SampleCoding,TracePadding,Headerwithtrs_open('trace-set.trs',# File name of the trace set'w',# Mode: r, w, x, a (default to x)# Zero or more options can be passed (supported options depend on the storage engine)engine='TrsEngine',# Optional: how the trace set is stored (defaults to TrsEngine)headers={# Optional: headers (see Header class)Header.LABEL_X:'Testing X',Header.LABEL_Y:'Testing Y',Header.DESCRIPTION:'Testing trace creation',},padding_mode=TracePadding.AUTO,# Optional: padding mode (defaults to TracePadding.AUTO)live_update=True# Optional: updates the TRS file for live preview (small performance hit)#   0 (False): Disabled (default)#   1 (True) : TRS file updated after every trace#   N        : TRS file is updated after N traces)astrs_file:# Extend the trace file with 100 traces with each 1000 samplestrs_file.extend([Trace(SampleCoding.FLOAT,[random.uniform(-255,255)for_inrange(0,1000)],data=os.urandom(16))for_inrange(0,100)])# Replace 5 traces (the slice [0:10:2]) with random length traces.# Because we are creating using the TracePadding.PAD mode, all traces# will be clipped or padded on the first trace lengthtrs_file[0:10:2]=[Trace(SampleCoding.FLOAT,[random.uniform(0,255)for_inrange(0,random.randrange(1000))],data=os.urandom(16),title='Clipped trace')for_inrange(0,5)]# Adding one Tracetrs_file.append(Trace(SampleCoding.FLOAT,[random.uniform(-255,255)for_inrange(0,1000)],data=os.urandom(16)))# We cannot delete traces with the TrsEngine, other engines do support this feature#del trs_file[40:50]# We can only change headers with a value that has the same length as the previous value# with the TrsEngine, other engines can support dynamically adding, deleting or changing# headers.#trs_file.update_header(Header.LABEL_X, 'Time')#trs_file.update_header(Header.LABEL_Y, 'Voltage')#trs_file.update_header(Header.DESCRIPTION, 'Traces created for some purpose!')print('Total length of new trace set: {0:d}'.format(len(trs_file)))

TraceSet从一种类型转换为另一种类型

importrandom,os,trsfilewith \
	trsfile.open('trace-set',# Previously create trace set'r',# Read only modeengine='FileEngine'# Using the FileEngine)astraces, \
	trsfile.open(# Note: TrsEngine is the default'trace-set.trs',# Name of the new trace set'w',# Write modeheaders=traces.get_headers()# Copy the headers)asnew_traces:new_traces.extend(traces)# Extend the new trace set with the# traces from the old trace set

文档

完整文档位于docs文件夹中,在Read the Docs上有可读版本。

测试

库支持pythonunittest模块,可以使用以下命令执行测试:

python -m unittest

许可证

BSD 3-Clause Clear License

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将resultset转换为json的最佳方式是什么   smb需要从具有用户名和密码但引发SMBApiException的java连接碎片驱动器   没有线程,java死锁实现无法工作。睡觉   java Tomcat内存中会话复制   从java文本窗格保存字体   java启动Windows 10 Paint3D以打开特定的图像文件   Eclipse Java,将文本从ISO88591转换为UTF8   java加载jar中包含的资源   java xpath在selenium中不可识别,但在XPather中可识别   java如何将Springbean从多个配置文件的自动关联候选中排除?   java在某个范围内的XOR最大值?   java Android JNI/C++:如何正确添加带有。h和。cpp文件?   java使用关键字this和类中的多个构造函数   C++如何将一个被重复调用的外部进程集成到java WebApp中?