Skip to content

Commit

Permalink
Force little-endian format when writing eeg datafile (#80)
Browse files Browse the repository at this point in the history
* force little-endian format when writing eeg datafile


Fix styling guideline

* add information regarding little-endian format in the docs

* tweak readme text

* modify condition when to swap bytes

* fit if clause on one line

Co-authored-by: Clemens Brunner <[email protected]>

* Ignore lines that cannot be tested from coverage

* Update contributors list and changelog

* remove redundant comments/pragmas

* add website and fix naming syntax

* Update docs/changelog.rst

Co-authored-by: Clemens Brunner <[email protected]>

* Fix indentation error E129

* Apply suggestions from code review

* simplify check

* changelog style

Co-authored-by: Stefan Appelhoff <[email protected]>
Co-authored-by: Clemens Brunner <[email protected]>
  • Loading branch information
3 people authored Sep 29, 2021
1 parent 456d014 commit 0088662
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ authors:
- given-names: "Phillip"
family-names: "Alday"
orcid: https://orcid.org/0000-0002-9984-5745
- given-names: "Aniket"
family-names: "Pradhan"
orcid: https://orcid.org/0000-0002-6705-5116
title: "pybv"
version: 0.5.0
date-released: 2021-01-03
Expand Down
7 changes: 6 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ consisting of:
- comments marked as ``; comment``
- key-value pairs marked as ``key=value``

A documentation for core BrainVision file format is provided by Brain Products.
The binary ``.eeg`` data file is written in little-endian format without a Byte Order
Mark (BOM), in accordance with the specification by Brain Products.
This ensures that the data file is uniformly written irrespective of the
native system architecture.

A documentation for the BrainVision file format is provided by Brain Products.
You can `view the specification <https://www.brainproducts.com/productdetails.php?id=21&tab=5>`_
as hosted by Brain Products.

Expand Down
7 changes: 6 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Authors
People who contributed to this software across releases (in **alphabetical order**):

- `Adam Li`_
- `Aniket Pradhan`_
- `Chris Holdgraf`_
- `Clemens Brunner`_
- `Phillip Alday`_
Expand All @@ -31,13 +32,16 @@ Current (unreleased)

Changelog
~~~~~~~~~

- :func:`pybv.write_brainvision` gained a new parameter, ``ref_ch_names``, to specify the reference channels used during recording, by `Richard Höchenberger`_ and `Stefan Appelhoff`_ (:gh:`75`)

API
~~~
- :func:`pybv.write_brainvision` now has an ``overwrite`` parameter that defaults to ``False``, by `Stefan Appelhoff`_ (:gh:`78`).

Bug
~~~
- Fix bug where :func:`pybv.write_brainvision` would write the binary file in big-endian on a big-endian system, by `Aniket Pradhan`_, `Clemens Brunner`_, and `Stefan Appelhoff`_ (:gh:`80`)

0.5.0 (2021-01-03)
==================

Expand Down Expand Up @@ -125,3 +129,4 @@ Changelog
.. _Clemens Brunner: https://cbrnr.github.io/
.. _Richard Höchenberger: https://hoechenberger.net/
.. _Adam Li: https://adam2392.github.io/
.. _Aniket Pradhan: http://home.iiitd.edu.in/~aniket17133/
10 changes: 10 additions & 0 deletions pybv/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import datetime
import os
import shutil
import sys
from os import path as op
from warnings import warn

Expand Down Expand Up @@ -491,5 +492,14 @@ def _write_bveeg_file(eeg_fname, data, orientation, format, resolution, units):
raise ValueError(msg)
data = data.astype(dtype=dtype)

# We always write data as little-endian without BOM
# `data` is already in native byte order due to numpy operations that
# result in copies of the `data` array (see above)
assert data.dtype.byteorder == "="

# swap bytes if system architecture is big-endian
if sys.byteorder == "big": # pragma: no cover
data = data.byteswap()

# Save to binary
data.ravel(order='F').tofile(eeg_fname)

0 comments on commit 0088662

Please sign in to comment.