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

[MRG] FIX: Convert line_freq and overwrite to proper types in CLI #1125

Merged
merged 6 commits into from
Mar 9, 2023
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
3 changes: 2 additions & 1 deletion doc/whats_new.rst
Expand Up @@ -52,7 +52,8 @@ Detailed list of changes
^^^^^^^^^^^^

- Amending a dataset now works in cases where the newly-written data contains additional participant properties (new columns in ``participants.tsv``) not found in the existing dataset, by `Richard Höchenberger`_ (:gh:`1113`)
- Fixes :func:`~mne_bids.copyfiles.copyfile_eeglab` to prevent data type conversion leading to an ``eeg_checkset`` failure when trying to load the file in EEGLAB, by `Laetitia Fesselier`_ (:gh:`1122`)
- Fix ``raw_to_bids`` CLI tool to properly recognize boolean and numeric values for the ``line_freq`` and ``overwrite`` parameters, by `Stefan Appelhoff`_ (:gh:`1125`)
- Fix :func:`~mne_bids.copyfiles.copyfile_eeglab` to prevent data type conversion leading to an ``eeg_checkset`` failure when trying to load the file in EEGLAB, by `Laetitia Fesselier`_ (:gh:`1122`)

:doc:`Find out what was new in previous releases <whats_new_previous_releases>`

Expand Down
11 changes: 10 additions & 1 deletion mne_bids/commands/mne_bids_raw_to_bids.py
Expand Up @@ -8,6 +8,8 @@
# Stefan Appelhoff <stefan.appelhoff@mailbox.org>
#
# License: BSD-3-Clause
from itertools import chain, repeat

import mne_bids
from mne_bids import write_raw_bids, BIDSPath
from mne_bids.read import _read_raw
Expand Down Expand Up @@ -80,9 +82,16 @@ def run():
hsp=opt.hsp, config_path=opt.config,
allow_maxshield=allow_maxshield)
if opt.line_freq is not None:
line_freq = None if opt.line_freq == "None" else opt.line_freq
line_freq = None if opt.line_freq == "None" else float(opt.line_freq)
raw.info['line_freq'] = line_freq

if opt.overwrite is not None:
truthy = [1, "True", "true"]
falsy = [0, "False", "false"]
bool_mapping = dict(
chain(zip(truthy, repeat(True)), zip(falsy, repeat(False))))
opt.overwrite = bool_mapping[opt.overwrite]

write_raw_bids(raw, bids_path, event_id=opt.event_id,
events=opt.events, overwrite=opt.overwrite,
events_data=opt.events_data, verbose=True)
Expand Down
4 changes: 2 additions & 2 deletions mne_bids/commands/tests/test_cli.py
Expand Up @@ -67,7 +67,7 @@ def test_raw_to_bids(tmp_path):
# Should work
with ArgvSetter(('--subject_id', subject_id, '--task', task, '--raw',
raw_fname, '--bids_root', output_path,
'--line_freq', 60)):
'--line_freq', "60")):
mne_bids_raw_to_bids.run()

# Test line_freq == 'None'
Expand All @@ -81,7 +81,7 @@ def test_raw_to_bids(tmp_path):
edf_fname = op.join(edf_data_path, 'test.edf')
with ArgvSetter(('--subject_id', subject_id, '--task', task, '--raw',
edf_fname, '--bids_root', output_path,
'--line_freq', 60)):
'--overwrite', "false", '--line_freq', 60)):
mne_bids_raw_to_bids.run()

# Too few input args
Expand Down