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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6b4708983b4b1b39ab291504746ee2e67dc603e5e3ce0337d165f1bb95348a9d
MD5 69ac27cff55dd8999c3f9ca128283803
BLAKE2b-256 734258b4545e9b6d50c5966e017326347f1f57ec8f6688aed4eb490a21964348

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7cb65ec31f6a208ddd0e2454b3c1872e3d0fa453eead4c7dcbe641e5539b6533
MD5 f320b3e7bd8c7dffea1e5fc58a35485d
BLAKE2b-256 5d3e6d2b7bd6c3b322346f201460d6d3a6359462952f26ed9aa0b31c53866074

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 75249c3982ff01839218969f3bb5a6814a1f002744a56638a3bc59a07dabbd59
MD5 a0c2cb359c10f917df22a9d7fd4d9d83
BLAKE2b-256 b777a61cae29a8eee38612ee1345354daacd2c3edc3c6a4f2d4128de546ee7fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d00b6ac615546bd0787cb7549e470dc10e148154bd54362a77eda5ac6cd26466
MD5 e1f61e26752c88db65f4aff3c501c955
BLAKE2b-256 a08745395f8d81ce08c4dee760f5e75877c4a417eb09049b725824b7010d0c9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 be544bc16e98dedee5e95b67fd4e09aa52318176bda3555a347247dada22adcc
MD5 75270acf9f630b56178964762ccee194
BLAKE2b-256 d9619b55169925d3b62a4a240a897c29be07b49f9f77a61607a368925acd318d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6f091aa76e83d8ecd2e8dd35970b5638cdbfa34fad9d78dac3261290d912e74f
MD5 6c5fb1d2e7642ccca7da4a57336e04a4
BLAKE2b-256 711ec9651a2d27847003ea3f6133d0b0f8b351706e5be6a7b2a67b907ce7eb17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bdc23adef291d30c17dbb5fcbda08c3d2e84ce165686cab9ca492d5b90bbfdd8
MD5 ea236631371e4fc15569866c96208306
BLAKE2b-256 7bcf50e6d3581069c909849a5ef5dc96c8e139d5940df742d8c6e2659c90f3f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for databeam_mcap_reader-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bf39d602f76657a36881da2b78f1bc734041a42c4db7c422cdfacac6f4ff1690
MD5 6228944d73f5a11ca404546f0580d3c9
BLAKE2b-256 0f1a1abf9fcd364fb185dbc5253bf2df1220382caad6db29512ffe02d37847dd

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