pybv
is a lightweight exporter to the BrainVision data format.
The BrainVision data format is a recommended data format for use in the Brain Imaging Data Structure.
The documentation can be found under the following links:
- for the stable release
- for the latest (development) version
BrainVision is the name of a file format commonly used for storing electrophysiology data. Originally, it was put forward by the company Brain Products, however the simplicity of the format has allowed for a diversity of tools reading from and writing to the format.
The format consists of three separate files:
- A text header file (
.vhdr
) containing meta data - A text marker file (
.vmrk
) containing information about events in the data - A binary data file (
.eeg
) containing the voltage values of the EEG
Both text files are based on the Microsoft Windows INI format consisting of:
- sections marked as
[square brackets]
- comments marked as
; comment
- key-value pairs marked as
key=value
A documentation for core BrainVision file format is provided by Brain Products. You can view the specification as hosted by Brain Products.
pybv
runs on Python version 3.6 or higher.
pybv
's only dependency is numpy
. However, we currently recommend that
you install MNE-Python for reading BrainVision data. See their instructions
here.
After you have a working installation of MNE-Python (or only numpy
if you
don't want to read data and only write it), you can install pybv
through
the following:
pip install --upgrade pybv
or if you use conda:
conda install --channel conda-forge pybv
The development of pybv
is taking place on
GitHub.
For more information, please see CONTRIBUTING.md
The primary functionality provided by pybv
is the write_brainvision
function. This writes a numpy array of data and provided metadata into a
collection of BrainVision files on disk.
from pybv import write_brainvision
# for further parameters see our API documentation in the docs
write_brainvision(data, sfreq, ch_names, fname, tmpdir, events,
resolution=1e-6, unit='µV', fmt='binary_float32')
Currently, pybv
recommends using MNE-Python
for reading BrainVision files.
This results in a nearly-round-trip conversion of the data (up to the numerical
precision you specify in the resolution
parameter).
Here is an example of the MNE code required to read in BrainVision data:
import mne
# Import the BrainVision data into an MNE Raw object
raw = mne.io.read_raw_brainvision('tmp/test.vhdr', preload=True)
# Reconstruct the original events from our Raw object
events, event_ids = mne.events_from_annotations(raw)
This package was originally adapted from the Philistine package by palday. It copies much of the BrainVision exporting code, removes the dependence on MNE, and focuses the code around BrainVision I/O.