This example shows how to extract the epochs from the dataset of a given
subject and then classify them using Machine Learning techniques using
Riemannian Geometry. The code also creates a figure with the spectral embedding
of the epochs.

"""
# Authors: Pedro Rodrigues <*****@*****.**>
#
# License: BSD (3-clause)

import warnings
warnings.filterwarnings("ignore")

# define the dataset instance
dataset = AlphaWaves(
)  # use useMontagePosition = False with recent mne versions

# get the data from subject of interest
subject = dataset.subject_list[0]
raw = dataset._get_single_subject_data(subject)

# filter data and resample
fmin = 3
fmax = 40
raw.filter(fmin, fmax, verbose=False)
raw.resample(sfreq=128, verbose=False)

# detect the events and cut the signal into epochs
events = mne.find_events(raw=raw, shortest_event=1, verbose=False)
event_id = {'closed': 1, 'open': 2}
epochs = mne.Epochs(raw,
Riemannian Geometry. The code also creates a figure with the spectral embedding
of the epochs.

"""
# Authors: Pedro Rodrigues <*****@*****.**>
#
# License: BSD (3-clause)

import warnings
warnings.filterwarnings("ignore")

# define the dataset instance
direc = '../Data/AlpData/'
subject = 'subject_004.mat'
filepath = direc + subject
dataset = AlphaWaves()

# get the data from subject of interest
raw = dataset._get_single_subject_data(filepath)

# filter data and resample
fmin = 3
fmax = 40
raw.filter(fmin, fmax, verbose=False)
raw.resample(sfreq=128, verbose=False)

# detect the events and cut the signal into epochs
events = mne.find_events(raw=raw, shortest_event=1, verbose=False)
event_id = {'closed': 1, 'open': 2}
epochs = mne.Epochs(raw,
                    events,
"""
This module provides an interface between end-point API (api.py) and classification method.
It interprets the request and call the appropriate classification method. 
In addition, it creates also the dataset instances.
"""

dataset_2012 = BrainInvaders2012(Training=True)
dataset_2013 = BrainInvaders2013(NonAdaptive=True,
                                 Adaptive=False,
                                 Training=True,
                                 Online=False)
dataset_2014a = BrainInvaders2014a()
dataset_2014b = BrainInvaders2014b()
dataset_2015a = BrainInvaders2015a()
dataset_2015b = BrainInvaders2015b()
dataset_alpha = AlphaWaves(useMontagePosition=False)
dataset_vr = VirtualReality(useMontagePosition=False)
dataset_phmd = HeadMountedDisplay(useMontagePosition=False)


def run_request(str_request):
    store = Store()
    request_and_keywords = interpret(str_request)
    request = request_and_keywords['request']
    # Keywords are used to conduct independant requests on the store.
    # Such results will be returns along with the classification results.
    keywords = request_and_keywords["keywords"]
    result = {}
    if ('bi2012' in request):
        params = request['bi2012']
        score = classification.classify_2012(dataset_2012, params, store)