Ejemplo n.º 1
0
def raw_clean(montage):
    """Return an `mne.io.Raw` object with no bad channels for use with tests.

    This fixture downloads and reads in subject 30, run 2 from the Physionet
    BCI2000 (eegbci) open dataset, which contains no bad channels on an initial
    pass of :class:`pyprep.NoisyChannels`. Intended for use with tests where
    channels are made artificially bad.

    File attributes:
    - Channels: 64 EEG
    - Sample rate: 160 Hz
    - Duration: 61 seconds

    This is only run once per session to save time downloading.

    """
    mne.set_log_level("WARNING")

    # Download and read S030R02.edf from the BCI2000 dataset
    edf_fpath = eegbci.load_data(30, 2, update_path=True)[0]
    raw = mne.io.read_raw_edf(edf_fpath, preload=True)
    eegbci.standardize(raw)  # Fix non-standard channel names

    # Set a montage for use with RANSAC
    raw.set_montage(montage)

    return raw
Ejemplo n.º 2
0
def get_eeg_data(subject, runs, event_id):
    tmin, tmax = -1.0, 4.0

    # Get and prepare the raw data
    raw_fnames = eegbci.load_data(subject, runs)
    raw = concatenate_raws([read_raw_edf(f, preload=True) for f in raw_fnames])
    eegbci.standardize(raw)
    montage = make_standard_montage('standard_1005')
    raw.set_montage(montage)
    raw.rename_channels(lambda x: x.strip('.'))
    raw.filter(7.0, 30.0, fir_design='firwin', skip_by_annotation='edge')

    events, _ = events_from_annotations(raw, event_id=event_id)

    picks = pick_types(raw.info, meg=False, eeg=True, stim=False, eog=False,
                exclude='bads')

    epochs = Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks,
                baseline=None, preload=True)

    labels = epochs.events[:, -1]

    epochs_data = epochs.get_data()

    return raw.info['sfreq'], epochs_data, labels
Ejemplo n.º 3
0
def loadthings(subject):
    runs = [6, 10, 14]
    raw_fnames = eegbci.load_data(subject, runs)
    raw = concatenate_raws([read_raw_edf(f, preload=True) for f in raw_fnames])

    raw_fnames = eegbci.load_data(subject, runs)
    raw = concatenate_raws([read_raw_edf(f, preload=True) for f in raw_fnames])
    eegbci.standardize(raw)
    #create 10-05 system
    montage = make_standard_montage('standard_1005')
    raw.set_montage(montage)
    raw.filter(7, 13)
    events, _ = events_from_annotations(raw, event_id=dict(T1=0, T2=1))
    #0: left, 1:right
    picks = pick_types(raw.info,
                       meg=False,
                       eeg=True,
                       stim=False,
                       eog=False,
                       exclude='bads')

    tmin, tmax = -1, 4
    epochs = Epochs(raw,
                    events,
                    None,
                    tmin,
                    tmax,
                    proj=True,
                    picks=picks,
                    baseline=None,
                    preload=True)
    #epochs_train=epochs.copy().crop(0,2)
    epochs_train = epochs.copy().crop(0, 2)
    labels = epochs.events[:, -1]

    # %%
    epochs_train_data = epochs_train.get_data()
    labels = epochs_train.events[:, -1]

    ad = np.array(epochs_train_data)
    All_Data = ad.reshape(
        64, epochs_train_data.shape[2] * epochs_train_data.shape[0])

    labels = labels.reshape(45, 1)

    extended = []
    for i in range(321):
        extended.append(labels)
    extended = np.array(extended)
    extended = extended.reshape(45, 321)
    extended = extended.T
    Labels = extended
    #np.savetxt("pythondata/extended.csv", extended)

    row, column = Labels.shape
    Labels = Labels.reshape(1, row * column)
    Labels = Labels.T

    return All_Data, Labels
def eeg_settings ():
    
    raw_setted = []
    
    for subj in range (len(subjects)):
        
        print(raw_conc_list[subj])  #control data
        eegbci.standardize(raw_conc_list[subj]) #Cambio i nomi dei canali
        montage = make_standard_montage('standard_1005') #Caricare il montaggio
        raw_conc_list[subj].set_montage(montage) #Setto il montaggio
        raw_setted.append(raw_conc_list[subj])
    
    return raw_setted
Ejemplo n.º 5
0
def raw():
    """Fixture for physionet EEG subject 4, dataset 1."""
    mne.set_log_level("WARNING")
    # load in subject 1, run 1 dataset
    edf_fpath = eegbci.load_data(4, 1, update_path=True)[0]

    # using sample EEG data (https://physionet.org/content/eegmmidb/1.0.0/)
    raw = mne.io.read_raw_edf(edf_fpath, preload=True)

    # The eegbci data has non-standard channel names. We need to rename them:
    eegbci.standardize(raw)

    return raw
Ejemplo n.º 6
0
def get_classification_dataset(subject=1, typeInt=4):
    #TypeInt:
    #Task 1 (open and close left or right fist)
    #Task 2 (imagine opening and closing left or right fist)
    #Task 3 (open and close both fists or both feet)
    #Task 4 (imagine opening and closing both fists or both feet)
    assert (typeInt >= 1)
    assert (typeInt <= 4)
    from mne.io import concatenate_raws, read_raw_edf
    from mne.datasets import eegbci
    tmin, tmax = -1., 4.
    runs = [3, 7, 11]
    runs = [r + typeInt - 1 for r in runs]
    print("loading subject {} with runs {}".format(subject, runs))
    if typeInt <= 1:
        event_id = dict(left=2, right=3)
    else:
        event_id = dict(hands=2, feet=3)

    raw_fnames = eegbci.load_data(subject, runs)
    raws = [read_raw_edf(f, preload=True) for f in raw_fnames]
    raw = concatenate_raws(raws)

    raw.filter(7., 30., fir_design='firwin', skip_by_annotation='edge')

    eegbci.standardize(raw)  # set channel names
    montage = mne.channels.make_standard_montage('standard_1005')
    raw.set_montage(montage)
    raw.rename_channels(lambda x: x.strip('.'))
    events, _ = mne.events_from_annotations(raw, event_id=dict(T1=2, T2=3))

    picks = mne.pick_types(raw.info,
                           meg=False,
                           eeg=True,
                           stim=False,
                           eog=False,
                           exclude='bads')

    # Read epochs (train will be done only between 1 and 2s)
    # Testing will be done with a running classifier
    epochs = mne.Epochs(raw,
                        events,
                        event_id,
                        tmin,
                        tmax,
                        proj=True,
                        picks=picks,
                        baseline=None,
                        preload=True)
    return (epochs)
Ejemplo n.º 7
0
    def preprocess(self):
        if not self._raws:
            raise RuntimeError('File not Loaded.')

        for raw in self._raws:
            eegbci.standardize(raw)  # set channel names
            # strip channel names of "." characters
        self._raws = channel_repair_exclud(self._raws,
                                           exclude='bads',
                                           montage='standard_1005')
        self._raws = band_pass_filter(self._raws, self.filter_low,
                                      self.filter_high)
        if self.remove_eog:
            self._raws = self._remove_eog(self._raws)
Ejemplo n.º 8
0
    def eeg_settings(raws):
        """
        Standardize montage of the raws
        :param raws: list of raws
        :return: list of standardize raws
        """
        raw_setted = []
        for subj in raws:
            eegbci.standardize(subj)  # Cambio i nomi dei canali
            montage = make_standard_montage(
                'standard_1005')  # Caricare il montaggio
            subj.set_montage(montage)  # Setto il montaggio
            raw_setted.append(subj)

        return raw_setted
Ejemplo n.º 9
0
def raw():
    """Return an `mne.io.Raw` object for use with unit tests.

    This fixture downloads and reads in subject 4, run 1 from the Physionet
    BCI2000 (eegbci) open dataset. This recording is quite noisy and is thus a
    good candidate for testing the PREP pipeline.

    File attributes:
    - Channels: 64 EEG
    - Sample rate: 160 Hz
    - Duration: 61 seconds

    This is only run once per session to save time downloading.

    """
    mne.set_log_level("WARNING")

    # Download and read S004R01.edf from the BCI2000 dataset
    edf_fpath = eegbci.load_data(4, 1, update_path=True)[0]
    raw = mne.io.read_raw_edf(edf_fpath, preload=True)
    eegbci.standardize(raw)  # Fix non-standard channel names

    return raw
Ejemplo n.º 10
0




#
#
######## Authors: Martin Billinger <*****@*****.**> ########
tmin, tmax = -1, 4
event_id = dict(hands=2, feet=3)
subject = 1
runs = [6, 10, 14]  # motor imagery: hands vs feet

raw_fnames = eegbci.load_data(subject, runs)
raw = concatenate_raws([read_raw_edf(f, preload=True) for f in raw_fnames])
eegbci.standardize(raw)  # set channel names
montage = make_standard_montage('standard_1005')
raw.set_montage(montage)

# strip channel names of "." characters
raw.rename_channels(lambda x: x.strip('.'))

# Apply band-pass filter

raw.filter(7., 30., fir_design='firwin', skip_by_annotation='edge')

events, _ = events_from_annotations(raw, event_id=dict(T1=2, T2=3))

picks = pick_types(raw.info, meg=False, eeg=True, stim=False, eog=False,
                   exclude='bads')
Ejemplo n.º 11
0
eegbci.load_data(106, runs=runs)



for subj in subjects:
    ls_run = [] #Lista dove inseriamo le run
    for run in runs:
        fname = eegbci.load_data(subj, runs=run)[0] #Prendo le run
        raw_run = read_raw_edf(fname, preload=True) #Le carico
        len_run = np.sum((raw_run._annotations).duration) #Controllo la durata
        if len_run > 123:
            raw_run.crop(tmax=124.4) #Taglio la parte finale
        ls_run.append(raw_run) #Aggiungo la run alla lista delle run
    raw = concatenate_raws(ls_run)
    eegbci.standardize(raw) #Cambio i nomi dei canali
    montage = make_standard_montage('standard_1005') #Caricare il montaggio
    raw.set_montage(montage) #Setto il montaggio
    raw.filter(1.0, 79.0, fir_design='firwin', skip_by_annotation='edge') #Filtro
    raw_notch = raw.notch_filter(freqs=60) #Faccio un filtro passa banda
    raw.plot_psd(area_mode=None, show=False, average=False, fmin =1.0, fmax=80.0, dB=False, n_fft=160)
    # todo: qui salvare il plot psd
    # Ica
    ica = ICA(n_components=64, random_state=42, method="fastica", max_iter=1000)

    ind = []
    for index, value in enumerate((raw.annotations).description):
        if value == "BAD boundary" or value == "EDGE boundary":
            ind.append(index)
    (raw.annotations).delete(ind)
Ejemplo n.º 12
0
from mne import Epochs, pick_types, events_from_annotations
from mne.io import concatenate_raws, read_raw_edf
from mne.channels import make_standard_montage
from mne.preprocessing import ICA

#%% CARICO IL DATABASE
tmin, tmax = -1., 4.
event_id = dict(hands=2, feet=3)
subject = 1
runs = [2]
#Scarico i dati e mi ritorna il path locale
raw_fnames = eegbci.load_data(subject, runs)
#Concateno le path e le metto in un unico file
raw = concatenate_raws([read_raw_edf(f, preload=True) for f in raw_fnames])
#Standardizzo la posizione degli elettrodi
eegbci.standardize(raw)
#Seleziono il montaggio
montage = make_standard_montage('standard_1005')
#Lo setto all'interno di raw
raw.set_montage(montage)
#Tolgo il punto alla fine
raw.rename_channels(lambda x: x.strip('.'))
raw.crop(tmax=60).load_data()
#%% VISUALIZZO I DATI RAW
ax = plt.axes()
raw.plot_psd(area_mode=None,
             show=False,
             average=False,
             ax=plt.axes(ylim=(0, 60)),
             fmin=1.0,
             fmax=80.0,