[英]How do I tell python what my data structure (that is in binary) looks like so I can plot it?
I have a data set that looks like this. 我有一个看起来像这样的数据集。
b'\xa3\x95\x80\x80YFMT\x00BBnNZ\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Type,Length,Name,Format,Columns\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa3\x95\x80\x81\x17PARMNf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00Name,Value\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa3\x95\x80\x82-GPS\x00BIHBcLLeeEefI\x00\x00\x00Status,TimeMS,Week,NSats,HDop,Lat,Lng,RelAlt,Alt,Spd,GCrs,VZ,T\x00\x00\xa3\x95\x80\x83\x1fIMU\x00Iffffff\x00\x00\x00\x00\x00\x00\x00\x00\x00TimeMS,GyrX,GyrY,G
I have been reading around to try and find how do I implement a code into python that will allow me to parse this data so that I can plot some of the column against each other (Mostly time). 我一直在阅读以尝试找到如何在python中实现代码,这将使我能够解析此数据,以便可以相互绘制某些列(通常是时间)。
Some things I found that may help in doing this: 我发现一些有助于这样做的事情:
There is a code that will allow me to convert this data into a CSV file. 有一段代码可以让我将这些数据转换为CSV文件。 I know how to use the code and convert it to a CSV file and plot from there, but for a learning experience I want to be able to do this without converting it to a CSV file. 我知道如何使用代码并将其转换为CSV文件并从那里绘图,但是为了获得学习经验,我希望能够做到这一点而无需将其转换为CSV文件。 Now I tried reading that code but I am clueless since I am very new to python. 现在,我尝试阅读该代码,但由于对Python非常陌生,所以我一无所知。 Here is the link to the code: 这是代码的链接:
https://github.com/PX4/Firmware/blob/master/Tools/sdlog2/sdlog2_dump.py
Also, Someone posted this saying this might be the log format, but again I couldn't understand or run any code on that page. 另外,有人发布这句话说这可能是日志格式,但是我又无法理解或运行该页面上的任何代码。
http://dev.px4.io/advanced-ulog-file-format.html
A good starting point for parsing binary data is the struct module https://docs.python.org/3/library/struct.html and it's unpack
function. 解析二进制数据的一个很好的起点是struct模块https://docs.python.org/3/library/struct.html ,它是unpack
功能。 That's what the CSV dump routine you linked to is doing as well. 您链接到的CSV转储例程也正在执行此操作。 If you walk through the process
method, it's doing the following: 如果您逐步了解该process
方法,它将执行以下操作:
You could modify this code to essentially replace the __printCSVRow
method with something that captures the data into a pandas dataframe (or other handy data structure) so that when the main routine is all done you can grab all the data from the dataframe and plot it. 您可以修改此代码,以将__printCSVRow
方法从本质上替换为将数据捕获到pandas数据框(或其他方便的数据结构)中的方法,以便在完成主例程后,您可以从数据框中获取所有数据并进行绘制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.