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.

Reader

Full Reader API reference: API_REF_READER.md

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.

Collector

Usage of Data Collector

TODO

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

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

Uploaded CPython 3.14Windows x86-64

databeam_mcap_reader-0.5.2-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.2-cp313-cp313-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.13Windows x86-64

databeam_mcap_reader-0.5.2-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.2-cp312-cp312-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.12Windows x86-64

databeam_mcap_reader-0.5.2-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.2-cp311-cp311-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.11Windows x86-64

databeam_mcap_reader-0.5.2-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.2-cp310-cp310-win_amd64.whl (9.8 MB view details)

Uploaded CPython 3.10Windows x86-64

databeam_mcap_reader-0.5.2-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.2-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 bc5f6e1b8fff993243996d6f1fb4e25c2f1cde07ed8958e9a265a2c6d5a42af6
MD5 fc41910dcb24fb8df69bac414670db44
BLAKE2b-256 47e44df2ce88f55924e248bb9e1d120337c527ede012a4c2192e98a039dfdbf7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.2-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 880330286672553f87f488bf58d223f210a5b5e4cd972544ad6c95b5824c278d
MD5 d697c0a75c265cad9bcf83db1bf8354b
BLAKE2b-256 c5c5b59fd621038bfdd35ccd3cb3a2175f3e11b2f25a6cb2fba10a8973109de9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4957c0af3147aec47f09aa8dabe2f5a81da41c94c84713ed420cdced258147e8
MD5 a45faa34b8ad9c2b4f1b109d53006f5e
BLAKE2b-256 7ed32218c4b62be65baacc548a1d0c0e7e7f7721b9690699ef094ac21460db0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 08d594a5b8a545cae8db60d5231d40e4cdebdd95a3621b913cf09b918f80d165
MD5 d2a7b9dbf4656cbcab75c8c88f26afe4
BLAKE2b-256 78e233887c4575bc1b3b2e8e94d663d5f71dd530632f7e8e623111010f3dbb3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6f8b8774446b668052477e29e6f2be3b48dc83893ead7ceca25d965cf111fa93
MD5 caac0d163cb2ae16dd44dd88e5ba2ef4
BLAKE2b-256 20e5973075ffe6dff4cb73dbe658a788c3a7081ae041641b49cb9d54e5870b35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4aeabde1896a121c8a674ec37a9dbba5102ccbaa87a192fbfa7ecdf406d94a8b
MD5 69e16f4bf1b2065ef39b31caf71419e3
BLAKE2b-256 c337d2e6f203f2e78043dc7dc447f988b4f9c9f398d686f9cb93cc7179de5708

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 860d8cbee4026a85d873467f74fc5ae0851ede5c5e50d9efe69781be0e462106
MD5 ab2148702c79ce0224b8e9b03a4eda75
BLAKE2b-256 3cfae256766378e381aff93a8a94fe33b2f9ef04c1abe2ec3ca55548840998c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.2-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 535aee977d857f7e1cdcee3d47825d60842b6bd25291947110b90b6c5fbab8a6
MD5 1ce2edf8adaaa822874b9f6e662950ea
BLAKE2b-256 12e161a03e956d54ee6e8cf7329f0ea40a0e8ad305ee601d6441b85f8121699e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 88c3a63296f833aeb4b178ec9c9e5226cdb81a8c7d45307da7ff45a5b94cfb22
MD5 583ed67d4bda623736f46c0e44149df9
BLAKE2b-256 a4b6da8e7d2f90ff043124f6f2c95f552357efb1863c5bea2e4f4c8983a2f977

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6d7a5564af06d602b2f8e4b297a3e5ab3fa11ed0ffb08021f96fb375c2c47f46
MD5 d711e10f4f388eb5daeac2ac502eadc6
BLAKE2b-256 a87e2142ad12317ad0c7ebd3285e319f357ab220d75963ed18660873674ba1df

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