-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
ENH: Add initial BCI2000 .dat reader (preload-only) #13699
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
197649b
ENH: Add initial BCI2000 .dat reader (preload-only)
HansujaB 2c83c2a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 83d11de
Merge branch 'main' into add-bci2000-reader
HansujaB 20a89f5
MAINT: Address CI feedback (style and import fixes)
HansujaB 31bb511
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 21d9519
MAINT: Use explicit relative import for create_info
HansujaB fdca559
DOC: Add read_raw_bci2k to reading_raw_data autosummary
HansujaB 77dc37f
DOC: Fix numpydoc format for read_raw_bci2k
HansujaB d871e26
DOC/MAINT: Document read_raw_bci2k and fix numpydoc/sphinx warnings
HansujaB 090d208
DOC: Remove duplicate read_raw_bci2k from mne/io/tests/__init__.pyi
HansujaB 142967e
FIX: Improve BCI2000 header parsing for multi-field header line
HansujaB 37f00ff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6f4033f
TEST: use BCI2k test dataset from mne-testing-data in BCI2K reader tests
HansujaB bfc888d
Merge branch 'add-bci2000-reader' of https://github.com/HansujaB/mne-…
HansujaB 4073dff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] dc50c11
TEST : remove unused imports and variables in BCI2k reader test
HansujaB 1e3b777
Merge branch 'add-bci2000-reader' of https://github.com/HansujaB/mne-…
HansujaB 3c763ad
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 02c6d88
FIX: remove unused stim_data and _bci2k_states assignments
HansujaB 346ae38
ENH: add example for reading BCI2000 .dat files
HansujaB 8b1757e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3b16882
FIX: move nested function outside , add bci2k_data save path in examp…
HansujaB 5dff160
Merge branch 'main' into add-bci2000-reader
HansujaB ab5c597
[autofix.ci] apply automated fixes
autofix-ci[bot] c551e4d
DOC : add changelog entry
HansujaB 9c5dd22
FIX: Fixes
larsoner b7465c8
FIX: Exception
larsoner 63dfae1
FIX: More
larsoner 2da83bc
FIX: Better
larsoner 52c16bb
FIX: mark
larsoner 8baf714
Merge remote-tracking branch 'upstream/main' into add-bci2000-reader
larsoner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add support for reading BCI2000 ``.dat`` files via :func:`mne.io.read_raw_bci2k`, and an example :file:`examples/io/read_bci2k.py` for downloading and visualizing BCI2000 data, by :newcontrib:`Hansuja Budhiraja`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """ | ||
| ====================== | ||
| Reading BCI2000 files | ||
| ====================== | ||
|
|
||
| In this example, we use MNE-Python to read a BCI2000 ``.dat`` file. | ||
| BCI2000 is a general-purpose brain-computer interface (BCI) system widely | ||
| used in EEG research. The file is downloaded from the MNE testing data | ||
| repository using ``pooch``. | ||
| """ # noqa: D205 D400 | ||
|
|
||
| # Authors: The MNE-Python contributors. | ||
| # License: BSD-3-Clause | ||
| # Copyright the MNE-Python contributors. | ||
|
|
||
| import pooch | ||
|
|
||
| import mne | ||
|
|
||
| # %% | ||
| # First, we download the sample BCI2000 ``.dat`` file using ``pooch``. | ||
|
|
||
| data_dir = mne.datasets.default_path() / "bci2k_data" | ||
| data_dir.mkdir(exist_ok=True) | ||
|
|
||
| fname = pooch.retrieve( | ||
| url="https://raw.githubusercontent.com/mne-tools/mne-testing-data/master/BCI2k/bci2k_test.dat", | ||
| known_hash="sha256:8efc7b5f700660a044086cb1449806ca408c2e6d32d9338c32e1bf31ce3ca9cb", | ||
| path=data_dir, | ||
| ) | ||
|
|
||
| # %% | ||
| # Now we can read the file using :func:`mne.io.read_raw_bci2k`. | ||
| # Note that ``preload=True`` is required for BCI2000 files. | ||
|
|
||
| raw = mne.io.read_raw_bci2k(fname, preload=True) | ||
| print(raw.info) | ||
|
|
||
| # %% | ||
| # We can inspect the object representation, channel names, types, sampling | ||
| # frequency, and recording duration. | ||
|
|
||
| print(raw) | ||
| print(f"Channel names : {raw.ch_names}") | ||
| print(f"Channel types : {raw.get_channel_types()}") | ||
| print(f"Sampling freq : {raw.info['sfreq']} Hz") | ||
| print(f"Duration : {raw.times[-1]:.2f} s") | ||
| print(f"n_channels : {raw.info['nchan']}") | ||
| print(f"Data shape : {raw.get_data().shape} (n_channels, n_samples)") | ||
|
|
||
| # %% | ||
| # If the BCI2000 file contains a ``StimulusCode`` state, it is automatically | ||
| # mapped to a ``STI 014`` stim channel. We can extract events from it using | ||
| # :func:`mne.find_events`. | ||
|
|
||
| if "STI 014" in raw.ch_names: | ||
| events = mne.find_events(raw, shortest_event=1) | ||
| print(f"Found {len(events)} events") | ||
| print(mne.count_events(events)) | ||
| else: | ||
| print("No stim channel found in this file.") | ||
|
|
||
| # %% | ||
| # Finally, we can visualize the raw data. | ||
|
|
||
| raw.plot(duration=5, n_channels=len(raw.ch_names), scalings="auto") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Authors: The MNE-Python contributors. | ||
| # License: BSD-3-Clause | ||
| # Copyright the MNE-Python contributors. | ||
|
|
||
| from .bci2k import read_raw_bci2k, RawBCI2k |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should save to whatever this path is, plus maybe a new folder (if needed)
bci_dataor similar?https://mne.tools/stable/generated/mne.datasets.default_path.html#mne.datasets.default_path
So something like