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] Datatype handling when in write_raw_bids #774
Conversation
The user must now specify the datatype when calling write_raw_bids. Not automatic datatype inferring is done anymore in write_raw_bids. However, it is checked if the specified datatype is present in the dataset.
…e-bids into write_EEG_iEEG
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a few suggestions.
thx @richardkoehler
mne_bids/utils.py
Outdated
if 'eeg' in raw: | ||
datatypes.append('eeg') | ||
if len(datatypes) == 0: | ||
raise ValueError('No MEG, EEG or iEEG channels found in data.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise ValueError('No MEG, EEG or iEEG channels found in data.' | |
raise ValueError('No MEG, EEG or iEEG channels found in data. ' |
mne_bids/utils.py
Outdated
if datatype in raw: | ||
datatype_matches = True | ||
elif datatype == 'meg': | ||
if datatype not in raw: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
mne_bids/write.py
Outdated
if bids_path.datatype is None: | ||
datatype = _handle_datatype(raw) | ||
else: | ||
datatype = bids_path.datatype | ||
_check_datatype(raw, datatype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do this in the _handle_datatype function
datatype = _handle_datatype(raw, bids_path.datatype)
then you call _check_datatype in _handle_datatype and your return directly the 2nd parameter if valid.
Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
@agramfort Thanks for the helpful suggestions! Tests are currently failing because write_raw_bids() now makes no more automatic assumptions about the datatype if there are multiple ephys data types (meg, eeg or ieeg) in our Raw object and because it actually checks if the bids_path.datatype is present in the Raw object. I can start fixing the tests, but as I already wrote in #752, I think the current PR might "break" write_raw_bids() for a lot of existing code out there (as demonstrated by the failing tests). So I think we need to make sure that everyone agrees with the new behavior of write_raw_bids:
Alternatively, we could "trust" the user to know what he is doing, and simply issue a warning message for case 2. There might be some cases where a user might want to write the data without specifying the channel types, even though I can't currently think of any. Is it really the job of MNE-BIDS to enforce these kind of things? |
I would say that if you have no datatype and the data contains MEG and EEG
then you should
infer automatically it's an meg data.
would this already avoid breaking many tests?
|
@agramfort Yes, this actually fixed many of the tests. I implemented this way of handling datatype=None and fixed the remaining failing tests. In the case of datatype='eeg' with additional 'meg' channels in the data we are now trusting the user to know what he is doing, and NOT enforcing the datatype 'meg'. Therefore, the user can decide to write out combined MEG-EEG recordings in an EEG data format. |
@agramfort Actually, it won't be possible as I get the following Error:
So apparently it doesn't make any sense to save MEG-EEG data as EEG data because brainvision doesn't support MEG units. Sorry, I'm not very familiar with MEG, I wasn't aware of this. |
mne_bids/tests/test_utils.py
Outdated
datatype = None | ||
with pytest.raises(ValueError, match=f'The specified datatype {datatype} ' | ||
'is currently not supported.'): | ||
_check_datatype(raw_eeg, datatype) | ||
datatype = 'anat' | ||
with pytest.raises(ValueError, match=f'The specified datatype {datatype} ' | ||
'is currently not supported.'): | ||
_check_datatype(raw_eeg, datatype) | ||
datatype = 'eeg' | ||
_check_datatype(raw_eeg, datatype) | ||
with pytest.raises(ValueError, match=f'The specified datatype {datatype} ' | ||
'was not found in the raw object.'): | ||
_check_datatype(raw_meg, datatype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
datatype = None | |
with pytest.raises(ValueError, match=f'The specified datatype {datatype} ' | |
'is currently not supported.'): | |
_check_datatype(raw_eeg, datatype) | |
datatype = 'anat' | |
with pytest.raises(ValueError, match=f'The specified datatype {datatype} ' | |
'is currently not supported.'): | |
_check_datatype(raw_eeg, datatype) | |
datatype = 'eeg' | |
_check_datatype(raw_eeg, datatype) | |
with pytest.raises(ValueError, match=f'The specified datatype {datatype} ' | |
'was not found in the raw object.'): | |
_check_datatype(raw_meg, datatype) | |
for datatype, raw in [(None, raw_eeg, ('eeg', raw_meg), ('anat', raw_eeg)]: | |
with pytest.raises(ValueError, match=f'The specified datatype {datatype} ' | |
'is currently not supported.'): | |
_check_datatype(raw, datatype) |
can you compress with something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did, hope it is fine the way I have solved it now :)
Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
Codecov Report
@@ Coverage Diff @@
## main #774 +/- ##
==========================================
+ Coverage 94.01% 94.07% +0.06%
==========================================
Files 23 23
Lines 2822 2851 +29
==========================================
+ Hits 2653 2682 +29
Misses 169 169
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx @richardkoehler !
thx a lot @richardkoehler ! |
@agramfort Thanks for the merge, happy to contribute :) Stupid question because this is my first contribute to mne-bids: The Merge checklist at the top is not for myself to complete right? Because it says "This is not your own PR". I haven't updated whats_new.rst or anything, but of course I would be happy to do so, if required |
it's for you to fill to help us review but here I looked myself.
thx again
… |
Thanks @richardkoehler! |
Oh noes, we forgot to add a changelog entry!! @richardkoehler care to add one? |
@hoechenberger Yes, I did so in #779 as I couldn't reopen this PR. |
PR Description
closes #752
The user must now specify the datatype when calling write_raw_bids. Not automatic datatype inferring is done anymore in write_raw_bids. However, it is checked if the specified datatype is present in the dataset.
Merge checklist
Maintainer, please confirm the following before merging: