简体   繁体   English

我如何告诉python我的数据结构(二进制)是什么样子,以便我可以绘制它?

[英]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方法,它将执行以下操作:

  • Read a chunk of binary data 读取二进制数据块
  • Figure out if it has a valid header 找出它是否具有有效的标题
  • Check the message type - if it's a FORMAT message parse that. 检查消息类型-如果它是FORMAT消息,则对此进行解析。 If it's a description message, parse that. 如果是描述消息,请对其进行解析。
  • Dump out a CSV row 转储CSV行

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.

相关问题 如何使用matplotlib为我的图形制作动画,以便看起来数据点在移动? - How can I animate my graph with matplotlib so that it looks like the data points are moving? 我有一个值数组,如何使用 matplotlib 的 plot 值使其看起来像 25 秒的视频 - I have an array of values, how can I plot values using matplotlib so that it looks like a video of 25 seconds 如何在 R 中创建一个看起来像附件图像的图? - How can I create a plot in R that looks like the attached image? 如何判断函数在Python中返回的值? - How can I tell what value my function is returning in Python? 如何判断python变量中包含哪种类型的数据? - How do I tell what type of data is inside python variable? 我想用“%”号显示我的EXCEL数据。 我如何使用python做到这一点 - I want to display my EXCEL data with “%” sign. How can i do so by using python 我如何用大量文件构建我的 Python 子模块,以便我只需要导入一个模块 - How do i structure my Python submodule with a lot of files, so that i have to import only one module 如何在Python中使用matplotlib绘制我的数据? - How do I plot my data using matplotlib in Python? 我应该如何构建我的 Python 模块,以便将来可以随时运行旧版本? - How should I structure my Python module so that I can run older versions at any time in the future? 如何判断Python中的结构是否有顺序? - How can I tell if a structure in Python has order?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM