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()

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

databeam_mcap_reader-0.3.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.3.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for databeam_mcap_reader-0.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c15f3d0be328476a4383d812f3f954c646f10bbac7566eb82bb9dcb2e0124de9
MD5 fc98038156ea66fd2471e66b9d3d55c9
BLAKE2b-256 4d252e497ccfd9bcbd9a3627b33e841e95a456459e8d21b2fcfe8edaf2fd2a47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.3.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1d957735358fc1fcd7f078ba4fa5722805695601979264d7d4b5c6e5bc607bc0
MD5 f95e3d8ed291683f509e2c521ff09617
BLAKE2b-256 c0f5f1ed231d1fa1312164c885561277ce35af8062127fb3657226818b7bbdc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1b4f8a92f3331485e8d4bfd418db960f436807bb1bd18583fe1514e7f381c21f
MD5 d704ca20f72e9455ac911d8523b87ab6
BLAKE2b-256 e561daca61ecb80924418c26fe40d36617e00ebcd209e23e77532394ac23a952

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4317da5f73a05eba8663f81e8dd94b8b0a3e10f349cb7f9f17c2b0bb7d41a158
MD5 5f5c785c52c4113c362274cb5f6e96ce
BLAKE2b-256 ab9a3ae44365455f557ad4b013fb09a9df7c7ed6c2692b39327fdeece554bf29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b12f4bd2293fde19c015a7fa66031e088ac780e4ae09f521a77ec78778efbb05
MD5 bc0d6a92bfb86378dde94d47edd7a46d
BLAKE2b-256 4236efb2c484ea86d19d64f9a5a113cf36676254757b9e5820f8c8d7476f7cce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5e7e4952aca5c024560fedb2a7797ffc50aaa92cacedad26d8847e35c49d4fe3
MD5 86cdfe7833a86ed36b605237dd9cddcd
BLAKE2b-256 75bf890ce601e9a5fa041a477960616cfabff95283278385f35869da9e254bb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 308a5a656337ed0068433815acb6650516b772abb53462ffbbda7b2d3f246215
MD5 fe6ce049025465a6cf167e5b12c290dd
BLAKE2b-256 37d6de21d4c03b850db0b312f136592b8e150c77f779a4d65d1e2a741a5df0cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 93b8df2397510c0fbaab5a8523075aeae301120d2ce51c907fd57d145ff94e53
MD5 4efe375a2e27519698ed6e99b256c860
BLAKE2b-256 374df9988b514fdf88c5039c78c7e60963654e87519b0c2160340019b2a36873

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