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.5.1-cp314-cp314-win_amd64.whl (10.0 MB view details)

Uploaded CPython 3.14Windows x86-64

databeam_mcap_reader-0.5.1-cp314-cp314-manylinux_2_34_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

databeam_mcap_reader-0.5.1-cp313-cp313-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.13Windows x86-64

databeam_mcap_reader-0.5.1-cp313-cp313-manylinux_2_34_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

databeam_mcap_reader-0.5.1-cp312-cp312-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.12Windows x86-64

databeam_mcap_reader-0.5.1-cp312-cp312-manylinux_2_34_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

databeam_mcap_reader-0.5.1-cp311-cp311-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.11Windows x86-64

databeam_mcap_reader-0.5.1-cp311-cp311-manylinux_2_34_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

databeam_mcap_reader-0.5.1-cp310-cp310-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.10Windows x86-64

databeam_mcap_reader-0.5.1-cp310-cp310-manylinux_2_34_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

File details

Details for the file databeam_mcap_reader-0.5.1-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 87ec6fbe9314578a19fab6fcab5577e0aaf3b236c5edcfc56be6814f8f7b29ed
MD5 f11624645b2e346e5305b7c870be07fa
BLAKE2b-256 21b4f62744221e7a887b528dacf5a62feed0f4fbf9d3f8e320f34763ccfda491

See more details on using hashes here.

File details

Details for the file databeam_mcap_reader-0.5.1-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.1-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4637c6e8ac107c91877c834d3bc4c1bd0a114571c611c65ef9fc20db158b0f4c
MD5 44abdfb52592d192b9c8fc3e274a3b6e
BLAKE2b-256 d4d82cdb27add20057f15787381527024d8d21d37f7e5365371062474b7ad0d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3009f7635012bed785c92b599d9a96210a44dac0c2199aff575efafe4bdf8a82
MD5 d85ae13e9ff4bca6eb77a037e79dfb49
BLAKE2b-256 3f74a673144446b7b22e8803c93f625baf66282b8f323d369dd58c76b469ee91

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 110440ad04a12e2f04e14f490fc9a611fbf723331019e42e1129ca0b4e1f989e
MD5 73e4160426e3b53389eb5d0b29757769
BLAKE2b-256 6cb65e24f5097ecfa61e5fdc90f6c248109e061d3c95504f5bbbd115aded221c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 842f0dd5899c15350b0c10279944edc2d91dc50494c0b63c5864bc77409c56c3
MD5 124fad24e416d36c1005d3994ab25db3
BLAKE2b-256 d9abfe9da845fc2138be206baec52719a7e5fc58dc1e93c1b87e281d52448e5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b8f057f0716fa4099982d195ace554bca8c7794b7054b06a27c432ce8c03ff43
MD5 55efb9a7d595e5fac5dbfea369d41f67
BLAKE2b-256 78d934b6c076bdac5eb7ebf7713fed0cab707e597b391b2b223569a5dd2cf8c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b52047134c531dd3fa2692e37ff3d0989834dc628a5210b4f6506e1aae867aa7
MD5 ee342d54f9aecc1cff49529f3e4df7de
BLAKE2b-256 50231db38a6820b7101ff0bc70d0dd544b67cb3e9b80d0da4423438555326973

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f5bc0179eff5a84cea54557eb0d9d7d5d0238745f86664ae8d9f03f2d4ee5d27
MD5 55c099293ffcfa0654950597e5ea3114
BLAKE2b-256 84447113c9536409e33186ec8c9aabe28c9175259e1b8e6eb10588834f0b9625

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 333bbaa85a509b336e1df20455dbd2a7672bc865654348a4677f2847c096f84f
MD5 4c358e222eefe397fde3356c0584caef
BLAKE2b-256 678c1278edf6c6bf9541544b20a1e6f953e685f617d87cdfca7ff239645ef52f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b59ee9d0095fef5e1a803ae6fea2f171847c6333e731a0a481ee790b61a0814e
MD5 d7ad04f14771da249a99bec09e267984
BLAKE2b-256 437e37ffa670563d2bcdce3065942ac7b45d661f25d1efbc80552206dadc1590

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