Skip to content

Commit

Permalink
Use built-in MNE export
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrnr committed Apr 9, 2024
1 parent 3efff83 commit 0580df5
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions mnelab/io/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,7 @@ def write_edf(fname, raw):

def write_bv(fname, raw, events=None):
"""Export data to BrainVision EEG/VHDR/VMRK file (requires pybv)."""
import pybv

name, _ = Path(fname).stem, "".join(Path(fname).suffixes)
parent = Path(fname).parent
data = raw.get_data()
fs = raw.info["sfreq"]
ch_names = raw.info["ch_names"]
if events is None:
if raw.annotations:
events = mne.events_from_annotations(raw, regexp=None)[0]
dur = raw.annotations.duration * fs
events = np.column_stack([events[:, [0, 2]], dur.astype(int)])
else:
events = events[:, [0, 2]]
units = [ch["unit"] for ch in raw.info["chs"]]
units = ["µV" if unit == 107 else "AU" for unit in units]
pybv.write_brainvision(
data=data,
sfreq=fs,
ch_names=ch_names,
fname_base=name,
folder_out=parent,
events=events,
unit=units,
)
raw.export(fname=Path(fname).with_suffix(".vhdr"), events=events)


# this dict contains each supported file extension as a key; the corresponding value is a
Expand Down

0 comments on commit 0580df5

Please sign in to comment.