Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable writing a meas_date event #32

Merged
merged 7 commits into from Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/changelog.rst
Expand Up @@ -15,6 +15,12 @@ Here we list a changelog of pybv.
Current
=======

Changelog
~~~~~~~~~
- Add option to disable writing a meas_date event (which is also the new default) by `Clemens Brunner`_ (`#32 <https://github.com/bids-standard/pybv/pull/32>`_)



0.1.0
=====

Expand Down Expand Up @@ -65,3 +71,4 @@ Authors
.. _Stefan Appelhoff: http://stefanappelhoff.com/
.. _Tristan Stenner: https://github.com/tstenner
.. _Phillip Alday: https://palday.bitbucket.io/
.. _Clemens Brunner: https://cbrnr.github.io/
18 changes: 10 additions & 8 deletions pybv/io.py
Expand Up @@ -67,10 +67,11 @@ def write_brainvision(data, sfreq, ch_names, fname_base, folder_out,
Binary format the data should be written as. Valid choices are
'binary_float32' (default) and 'binary_int16'.
meas_date : datetime.datetime | str | None
The measurement date of the data specified as a datetime.datetime
object. Alternatively, can be a string in the format:
"YYYYMMDDhhmmssuuuuuu". "u" stands for microseconds. If None, defaults
to '00000000000000000000'.
The measurement date specified as a datetime.datetime object.
Alternatively, can be a string in the format 'YYYYMMDDhhmmssuuuuuu'
('u' stands for microseconds). Note that setting a measurement date
implies that one additional event is created in the .vmrk file. To
prevent this, set this parameter to None (default).
"""
# Create output file names/paths
if not op.isdir(folder_out):
Expand Down Expand Up @@ -118,10 +119,10 @@ def write_brainvision(data, sfreq, ch_names, fname_base, folder_out,
raise ValueError('`meas_date` must be of type str, datetime.datetime, '
'or None but is of type '
'"{}"'.format(type(meas_date)))
elif meas_date is None:
meas_date = '00000000000000000000'
elif isinstance(meas_date, datetime.datetime):
meas_date = meas_date.strftime('%Y%m%d%H%M%S%f')
elif meas_date is None:
pass
elif not (meas_date.isdigit() and len(meas_date) == 20):
raise ValueError('Got a str for `meas_date`, but it was not formatted '
'as expected. Please supply a str in the format: '
Expand Down Expand Up @@ -173,7 +174,8 @@ def _write_vmrk_file(vmrk_fname, eeg_fname, events, meas_date):
print(r'; <Date (YYYYMMDDhhmmssuuuuuu)>', file=fout)
print(r'; Fields are delimited by commas, some fields might be omitted (empty).', file=fout) # noqa: E501
print(r'; Commas in type or description text are coded as "\1".', file=fout) # noqa: E501
print(r'Mk1=New Segment,,1,1,0,{}'.format(meas_date), file=fout)
if meas_date is not None:
print(r'Mk1=New Segment,,1,1,0,{}'.format(meas_date), file=fout)

if events is None or len(events) == 0:
return
Expand All @@ -187,7 +189,7 @@ def _write_vmrk_file(vmrk_fname, eeg_fname, events, meas_date):
twidth = twidth if twidth > 3 else 3
tformat = 'S{:>' + str(twidth) + '}'

for marker_number, irow in enumerate(range(len(events)), start=2):
for marker_number, irow in enumerate(range(len(events)), start=1 if meas_date is None else 2): # noqa: E501
i_ix = events[irow, 0] + 1 # BrainVision uses 1-based indexing
i_val = events[irow, 1]
print(r'Mk{}=Stimulus,{},{},1,0'
Expand Down