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

Add bi2012 dependency #37

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
60d8dec
add bi2012 dataset and util function
gcattan Mar 20, 2022
326624c
typo
gcattan Mar 20, 2022
c1cab2e
add iterator over bi2012 dataset
gcattan Mar 20, 2022
4b99ad6
update documentation
gcattan Mar 20, 2022
5a3c767
remove mne dependency
gcattan Mar 20, 2022
8450f34
add same mne reference as in bi2012
gcattan Mar 20, 2022
0a0e20b
update conf.py
gcattan Mar 20, 2022
96251c9
workaround for datapath
gcattan Mar 20, 2022
e223a51
restart pipeline
gcattan Mar 20, 2022
58e9743
update workaround
gcattan Mar 21, 2022
5cb678e
missing
gcattan Mar 21, 2022
a39d982
try update_path
gcattan Mar 21, 2022
e490774
missing
gcattan Mar 21, 2022
d594a1a
remove update_path
gcattan Mar 21, 2022
48bd549
remove mne version
gcattan Mar 21, 2022
02c3114
try mne 0.20.1
gcattan Mar 21, 2022
c73df2e
revert modif to utils.py related to data_path
gcattan Mar 21, 2022
e75bf18
make bi2012 a required dependency
gcattan Mar 21, 2022
75945c2
lower mne version
gcattan Mar 21, 2022
a863b8d
invalid syntax fixed
gcattan Mar 21, 2022
0e80456
update index.rst
gcattan Mar 21, 2022
c786f54
Update doc/requirements.txt
gcattan Mar 24, 2022
1aa8cd9
remove skeleton for bi2012_quantum_classify
gcattan Mar 24, 2022
256ed31
Update pyriemann_qiskit/datasets/utils.py
gcattan Mar 24, 2022
941fba5
Merge branch 'gc/bi2012_dependency' of https://github.com/gcattan/pyR…
gcattan Mar 24, 2022
a388976
refactor helper in utils.
gcattan Mar 24, 2022
9dd179f
update setup.py
gcattan Mar 24, 2022
aa8609e
Update pyriemann_qiskit/datasets/utils.py
gcattan Mar 25, 2022
97cc996
Update pyriemann_qiskit/datasets/utils.py
gcattan Mar 25, 2022
4ffd1a2
Update pyriemann_qiskit/datasets/utils.py
gcattan Mar 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ Datasets
get_mne_sample
get_linearly_separable_dataset
get_qiskit_dataset
get_bi2012_dataset

3 changes: 2 additions & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sphinx-gallery
sphinx-bootstrap_theme
numpydoc
cython
mne[data]>=0.24
mne==0.20.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a good idea to freeze the MNE version, it should really be avoided. Is this because of bi2012 dependency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately yes. It is using _fetch_file which doesn t seem available in recent versions of mne:

image

I have just opened an issue in bi2012, so we can keep trace of it.

seaborn
scikit-learn
joblib
Expand All @@ -11,3 +11,4 @@ cvxpy==1.1.12
qiskit==0.20.0
scipy==1.7.3
git+https://github.com/pyRiemann/pyRiemann#egg=pyriemann
braininvaders2012>=0.1
6 changes: 4 additions & 2 deletions pyriemann_qiskit/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from .utils import (get_mne_sample,
get_linearly_separable_dataset,
get_qiskit_dataset)
get_qiskit_dataset,
get_bi2012_dataset)


__all__ = ["get_mne_sample",
"get_linearly_separable_dataset",
"get_qiskit_dataset"]
"get_qiskit_dataset",
"get_bi2012_dataset"]
96 changes: 95 additions & 1 deletion pyriemann_qiskit/datasets/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import numpy as np
from mne import io, read_events, pick_types, Epochs
from mne import io, read_events, pick_types, Epochs, find_events
from mne.datasets import sample
from qiskit.ml.datasets import ad_hoc_data
from sklearn.datasets import make_classification
from sklearn.preprocessing import LabelEncoder
from braininvaders2012.dataset import BrainInvaders2012


def get_mne_sample(n_trials=10):
Expand Down Expand Up @@ -39,6 +41,7 @@ def get_mne_sample(n_trials=10):
https://mne.tools/stable/overview/datasets_index.html

"""

data_path = sample.data_path()

# Set parameters and read data
Expand Down Expand Up @@ -123,3 +126,94 @@ def get_linearly_separable_dataset():
X += 2 * rng.uniform(size=X.shape)

return(X, y)


def get_bi2012_dataset(training=True,
fmin=1, fmax=24, sampling=128, tmin=0.1, tmax=0.7,
baseline=None, verbose=False):
"""Return sample data from the brain invaders 2012 dataset.

Return an iterator over the brain invaders 2012 dataset [1]_.
Each call to the _next_ method return the epochs `X` and the predicted
target vector `y` relative to `X` for a subject in the dataset.

The dataset contains the EEG recording of 26 participants playing a BCI
version of the vintage game Brain Invaders, based on the
oddball paradigm (P300).
Each subject participated in a Training and Online session of the game.

A detailed description of the dataset can be found in [2]_.

Parameters
----------
training : bool (default:True)
If true will only download and analyze data related
to the training session.
fmin : int (default:1)
Minimum frequence (Hz) for passband filtering (data preprocessing).
fmax : int (default:24)
Maximum frequence (Hz) for passband filtering (data preprocessing).
sampling : int (default:128)
Data were initially sampled at 128Hz. You can resample the data using
this parameter.
tmin : int (default:0.1)
Start time before event.
tmax : int (default:0.7)
Stop time before event.
baseline : None | tuple[2] (default:None)
The time interval to apply baseline correction [3]_.
verbose : bool (default:False)
Print all traces if true.

Returns
-------
dataset: Iterator
An iterator over the brain invaders 2012 dataset.

References
----------
.. [1] Available from: \
https://github.com/plcrodrigues/py.BI.EEG.2012-GIPSA
.. [2] G. F. P. Van Veen et al. \
‘Building Brain Invaders: EEG data of an experimental validation’
(mai 2019). Available at: \
https://hal.archives-ouvertes.fr/hal-02126068
.. [3] https://mne.tools/0.20/generated/mne.Epochs.html

"""

dataset = BrainInvaders2012(Training=training, Online=not training)
subjects = dataset.subject_list

class Iterator():
def _iter_(self):
self.index = 0

def _next_(self):
if self.index == len(subjects - 1):
raise StopIteration

subject = subjects[self.index]
self.index += 1
data = dataset._get_single_subject_data(subject)
run = "run_" + ("training" if training else "online")
raw = data['session_1'][run]

# filter data and resample
raw.filter(fmin, fmax, verbose=verbose)
raw.resample(sampling)

# detect the events and cut the signal into epochs
events = find_events(raw=raw, shortest_event=1, verbose=verbose)
event_id = {'NonTarget': 1, 'Target': 2}
epochs = Epochs(raw, events, event_id, tmin, tmax,
baseline=baseline, verbose=verbose, preload=True)
epochs.pick_types(eeg=True)

# get trials and labels
X = epochs.get_data()
y = events[:, -1]
y = LabelEncoder().fit_transform(y)
return (X, y)

return Iterator()
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
'scipy==1.5.4; python_version < "3.7.0"',
'scipy==1.7.3; python_version >= "3.7.0"',
'docplex',
'braininvaders2012>=0.1',
'mne==0.20.1',
'tqdm'
],
extras_require={'docs': ['sphinx-gallery', 'sphinx-bootstrap_theme', 'numpydoc', 'mne', 'seaborn'],
'tests': ['pytest', 'seaborn', 'flake8', 'mne', 'pooch', 'tqdm']},
extras_require={'docs': ['sphinx-gallery', 'sphinx-bootstrap_theme', 'numpydoc', 'seaborn'],
'tests': ['pytest', 'seaborn', 'flake8', 'pooch', 'tqdm']},
zip_safe=False,
)