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

command raw_to_bids takes overwrite and line_freq as text and fails for brainvision format #1124

Closed
achilleasNP opened this issue Mar 8, 2023 · 1 comment · Fixed by #1125
Labels

Comments

@achilleasNP
Copy link

achilleasNP commented Mar 8, 2023

Description of the problem

raw_to_bids passes the arguments --overwrite and --line_freq to as text causing type errors. The --overwrite error only occurs when writing to brainvision format.

Steps to reproduce

from mne.datasets import eegbci
from mne.io import read_raw_edf
import os.path as path
import subprocess

def main():
    subject=1
    run=2
    fname = eegbci.load_data(subject=subject,runs=run, path="data/external")[0]

    subprocess.run(["mne_bids", "--version"])
    # Example with type problem for line_freq option
    subprocess.run(["mne_bids", "raw_to_bids", 
                   "--subject_id","TEST001", 
                   "--task","passive", 
			      "--raw", fname,
   	      		  "--overwrite", "True",
			      "--line_freq", "50",  
			      "--bids_root", "data/fail"])

    my_raw = read_raw_edf(fname)
    root, _ = path.splitext(fname)
    fname_fif = root + ".fif"
    my_raw.save(fname_fif)
    # The problem for overwrite appears when starting with a fif formatted file
 
    subprocess.run(["mne_bids", "raw_to_bids", 
                   "--subject_id","TEST001", 
                   "--task","passive", 
	           "--raw", fname_fif,
   	           "--overwrite", "True",
	           "--bids_root", "data/fail"])


if __name__ == "__main__":
    main()O

Expected results

Downloading file 'S001/S001R02.edf' from 'https://physionet.org/files/eegmmidb/1.0.0/S001/S001R02.edf' to '/home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0'.
MNE-BIDS 0.12
Extracting EDF parameters from /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.edf...
EDF file detected
Setting channel info structure...
Creating raw.info structure...
Extracting EDF parameters from /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.edf...
EDF file detected
Setting channel info structure...
Creating raw.info structure...
Writing 'data/fail/README'...
Writing 'data/fail/participants.tsv'...
Writing 'data/fail/participants.json'...
The provided raw data contains annotations, but you did not pass an "event_id" mapping from annotation descriptions to event codes. We will generate arbitrary event codes. To specify custom event codes, please pass "event_id".
Used Annotations descriptions: ['T0']
Writing 'data/fail/sub-TEST001/eeg/sub-TEST001_task-passive_events.tsv'...
Writing 'data/fail/dataset_description.json'...
Writing 'data/fail/sub-TEST001/eeg/sub-TEST001_task-passive_eeg.json'...
Writing 'data/fail/sub-TEST001/eeg/sub-TEST001_task-passive_channels.tsv'...
Copying data files to sub-TEST001_task-passive_eeg.edf
Writing 'data/fail/sub-TEST001/sub-TEST001_scans.tsv'...
Wrote data/fail/sub-TEST001/sub-TEST001_scans.tsv entry with eeg/sub-TEST001_task-passive_eeg.edf.
Extracting EDF parameters from /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.edf...
EDF file detected
Setting channel info structure...
Creating raw.info structure...
/home/apitsill/projects/bids/eeg/my_brain_technologies/failing_example.py:24: RuntimeWarning: This filename (/home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif) does not conform to MNE naming conventions. All raw files should end with raw.fif, raw_sss.fif, raw_tsss.fif, _meg.fif, _eeg.fif, _ieeg.fif, raw.fif.gz, raw_sss.fif.gz, raw_tsss.fif.gz, _meg.fif.gz, _eeg.fif.gz or _ieeg.fif.gz
  my_raw.save(fname_fif)
Writing /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif
Closing /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif
[done]
Opening raw data file /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif...
/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py:92: RuntimeWarning: This filename (/home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif) does not conform to MNE naming conventions. All raw files should end with raw.fif, raw_sss.fif, raw_tsss.fif, _meg.fif, _eeg.fif, _ieeg.fif, raw.fif.gz, raw_sss.fif.gz, raw_tsss.fif.gz, _meg.fif.gz, _eeg.fif.gz or _ieeg.fif.gz
  run()
Isotrak not found
    Range : 0 ... 9759 =      0.000 ...    60.994 secs
Ready.
Opening raw data file /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif...
/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py:92: RuntimeWarning: This filename (/home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif) does not conform to MNE naming conventions. All raw files should end with raw.fif, raw_sss.fif, raw_tsss.fif, _meg.fif, _eeg.fif, _ieeg.fif, raw.fif.gz, raw_sss.fif.gz, raw_tsss.fif.gz, _meg.fif.gz, _eeg.fif.gz or _ieeg.fif.gz
  run()
Isotrak not found
    Range : 0 ... 9759 =      0.000 ...    60.994 secs
Ready.
Writing 'data/fail/participants.tsv'...
Writing 'data/fail/participants.json'...
The provided raw data contains annotations, but you did not pass an "event_id" mapping from annotation descriptions to event codes. We will generate arbitrary event codes. To specify custom event codes, please pass "event_id".
Used Annotations descriptions: ['T0']
Writing 'data/fail/sub-TEST001/eeg/sub-TEST001_task-passive_events.tsv'...
Writing 'data/fail/dataset_description.json'...
Writing 'data/fail/sub-TEST001/eeg/sub-TEST001_task-passive_eeg.json'...
Writing 'data/fail/sub-TEST001/eeg/sub-TEST001_task-passive_channels.tsv'...
/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py:92: RuntimeWarning: Converting data files to BrainVision format
  run()
Writing 'data/fail/sub-TEST001/sub-TEST001_scans.tsv'...
Wrote data/fail/sub-TEST001/sub-TEST001_scans.tsv entry with eeg/sub-TEST001_task-passive_eeg.vhdr.

Actual results

Downloading file 'S001/S001R02.edf' from 'https://physionet.org/files/eegmmidb/1.0.0/S001/S001R02.edf' to '/home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0'.
MNE-BIDS 0.12
Extracting EDF parameters from /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.edf...
EDF file detected
Setting channel info structure...
Creating raw.info structure...
Traceback (most recent call last):
  File "/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py", line 92, in <module>
    run()
  File "/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py", line 84, in run
    raw.info['line_freq'] = line_freq
    ~~~~~~~~^^^^^^^^^^^^^
  File "/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne/io/meas_info.py", line 885, in __setitem__
    val = self._attributes[key](val)  # attribute checker function
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne/io/meas_info.py", line 351, in _check_line_freq
    _validate_type(line_freq, (None, 'numeric'), 'line_freq')
  File "/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne/utils/check.py", line 543, in _validate_type
    raise TypeError(
TypeError: line_freq must be an instance of None or numeric, got <class 'str'> instead.
Extracting EDF parameters from /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.edf...
EDF file detected
Setting channel info structure...
Creating raw.info structure...
/home/apitsill/projects/bids/eeg/my_brain_technologies/failing_example.py:24: RuntimeWarning: This filename (/home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif) does not conform to MNE naming conventions. All raw files should end with raw.fif, raw_sss.fif, raw_tsss.fif, _meg.fif, _eeg.fif, _ieeg.fif, raw.fif.gz, raw_sss.fif.gz, raw_tsss.fif.gz, _meg.fif.gz, _eeg.fif.gz or _ieeg.fif.gz
  my_raw.save(fname_fif)
Writing /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif
Closing /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif
[done]
Opening raw data file /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif...
/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py:92: RuntimeWarning: This filename (/home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif) does not conform to MNE naming conventions. All raw files should end with raw.fif, raw_sss.fif, raw_tsss.fif, _meg.fif, _eeg.fif, _ieeg.fif, raw.fif.gz, raw_sss.fif.gz, raw_tsss.fif.gz, _meg.fif.gz, _eeg.fif.gz or _ieeg.fif.gz
  run()
Isotrak not found
    Range : 0 ... 9759 =      0.000 ...    60.994 secs
Ready.
Opening raw data file /home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif...
/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py:92: RuntimeWarning: This filename (/home/apitsill/projects/bids/eeg/my_brain_technologies/data/external/MNE-eegbci-data/files/eegmmidb/1.0.0/S001/S001R02.fif) does not conform to MNE naming conventions. All raw files should end with raw.fif, raw_sss.fif, raw_tsss.fif, _meg.fif, _eeg.fif, _ieeg.fif, raw.fif.gz, raw_sss.fif.gz, raw_tsss.fif.gz, _meg.fif.gz, _eeg.fif.gz or _ieeg.fif.gz
  run()
Isotrak not found
    Range : 0 ... 9759 =      0.000 ...    60.994 secs
Ready.
Writing 'data/fail/README'...
Writing 'data/fail/participants.tsv'...
Writing 'data/fail/participants.json'...
The provided raw data contains annotations, but you did not pass an "event_id" mapping from annotation descriptions to event codes. We will generate arbitrary event codes. To specify custom event codes, please pass "event_id".
Used Annotations descriptions: ['T0']
Writing 'data/fail/sub-TEST001/eeg/sub-TEST001_task-passive_events.tsv'...
Writing 'data/fail/dataset_description.json'...
Writing 'data/fail/sub-TEST001/eeg/sub-TEST001_task-passive_eeg.json'...
Writing 'data/fail/sub-TEST001/eeg/sub-TEST001_task-passive_channels.tsv'...
/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py:92: RuntimeWarning: Converting data files to BrainVision format
  run()
Traceback (most recent call last):
  File "/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py", line 92, in <module>
    run()
  File "/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/commands/mne_bids_raw_to_bids.py", line 86, in run
    write_raw_bids(raw, bids_path, event_id=opt.event_id,
  File "<decorator-gen-620>", line 10, in write_raw_bids
  File "/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/write.py", line 1950, in write_raw_bids
    _write_raw_brainvision(raw, bids_path.fpath, events=events_array,
  File "/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/mne_bids/write.py", line 1064, in _write_raw_brainvision
    write_brainvision(data=raw.get_data(),
  File "/home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/lib/python3.11/site-packages/pybv/io.py", line 194, in write_brainvision
    raise ValueError("overwrite must be a boolean (True or False).")
ValueError: overwrite must be a boolean (True or False).

Additional information

Platform:         Linux-6.1.0-5-amd64-x86_64-with-glibc2.36
Python:           3.11.2 (main, Feb 12 2023, 00:48:52) [GCC 12.2.0]
Executable:       /home/apitsill/.local/share/virtualenvs/my_brain_technologies-HhFDe8va/bin/python
CPU:              : 8 cores
Memory:           Unavailable (requires "psutil" package)
mne:              1.3.1
numpy:            1.24.2 {unknown linalg bindings (threadpoolctl module not found: No module named 'threadpoolctl')}
scipy:            1.10.1
matplotlib:       3.7.1 {backend=TkAgg}

sklearn:          Not found
numba:            Not found
nibabel:          Not found
nilearn:          Not found
dipy:             Not found
openmeeg:         Not found
cupy:             Not found
pandas:           1.5.3
pyvista:          Not found
pyvistaqt:        Not found
ipyvtklink:       Not found
vtk:              Not found
qtpy:             Not found
ipympl:           Not found
pyqtgraph:        Not found
pooch:            v1.7.0

mne_bids:         0.12
mne_nirs:         Not found
mne_features:     Not found
mne_qt_browser:   Not found
mne_connectivity: Not found
mne_icalabel:     Not found
@achilleasNP achilleasNP added the bug label Mar 8, 2023
@welcome
Copy link

welcome bot commented Mar 8, 2023

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴🏽‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant