Skip to main content

MCAP file reader for JSON data implemented in C++ and Python.

Project description

Read DataBeam MCAP files with ease.

This Python library provides a high performance parser - implemented in C++ - for MCAP files produced by the DataBeam DAQ software: https://github.com/virtual-vehicle/databeam.

databeam_mcap_reader only works for reading MCAP files with JSON-encoded data containing a mandatory schema.

Unfinalized or damaged MCAP files will get automatically repaired by the MCAP-CLI tool.

See official MCAP documentation for more information.

Usage of Reader

Get a reader instance:

import databeam_mcap_reader as mr
reader = mr.McapReader()

Open a file:

reader.open('path/to/file.mcap')

Fetch details about the file:

# print infos
print(reader.get_info_string())

# dict of topics with field names, data-types and message counts
structure = reader.get_structure()

# list of topic names
topics = reader.get_topic_names()

# total number of messages
count = reader.get_total_message_count()

# start and end time in nanoseconds
start_time_ns = reader.time_start_ns
end_time_ns = reader.time_end_ns

Fetch data from a specific topic:

# get a numpy structured array with data from a topic
data = reader.get_data(topic_name)

Fetch all data:

# get a dict of numpy structured arrays with data from all topics
data = reader.get_all_data()

Fetch a specific amount of data with a start time and number of messages:

data = reader.get_data('testtopic', start_time_ns=0, num_messages=1000)
# fetch next block, starting right after the first
data = reader.get_data('testtopic', start_time_ns=data['ts'][-1] + 1, num_messages=1000)

Example for chunked reader:

for chunk in reader.get_data_chunked("testtopic", chunk_size_megabytes=1000):
    print(f'got {chunk.size} messages')
    # --> process data chunk (numpy structured array)!

Use matplotlib to plot data:

import matplotlib.pyplot as plt
for topic_name in reader.get_topic_names():
    data = reader.get_data(topic_name)
    fields = reader.get_structure()[topic_name]['fields']
    dtypes = reader.get_structure()[topic_name]['dtypes']
    channels = []
    for i, field in enumerate(fields):
        if dtypes[i] != 'boolean' and dtypes[i] != 'string' and dtypes[i] != 'array':
            channels.append(field)
    for ch in [ch for ch in channels if ch != 'ts']:
        plt.plot(data['ts'], data[ch], label=ch)

plt.xlabel('Time')
plt.ylabel('Value')
plt.legend()
plt.title('Channels over Time')
plt.show()

Please see reader.py - there are examples at the end of the file.

Usage of Data Collector

TODO

Configure Logging

import logging
import databeam_mcap_reader as mr
logging.getLogger('databeam_mcap').setLevel(logging.DEBUG)  # or other logging level

Build wheel files

Wheel files must be specifically built for all supported Python versions.

Linux / Docker

Make sure Docker is installed and running: https://docs.docker.com/get-docker/

make linux_wheels

This will run a manylinux Docker container and build the wheel files with the specified Python versions (see Makefile).

Windows

Make sure Python is installed in all required versions and py command is available: https://www.python.org/downloads/windows/

Install Visual Studio 2022 with Python and C++ extensions: https://visualstudio.microsoft.com/downloads/

Install Conan natively: https://conan.io/downloads

conan
conan profile detect --force

Open terminal and run:

.\build_wheels_windows.ps1 <python_version> [<python_version> ...]
Example:
 .\build_wheels_windows.ps1 3.10 3.11 3.12 3.13

Development / Testing (Linux)

Build only c++ extension for development

make dev

python3
import build_dev._core as mr
mr.parse_mcap(...)

Test built wheel

make wheel

python3 -m venv venv_test
. ./venv_test/bin/activate
pip install dist/databeam_mcap_readerXXX.whl

python3 -c "import databeam_mcap_reader as mr; import numpy as np; reader = mr.McapReader(); mr.parse_mcap('whee', 't', np.dtype([]), 1)"

OK, if there are no import-errors and it complains, that whee file is missing.

License

Distributed under the MIT license. See LICENSE.txt file for more information.

Contact

Virtual Vehicle Research GmbH: https://www.v2c2.at

Project Lead: Peter Sammer - peter.sammer@v2c2.at

This repository contains only public open-source components: https://github.com/virtual-vehicle/databeam

We gladly offer support, custom installations and extensions for devices, test-benches, experiments and more.

Acknowledgments

Virtual Vehicle Research GmbH has received funding within COMET Competence Centers for Excellent Technologies from the Austrian Federal Ministry for Climate Action, the Austrian Federal Ministry for Labour and Economy, the Province of Styria (Dept. 12) and the Styrian Business Promotion Agency (SFG). The Austrian Research Promotion Agency (FFG) has been authorised for the programme management.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

databeam_mcap_reader-0.4.1-cp313-cp313-win_amd64.whl (7.6 MB view details)

Uploaded CPython 3.13Windows x86-64

databeam_mcap_reader-0.4.1-cp313-cp313-manylinux_2_34_x86_64.whl (8.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

databeam_mcap_reader-0.4.1-cp312-cp312-win_amd64.whl (7.6 MB view details)

Uploaded CPython 3.12Windows x86-64

databeam_mcap_reader-0.4.1-cp312-cp312-manylinux_2_34_x86_64.whl (8.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

databeam_mcap_reader-0.4.1-cp311-cp311-win_amd64.whl (7.6 MB view details)

Uploaded CPython 3.11Windows x86-64

databeam_mcap_reader-0.4.1-cp311-cp311-manylinux_2_34_x86_64.whl (8.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

databeam_mcap_reader-0.4.1-cp310-cp310-win_amd64.whl (7.6 MB view details)

Uploaded CPython 3.10Windows x86-64

databeam_mcap_reader-0.4.1-cp310-cp310-manylinux_2_34_x86_64.whl (8.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

File details

Details for the file databeam_mcap_reader-0.4.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ea17c1b99be97e6d34ef1a02a6a4ead94baebdc68d1f9a04f651238f2c1f424c
MD5 54711e97cb6d18bce7932d656d7e2c92
BLAKE2b-256 9c5641b70c9ad451c97c13a9595a7c43adf2f79103186789f580682f9add46b1

See more details on using hashes here.

File details

Details for the file databeam_mcap_reader-0.4.1-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3d8ee6b409fec916ad7595d3fb8c4577736a0a00e53313cfdb2c25d19cd2e0cc
MD5 e4e465f6fa0f861aee3414350a365a36
BLAKE2b-256 6cec8e0958b9aaaf4305a73a929e31ced3d82641de19a54b7fd52dfbd2e98380

See more details on using hashes here.

File details

Details for the file databeam_mcap_reader-0.4.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 aadcb8ce0c839a4782b7d557fdb261552f209a5fadea52eacf0bbfe049a19949
MD5 fcd2532850e09354ff7eaecc351cd9e2
BLAKE2b-256 5e18bf35414eccfd8bc1e1dc6653d81fbb6672446e4f75786d18ce77461188e6

See more details on using hashes here.

File details

Details for the file databeam_mcap_reader-0.4.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ede2dc77071b2e96a6e3bc97ea901adcc09ed00726a38454854a605985b008b2
MD5 0e4d26fa1b9e079402b484dbe9dfb3eb
BLAKE2b-256 fab9f1fdd54baf43824056d87e766c2eb2f83e708f346e4961be4fd8187a82e7

See more details on using hashes here.

File details

Details for the file databeam_mcap_reader-0.4.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 df7d56abfb857ee30ff5be53263cd3f4a0b53c0963006e39288fe7b5bb7af461
MD5 126735d905773b7040f1adc802362e03
BLAKE2b-256 20e32b7f73e4446c064d9f93c49bd18e269a016f25e33f0512154538d79f654a

See more details on using hashes here.

File details

Details for the file databeam_mcap_reader-0.4.1-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f83c16c672678be37e627ce60e4204f9ff546d6821a041ce3ee7308ea9d303e8
MD5 3f339fdecb61928e329f0240604b9289
BLAKE2b-256 abae0de1d50dd4ff3727937968f4dc09635b0e4c36f8b631cc52885d62682c02

See more details on using hashes here.

File details

Details for the file databeam_mcap_reader-0.4.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bac8cea050c67a017efe4a4113f1a8c748656870a04d3c22a15fc8750f570340
MD5 73b4f302bfadb93eaf60294613f51a93
BLAKE2b-256 7d4d0abffdb31eff0992c246f61de388f6e1612abd2f81dc585bd50208fc767a

See more details on using hashes here.

File details

Details for the file databeam_mcap_reader-0.4.1-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9c3967c37ef6669dbb826b408adb0a919df574af63970c7e9bd26be8ebaa33a9
MD5 ea8de690142eeff1cada33e86649287b
BLAKE2b-256 a6911b17debfbc4e8155f37216b5bb621bbc1a67b6edb3fe425e9c2443c59fc0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page