Skip to main content

A Python package for working with BrainVision Recording Format (BVRF) files.

Project description

Python PyPI License

PyBVRF

PyBVRF is a Python package for working with BVRF (BrainVision Recording Format) files.

The package includes the following features:

  • Support for multi-participant recordings
  • Seamless integration with MNE-Python
  • Convenient access to metadata (including the original YAML header)
  • Support for markers and impedance data

A BVRF recording consists of multiple files which are expected to be available in the same directory. The required files are:

  • <fname>.bvrh (header file)
  • <fname>.bvrd (data file)
  • <fname>.bvrm (marker file)

Optionally, <fname>.bvri (impedance file) may also be present.

Basic usage

Use read_bvrf() to load a recording. The file extension is optional (the function accepts any of the four supported extensions or just the base filename).

from pybvrf import read_bvrf

header, data, markers, impedances = read_bvrf("recording")

Here, header is a dict containing metadata about the recording (such as sampling frequency, channel names, and participant information):

print(f"Sampling frequency: {header['fs']} Hz")
print(f"Number of channels: {header['n_channels']}")
print(f"Channel names: {header['ch_names']}")
print(f"Number of participants: {header['n_participants']}")

The entire original header information is available as header["yaml_header"] (a dict parsed from the YAML header file).

Next, data is a 2D NumPy array (channels ⨉ samples) containing the EEG signals:

print(f"Data shape: {data.shape}")

Finally, markers contains information about events in a NumPy structured array:

print(f"Number of markers: {len(markers)}")
print(f"Marker fields: {markers.dtype.names}")

If impedances are available, impedances is a dict mapping channel names to impedance values:

if impedances:
    print(f"Impedances: {impedances}")

Advanced usage

Multi-participant recordings (header["n_participants"] > 1) are available in a single data structure by default, with channels from all participants concatenated together (but suffixed with the participant ID). For example, if there are two participants P1 and P2, the channel names might be "C3 (P1)", "Cz (P1)", "C4 (P1)", "C3 (P2)", "Cz (P2)", and "C4 (P2)". You can use split_participants() to split the data into separate data structures per participant:

from pybvrf import split_participants

participant_data = split_participants(header, data, markers, impedances)

This returns a dict mapping participant IDs to their respective data (a tuple of header, data, markers, and impedances).

MNE-Python integration

PyBVRF integrates seamlessly with MNE-Python for advanced EEG analysis:

from pybvrf import read_raw_bvrf

raw = read_raw_bvrf("recording.bvrh")

Like read_bvrf(), read_raw_bvrf() accepts any of the four supported file extensions or just the base filename. It returns a Raw object containing the EEG data, along with the appropriate metadata and annotations.

If a recording includes multiple participants, the function returns a single Raw object by default, with all participants' data concatenated (channel names are suffixed with the participant ID as described above).

You can also load selected participants and/or split multi-participant recordings into separate Raw objects:

from pybvrf import read_raw_bvrf

# load specific participants
raw = read_raw_bvrf("multi_recording.bvrh", participants="P1")
raw = read_raw_bvrf("multi_recording.bvrh", participants=["P1", "P2"])

# split into separate Raw objects per participant
raw_dict = read_raw_bvrf("multi_recording.bvrh", split=True)
for pid, raw in raw_dict.items():
    print(f"Participant {pid}: {raw.info['nchan']} channels")
    
# load specific participants and split
raw_dict = read_raw_bvrf("multi_recording.bvrh", participants=["P1", "P3"], split=True)

Acknowledgements

The initial release of PyBVRF was sponsored by Brain Products.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybvrf-0.1.2.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybvrf-0.1.2-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file pybvrf-0.1.2.tar.gz.

File metadata

  • Download URL: pybvrf-0.1.2.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pybvrf-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e1978553413b737e1e2f7ac6d4ac73d39ad7d2ba1d8634d00a9f75744eca4c67
MD5 586d27de2c8ec5e4c14213e9c8130fa2
BLAKE2b-256 5607ab0ae019d1d0992efd8fb7941dd1fc35ca3a2ab19c3ecfe038da8cabcb27

See more details on using hashes here.

File details

Details for the file pybvrf-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pybvrf-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pybvrf-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c9287fc90d857694723b1ac8ed338290b4b754b4c7c0adc9213bedc4ef490b8
MD5 5b8c961cd3e9d5f3a334414768efcbc4
BLAKE2b-256 bb7ea82cbdb8e164e5802d18bd9cccc8018e4b09c186b69395451413dd6d074e

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