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.0-cp313-cp313-win_amd64.whl (7.6 MB view details)

Uploaded CPython 3.13Windows x86-64

databeam_mcap_reader-0.4.0-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.0-cp312-cp312-win_amd64.whl (7.6 MB view details)

Uploaded CPython 3.12Windows x86-64

databeam_mcap_reader-0.4.0-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.0-cp311-cp311-win_amd64.whl (7.6 MB view details)

Uploaded CPython 3.11Windows x86-64

databeam_mcap_reader-0.4.0-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.0-cp310-cp310-win_amd64.whl (7.6 MB view details)

Uploaded CPython 3.10Windows x86-64

databeam_mcap_reader-0.4.0-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.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 82b3c9c0e2afe780b1766c28289b2f0e281cf9991c1c5b0d0243bcd15edbcda8
MD5 5a15e52022b17179aea84f794c0f7df4
BLAKE2b-256 16f4c94ace753ce4eb64590d9f50ce884ef6f4a7d7bb88532c42676e890ccfb4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7bb2729bc66bf344abaf062a015b7d4068d877a8e31349f4c652dd35deb67df1
MD5 ebbacc5bb2ea351449e1ad291df746af
BLAKE2b-256 a992f30431e7650d5b160d8edc8cd873047be8379e2923129d2e9feb57130525

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ab49c307f1f51ad5fe49ed80158c1c819bced7e531121640993b5ed963b31c52
MD5 e72a7e9e854bd2eae5d71c7eca8fac1c
BLAKE2b-256 99ed590182188cd4345f2a2bca9de4b21bb4fb0fd49eb64fb2622dfe5702081c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a20a10555ce3dcae0c9bab4faac2036505b5a6bfa5040c329d2a6f2051c3554e
MD5 97187901156154879d939e47545f5e14
BLAKE2b-256 eb3bb042c3b69aefe25871f3d6761ac59b1256925d067fce46407a64873e1040

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 748d1866ec7988a36f694822dfd851c7e28e06983c9e54ba390b1133ec44e8de
MD5 17cf2ff32e43ba60b9bc4aba1e132d6d
BLAKE2b-256 78f0e643ecafe7e209c7aadf491cf5e8a222674396e984e7a090d0ba98c91ff2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5af2dca834db91b691871dfe47f4361825fa5a2f746915491536f71ee156245c
MD5 637ae232e592a69c86fb755e6cdf6a8b
BLAKE2b-256 9b4a75585c18e5d7df2781786cf8de6e31defd478f9a1635758ed770bdc15fe3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a835ad58305c59cb1c585a3926be14e9d8e4d0ad5a82b6fb1e7ab36fb8497f4e
MD5 df653606eb6dd7d53427e8a1b14cb6f8
BLAKE2b-256 e2a9b46c0fef15726e860ac688e765c6c0bc9cc4314dba22ce7cfdcc2320dd67

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.4.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 802ccad21f6c09c9ee8023a07d40fc791772020bb1d955811b78b6b61751a89a
MD5 c14d9714cec94bd23410607e4bc9fac2
BLAKE2b-256 6d7bd636e210cb6dbc8b5baa3633adc7d35c0fa24ab51a89e899835d2edd8a58

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