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

write_raw_bids() accepts (and silently ignores / alters) unsuitable extension #1041

Open
hoechenberger opened this issue Aug 6, 2022 · 10 comments
Assignees
Labels
Milestone

Comments

@hoechenberger
Copy link
Member

hoechenberger commented Aug 6, 2022

When trying to write EEG data to a FIFF file, write_raw_bids() happily accepts a respective BIDSPath, but actually writes the data to a BV file.

It should at least warn, or even better, raise an exception.

MWE:

# %%
from pathlib import Path
import mne
import mne_bids

# Load dat
ssvep_folder = mne.datasets.ssvep.data_path()
ssvep_data_raw_path = (ssvep_folder / 'sub-02' / 'ses-01' / 'eeg' /
                       'sub-02_ses-01_task-ssvep_eeg.vhdr')
ssvep_raw = mne.io.read_raw_brainvision(ssvep_data_raw_path, verbose=False)


# Create a BIDS dataset
root = Path('/tmp/bids-test')
bp = mne_bids.BIDSPath(
    subject='02',
    session='01',
    task='ssvep',
    suffix='meg',
    extension='.fif',
    datatype='eeg',
    root=root
)
bp_written = mne_bids.write_raw_bids(
    raw=ssvep_raw,
    bids_path=bp,
    overwrite=True,
)
print(repr(bp_written))

produces:

BIDSPath(
root: /tmp/bids-test
datatype: eeg
basename: sub-02_ses-01_task-ssvep_eeg.vhdr)
@sappelhoff sappelhoff added the bug label Aug 6, 2022
@sappelhoff
Copy link
Member

agreed, this looks like a bug to me. I think it should "autoconvert" to FIF ... or raise an exception demanding format to be explicitly set to FIF.

@sappelhoff sappelhoff added this to the 0.11 milestone Aug 6, 2022
@agramfort
Copy link
Member

agramfort commented Aug 6, 2022 via email

@hoechenberger
Copy link
Member Author

hoechenberger commented Aug 6, 2022

I maybe didn't explain it well.

The input I have is FIFF.

The data type is eeg.

BIDS mandates that EEG data be stored in BrainVision format; FIFF is not allowed.

MNE-BIDS silently converts my data from FIFF to BV, even though the target BIDSPath I supply explicitly states an extension of .fif

So in my perception, MNE-BIDS simply overrules what I explicitly asked it to do (write the data to FIFF), in order to conform to BIDS.

Instead, it should raise an exception, stating that EEG data cannot be written to FIFF as it violates the standard.

@agramfort
Copy link
Member

agramfort commented Aug 6, 2022 via email

@hoechenberger
Copy link
Member Author

hoechenberger commented Aug 6, 2022

Yes I totally agree, and I would say we should amend the BIDS standard to allow for FIFF for EEG data as well. But it's currently not the case.

As for derivatives, that further complicates things, yes!!

But currently it is how it is: BIDS doesn't allow FIFF for EEG, at least not for raw data. Unless I'm missing something in the spec -- @sappelhoff?

@sappelhoff
Copy link
Member

Original data is in FIF and I don't see why
derivatives eg filtered raw data after picking the EEG
channels shouldn't stay in FIF. Does it make sense?

agreed. And I think this is in line with the spec --> EEG data that was recorded together with MEG data can be stored under an MEG datatype.

If you want to completely rip out the EEG data from the MEG format and only deal with EEG, then I think it's fair to require that you use BIDS conventions for EEG and convert your data and then continue.

@agramfort
Copy link
Member

agramfort commented Aug 7, 2022 via email

@hoechenberger hoechenberger self-assigned this Aug 19, 2022
hoechenberger added a commit to hoechenberger/mne-bids that referenced this issue Aug 19, 2022
… the BIDSPath

Some extensions / formats are only allowed for certain data types, e.g.
.vhdr is (i)EEG-only.

When passing a BIDSPath containing both datatype and extension
to write_raw_bids(), in case of a mismatch we would previously simply
silently replace the incorrect extension, effectively writing to a
location (and file format) the user didn't expect.

We now raise an exception in such situations.

Fixes mne-tools#1041
@hoechenberger
Copy link
Member Author

hoechenberger commented Aug 19, 2022

I've been trying to address this in #1053 but I ran into an issue:

It appears the format kwarg controls the output format. But this then gets confusing as the user can also specify a filename extension in the provided BIDSPath. In this case, write_raw_bids() will, by default (format='auto') simply replace any provided extension by the one it sees fit for the data format to be written. I think this is very confusing behavior.

My proposal would be to get rid of the format parameter of write_raw_bids() altogether and only rely on the provided extension of the BIDSPath.

@agramfort
Copy link
Member

agramfort commented Aug 19, 2022 via email

@hoechenberger
Copy link
Member Author

Maybe that would be a good idea. Currently it infers the format based in the data, for example if there are MEG channels it will pick meg

@hoechenberger hoechenberger modified the milestones: 0.11, 0.12 Oct 6, 2022
@sappelhoff sappelhoff modified the milestones: 0.12, 0.13 Dec 18, 2022
@sappelhoff sappelhoff modified the milestones: 0.13, 0.14 Jul 27, 2023
@sappelhoff sappelhoff modified the milestones: 0.14, 0.15 Dec 9, 2023
@sappelhoff sappelhoff modified the milestones: 0.15, 0.16 May 19, 2024
@sappelhoff sappelhoff modified the milestones: 0.16, 0.17 Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants