MNE-BIDS-Pipeline too many json files error

Hello,

I’ve got an error from mne-bids-pipeline that there are too many json files in my bids dataset:

Aborting pipeline run. The full traceback is:

Traceback (most recent call last):

  File "/home/ma09/.conda/envs/my_mne1.3/lib/python3.10/site-packages/mne_bids_pipeline/_run.py", line 55, in wrapper
    out = memory.cache(func)(*args, **kwargs)

  File "/home/ma09/.conda/envs/my_mne1.3/lib/python3.10/site-packages/mne_bids_pipeline/_run.py", line 148, in wrapper
    in_files = kwargs["in_files"] = self.get_input_fnames(**these_kwargs)

  File "/home/ma09/.conda/envs/my_mne1.3/lib/python3.10/site-packages/mne_bids_pipeline/steps/init/_02_find_empty_room.py", line 43, in get_input_fnames_find_empty_room
    bids_path_in.copy()

  File "/home/ma09/.conda/envs/my_mne1.3/lib/python3.10/site-packages/mne_bids/path.py", line 987, in find_matching_sidecar
    return _find_matching_sidecar(

  File "/home/ma09/.conda/envs/my_mne1.3/lib/python3.10/site-packages/mne_bids/path.py", line 1552, in _find_matching_sidecar
    raise RuntimeError(msg)

RuntimeError: Expected to find a single .json file associated with sub-01_task-main_run-01, but found 11:

/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/meg/sub-01_coordsystem.json
/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/meg/sub-01_task-main_run-01_meg.json
/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/meg/sub-01_task-main_run-02_meg.json
/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/meg/sub-01_task-main_run-03_meg.json
/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/meg/sub-01_task-main_run-04_meg.json
/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/meg/sub-01_task-main_run-05_meg.json
/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/beh/sub-01_task-main_run-01_beh.json
/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/beh/sub-01_task-main_run-02_beh.json
/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/beh/sub-01_task-main_run-03_beh.json
/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/beh/sub-01_task-main_run-04_beh.json
/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/beh/sub-01_task-main_run-05_beh.json

The search_str was "/imaging/davis/Projects/SpeechMisperceptionMEEG/MNE-BIDS_data/sub-01/**/sub-01*.json"

This is a MEG dataset which I converted to BIDS format using mne-bids. The json files which appear to cause the trouble are sidecar files for the behavioural data I saved to the beh/ subfolder like so:

|MNE-BIDS_data/
|— README
|— dataset_description.json
|— participants.json
|— participants.tsv
|— sub-01/
|------ sub-01_scans.tsv
|------ beh/
|--------- sub-01_task-main_run-01_beh.json
|--------- sub-01_task-main_run-01_beh.tsv
|--------- sub-01_task-main_run-02_beh.json
|--------- sub-01_task-main_run-02_beh.tsv
|--------- sub-01_task-main_run-03_beh.json
|--------- sub-01_task-main_run-03_beh.tsv
|--------- sub-01_task-main_run-04_beh.json
|--------- sub-01_task-main_run-04_beh.tsv
|--------- sub-01_task-main_run-05_beh.json
|--------- sub-01_task-main_run-05_beh.tsv
|------ meg/

The _beh.tsv files contain a bunch of additional info about the trials (which I couldn’t fit in the meg events) plus responses and response times. The sidecar files describe the variables in the .tsv files as per the bids specification. I thought adding these json files should be ok, but I am not sure.

Am I doing something wrong at the bids conversion stage or could this be a bug in mne-bids-pipeline?

Many thanks,
Máté

System info:

Platform:         Linux-3.10.0-1160.el7.x86_64-x86_64-with-glibc2.17
Python:           3.10.9 | packaged by conda-forge | (main, Feb  2 2023, 20:20:04) [GCC 11.3.0]
Executable:       /home/ma09/.conda/envs/my_mne1.3/bin/python
CPU:              x86_64: 32 cores
Memory:           251.4 GB

mne:              1.3.0
numpy:            1.23.5 {OpenBLAS 0.3.21 with 32 threads}
scipy:            1.10.0
matplotlib:       3.6.3 {backend=module://matplotlib_inline.backend_inline}

sklearn:          1.2.1
numba:            0.56.4
nibabel:          5.0.1
nilearn:          0.10.0
dipy:             1.6.0
openmeeg:         2.5.5
cupy:             Not found
pandas:           1.5.3
pyvista:          0.38.2 {OpenGL could not be initialized}
pyvistaqt:        0.9.1
ipyvtklink:       0.2.2
vtk:              9.2.5
qtpy:             2.3.0 {None=None}
ipympl:           Not found
pyqtgraph:        0.13.1
pooch:            v1.6.0

mne_bids:         0.12
mne_nirs:         Not found
mne_features:     Not found
mne_qt_browser:   0.4.0
mne_connectivity: Not found
mne_icalabel:     Not found

Hello and thanks for reporting this issue! This is either a bug in MNE-BIDS or the pipeline itself.

Pinging @sappelhoff @agramfort and @larsoner as I won’t have time to look into this myself until next week!

Good luck,
Richard

This search string is too general. Could you share the code that leads to this error? Perhaps you underspecified a BIDSPath somewhere? :thinking:

@sappelhoff MNE-BIDS-Pipeline generated this, so it’s likely a bug there

Hi Both,

Thanks for the responses. @sappelhoff, indeed this error has been thrown by mne-bids-pipeline at the initial checks, specifically at the execution of _02_find_empty_room.py. For more info please see the detailed error output in my original post.

Just to add, after I removed the _beh.json files from the repository, the pipeline ran without a problem. It’s fine for me now, but it would be good to have these json files in the repository with the pipeline still running.

Best,
Máté

I’ve created BUG: Too many JSON files error · Issue #717 · mne-tools/mne-bids-pipeline · GitHub so we don’t forget to fix this bug. Bonus points if you want to give it a shot @allermat ! :slight_smile:

2 Likes

I’d be happy to give it a go! Do you guys have any guidelines for pull requests?

Yep!

https://mne.tools/stable/install/contributing.html#overview-of-contribution-process

1 Like

I did some digging and I think I’ve found a solution (but not necessarily the right one). See here: BUG: Too many JSON files error · Issue #717 · mne-tools/mne-bids-pipeline · GitHub

This issue has been fixed, see: fix: issue #717 fixed, updated get_input_fnames_find_empty_room() in … by allermat · Pull Request #743 · mne-tools/mne-bids-pipeline · GitHub