Skip to content

Commit

Permalink
FIX: export name
Browse files Browse the repository at this point in the history
  • Loading branch information
sappelhoff committed May 28, 2022
1 parent 355b76a commit 8c5bd42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pybv/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ def _export_mne_raw(*, raw, fname, events=None, overwrite=False):
----------
raw : mne.io.Raw
The raw data to export.
fname : str
The name of the file where raw data will be exported to. Must end with ".vhdr",
and accompanying ".vmrk" and ".eeg" files will be written inside the same
directory.
fname : str | pathlib.Path
The name of the file where raw data will be exported to. Must end with
``".vhdr"``, and accompanying *.vmrk* and *.eeg* files will be written
inside the same directory.
events : np.ndarray | None
Events to be written to the marker file (*.vmrk*). When array, must be in
`MNE-Python format <https://mne.tools/stable/glossary.html#term-events>`_.
When ``None`` (default), events will be written based on ``raw.annotations``.
overwrite : bool
Whether or not to overwrite existing data. Default to ``False``.
Whether or not to overwrite existing data. Defaults to ``False``.
"""
# Prepare file location
if not str(fname).endswith(".vhdr"):
raise ValueError("`fname` must have the '.vhdr' extension for BrainVision.")
fname = Path(fname)
folder_out = fname.parents[0]
fname_base = fname.name
fname_base = fname.stem

# Prepare data from raw
data = raw.get_data() # gets data starting from raw.first_samp
Expand Down
5 changes: 5 additions & 0 deletions pybv/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def test_export_mne_raw(tmpdir):
with pytest.warns(RuntimeWarning, match="'double' .* Converting to float32"):
_export_mne_raw(raw=raw, fname=fname)

with pytest.raises(ValueError, match="`fname` must have the '.vhdr'"):
_export_mne_raw(raw=raw, fname=str(fname).replace(".vhdr", ".eeg.tar.gz"))

# test overwrite
with pytest.warns():
_export_mne_raw(raw=raw, fname=fname, overwrite=True)
Expand All @@ -63,3 +66,5 @@ def test_export_mne_raw(tmpdir):
]
).T
_export_mne_raw(raw=raw, fname=fname, events=events)
raw_read = mne.io.read_raw_brainvision(fname)
np.testing.assert_allclose(raw_read.get_data(), raw.get_data())

0 comments on commit 8c5bd42

Please sign in to comment.