ENH: Add initial BCI2000 .dat reader (preload-only)#13699
ENH: Add initial BCI2000 .dat reader (preload-only)#13699larsoner merged 31 commits intomne-tools:mainfrom
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
larsoner
left a comment
There was a problem hiding this comment.
I didn't look too deeply at the code, but looks like a reasonable start! With something like this we'd want to see it used somewhere, too -- is there a good file we could download using pooch in an example and use in an examples/io/something.py or similar? We could do something like what's done here
Also did you use AI tools in developing this code? If so please disclose the nature of AI tool usage
mne/io/bci2k/tests/test_bci2k.py
Outdated
| from mne.io.bci2k import RawBCI2k, read_raw_bci2k | ||
|
|
||
|
|
||
| def _write_demo_bci2k( |
There was a problem hiding this comment.
A more modern way to do this would be to
| def _write_demo_bci2k( | |
| @pytest.fixture | |
| def bci2k_path(tmp_path): | |
| fname = tmp_path / "something" | |
| ... | |
| return fname |
and then you use this inside your test
There was a problem hiding this comment.
@larsoner Thanks a lot for your review!
I searched for an example file but couldn't really find one, although I came across PhysioNet bigP3BCI dataset. The problem is , they converted .dat files to EDF + file header, so we can't use it !
What we can do is (use the same approach to generate a small example file) :
We can generate a small BCI2000 .dat file using a short P3Speller session with minimal channels and then host a trimmed version (a few seconds only) .
If this approach is acceptable I can work on it , Let me know!
Regarding AI usage , I looked upon the major stuff and algorithm development myself but for debugging and redundancy reduction, I took the help of AI tools to increase my efficiency!
There was a problem hiding this comment.
We can generate a small BCI2000 .dat file using a short P3Speller session with minimal channels and then host a trimmed version (a few seconds only) .
This would be great, then we could add it to mne-testing-data and use it here
There was a problem hiding this comment.
@larsoner Great! Should I open a separate PR to add the sample file to mne-testing-data, or can I include it in this PR?
There was a problem hiding this comment.
@HansujaB you can make a PR to https://github.com/mne-tools/mne-testing-data
Please make sure the new testing file is super small! Like < 1mb if possible. You can crop the data in the file to be only 1-second long if needed.
There was a problem hiding this comment.
@scott-huberty Thanks! I’ll generate a small trimmed .dat file and open a PR to mne-testing-data. It might take me a little while since I have exams this week, but I’ll try to get it up as soon as possible.
d50fc36 to
090d208
Compare
|
@larsoner @scott-huberty I have opened a PR for test file in mne-testing-data as discussed. While testing the dataset locally with the BCI2000 reader, I noticed a small parsing issue and have pushed a fix for that as well. Apologies for the delay! |
…python into add-bci2000-reader
for more information, see https://pre-commit.ci
…python into add-bci2000-reader
for more information, see https://pre-commit.ci
|
@larsoner Since the mne-testing-data PR has been merged, I have updated the test to use the dataset from there. Please let me know if anything else needs to be changed. |
|
Looks like the style CI is unhappy, can you look? Once that's passing I can approve the other workflows |
|
Also looks like the main comment from #13699 (review) hasn't been addressed |
|
Hi @larsoner, tests now use mne-testing-data , so the fixture suggestion no longer applies. Could you confirm if there's anything else from that thread that still needs addressing? Also pushed the style CI fixes. Thanks! |
Yeah, the comment I linked to had this:
I don't see any |
|
@larsoner I have added the example file! |
|
@larsoner Right now , we are failing 2 tests
Functions missing from read_raw: Should I remove it from |
|
These errors are likely because it needs to be added to the API reference like other reading functions: |
|
@larsoner Actually it is added to the API reference as well ! |
|
|
||
| fname = pooch.retrieve( | ||
| url="https://raw.githubusercontent.com/mne-tools/mne-testing-data/master/BCI2k/bci2k_test.dat", | ||
| known_hash="sha256:8efc7b5f700660a044086cb1449806ca408c2e6d32d9338c32e1bf31ce3ca9cb", |
There was a problem hiding this comment.
We should save to whatever this path is, plus maybe a new folder (if needed) bci_data or similar?
https://mne.tools/stable/generated/mne.datasets.default_path.html#mne.datasets.default_path
So something like
data_dir = mne.datasets.default_path() / "bci2k_data"
data_dir.mkdir(exist_ok=True)
...
mne/io/bci2k/bci2k.py
Outdated
| params = {} | ||
| state_defs = {} | ||
|
|
||
| def _parse_sampling_rate(val): |
There was a problem hiding this comment.
Can you move this outside the function? Nesting like this makes it hard to know which vars are from this function's scope and which are from the parent's
|
@larsoner I have pushed the changes , let me know if something needs to be modified. Thanks! |
@larsoner We are still facing these 2 issues :( |
|
I'll push a commit to fix the doc linking error and finish the steps from https://github.com/mne-tools/mne-testing-data?tab=readme-ov-file#add-or-change-files-in-the-repo-for-use-with-mne to update the version |
|
@larsoner Thanks a lot for the finishing touches! |
|
Thanks @HansujaB ! |
Reference issue (if any)
Fixes #13151
What does this implement/fix?
This PR adds basic support for reading BCI2000
.datfiles via:The implementation:
StimulusCodetoSTI 014stim channelRawobject usingRawArrayTests
Synthetic
.datgenerator included in testsVerifies:
StimulusCodedecodingpreload=FalseraisesScope (Intentional Limitations)
preload=Falseis not supported (raisesNotImplementedError)EEG1,EEG2, …)_get_supported()(since.datis already mapped to Curry)The goal is to provide a correct, minimal reader that can be safely extended in follow-up PRs.