Skip to main content

MDF4 Iterator - Load Raw CAN Bus Data

This package lets you extract raw CAN bus data from the CANedge MDF4 log files. The package can e.g. be used together with the canedge_browser and can_decoder modules.


Key features

1. Easily extract raw CAN bus data from MDF4 files
2. Data can be loaded from a local path or e.g. from an S3 server path
3. The output can be an iterable or a pandas dataframe
4. Files can e.g. be loaded from lists generated by the canedge_browser package
5. Loaded CAN data can be decoded using the can_decoder package
6. No external dependencies
7. Faster bulk extraction using optional dependencies

Installation

Use pip to install the mdf_iter module:

pip install mdf_iter

Optionally install pandas for fast bulk loading:

pip install pandas

Dependencies

  • pandas (optional)

Platforms

Pre-built wheels are available for the following platforms:

  • Linux: x86-64 (Python 3.7+)
  • Windows: x86-64 (Python 3.7+)

Other platforms require manual compilation from source.


Module usage examples

Below we open and iterate over the CAN records in a log file from local disk:

import mdf_iter

mdf_path = "00000001.MF4"

with open(mdf_path, "rb") as handle:
    mdf_file = mdf_iter.MdfFile(handle)
    record_iterator = mdf_file.get_can_iterator()
    
    for record in record_iterator:
        print(record)

Below we open a log file from an S3 server into a pandas dataframe:

import mdf_iter
import s3fs

fs = s3fs.S3FileSystem(
    key="<key>", secret="<secret>", client_kwargs={"endpoint_url": "<url>"}
)
mdf_path = "bucket_name/12345678/00000001/00000001-12345678.MF4"

with fs.open(mdf_path, "rb") as handle:
    mdf_file = mdf_iter.MdfFile(handle)
    df_raw = mdf_file.get_data_frame()

print(df_raw)

Regarding data sources (local, S3 servers, ...)

The package can by default handle inputs in the form of:

  • Python strings
  • Python Path objects from pathlib
  • File-like objects, obtained using open(file_name, "rb") or fsspec and similar projects.

Any other data source can be adapted to work with the library, if it behaves like a file.

fs = some_fsspec_filesystem_implementation
file_path = a_valid_fsspec_file_path

with fs.open(file_path, "rb") as handle:
    mdf_file = mdf_iter.MdfFile(handle)
    ...

For examples using fsspec to e.g. load data from an S3 server (for use with the CANedge2, see the examples folder.


Extraction methods

Data can be extracted either through an iterator, or in bulk using pandas if it is installed.

with mdf_iter.MdfFile("path") as mdf_file:
    # Using iterator.
    record_iterator = mdf_file.get_can_iterator()
    
    for record in record_iterator:
        ...
    
    # Using pandas.
    df_raw = mdf_file.get_data_frame()

print(df_raw)

Extracting log file metadata

Metadata for a log file is accessible through get_metadata(). This returns a dictionary with string keys and dictionary values in the form of MdfMetadataEntry. These are also dictionaries, which expose the possible metadata from the blocks in the MDF file. The possible fields are:

  • description - description of the field
  • name - name of the field, also part of the key
  • read_only - whether the field is marked as read only (has no effect)
  • unit - associated unit for the field
  • value_raw - the value as a string
  • value_type - the value type

For further usage examples, see the examples folders.

Metadata

Release files for mdf-iter 2.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for mdf-iter 2.1.1
File Interpreter ABI Platform
mdf_iter-2.1.1-cp37-abi3-win_amd64.whl CPython 3.7 abi3 Windows x86-64 Details
mdf_iter-2.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 abi3 Linux glibc 2.17+ x86-64 Details
mdf_iter-2.1.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.7 abi3 Linux glibc 2.17+ ARM64 Details

Total release size: 1.3 MB

Release files / mdf_iter-2.1.1-cp37-abi3-win_amd64.whl

Download URL mdf_iter-2.1.1-cp37-abi3-win_amd64.whl
Size 522.5 kB
Tags CPython 3.7 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
77d6e077e75ecc2fffed5f49b25b22e0f93255d9c3fb07e16090f803a117beef
BLAKE2b-256 checksum
How to use checksums
c3ffdeb29948563c6c8eaab30eae1e1e0a49c761c0e070d445084a959799d0a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / mdf_iter-2.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mdf_iter-2.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 412.1 kB
Tags CPython 3.7 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
e6106c7202d64f80443686188233f5c042b4f141e111c55d5789ad4509e4f2eb
BLAKE2b-256 checksum
How to use checksums
3ef979deb2a14a19de5961ec17136958939d84714c29f6d7daab96a6f3c79204
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / mdf_iter-2.1.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL mdf_iter-2.1.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 392.0 kB
Tags CPython 3.7 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
5fa06cf38b9b07b8a1deaaecf6d439d9930fb37080a7c0b2bdb53111156512d5
BLAKE2b-256 checksum
How to use checksums
5a3256c3a80d53542b141147ff8c716cabbd0879680e80ba08e5c176d6b765fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

2.1.1 This release

3 release files

2.0.10

3 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

0.0.7

3 release files

0.0.6

3 release files

0.0.4

7 release files

0.0.3

5 release files

0.0.2

4 release files

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page