예제 #1
0
파일: main.py 프로젝트: catavei/Proiect3
def create_initial_EEGs(raw_input):
    data_in = raw_input[1:, 1:30]

    tables_array = np.split(data_in, NO_OF_EEGS)

    EEGs = []

    for table in tables_array:

        subject = str(table[0, 0])
        class_nr = int(table[0, 2])
        class_label = str(table[0, 3])
        channels = []

        for i in range(NO_OF_CHANNELS):

            channel_label = str(table[i, 5])
            MFCCs = table[i, 11:]
            MFCC_list = []

            for j in range(NO_OF_MFCCS):
                MFCC_list.append(float(MFCCs[j]))

            channel = Channel(i, channel_label, MFCC_list)
            channels.append(channel)

        EEGs.append(EEG(subject, class_nr, class_label, channels))

    return EEGs
예제 #2
0
def trials(trial_name=''):
    error_master = []
    no_error_master = []
    trial_dicts = {
        'Offline': offline_dict,
        'S2': S2_dict,
        'S3': S3_dict,
    }
    # Create or load the data
    if not (os.path.exists(f'{trial_name}_error.npy') and os.path.exists(f'{trial_name}_no_error.npy')):
        trial = trial_dicts[trial_name]
        for subject in trial.keys():
            runs = trial[subject]
            #                count = 0
            for run in runs:
                path = os.path.join(root, subject, trial_name, run)
                e = EEG()
                (eeg, trig, mat) = e.open(
                    path,
                    channel_names=channel_names_spellers
                )

                #theta = e.getTheta()
                theta = e.getRawEEG(channels=channels_of_interest)[0]
                theta = e.CARFilter(theta)

                powerFeature = PowerFeature()
                theta, grand_avg, gran_var = powerFeature.extract(theta,
                                            window=32,
                                            overlap=16
                                            )
                # theta = np.expand_dims(theta, axis=1)
                error = e.splitNDArray(theta, 0, 1, True, fs=512, downsample=16)
                no_error = e.splitNDArray(theta, 0, 1, False, fs=512, downsample=16)


                if error_master == []:
                    error_master = error
                    no_error_master = no_error
                else:
                    error_master = np.append(error_master, error, axis=0)
                    no_error_master = np.append(no_error_master, no_error, axis=0)

        np.save(f'{trial_name}_error', error_master)
        np.save(f'{trial_name}_no_error', no_error_master)

    else:
        error_master = np.load(f'{trial_name}_error.npy')
        no_error_master = np.load(f'{trial_name}_no_error.npy')

    #error_master = error_master[..., 1:]
    error_master = np.swapaxes(error_master, 1, 2)

    #no_error_master = no_error_master[..., 1:]
    no_error_master = np.swapaxes(no_error_master, 1, 2)

    error_master *= 10e6  # zscore(error_master)
    no_error_master *= 10e6  # zscore(no_error_master)

    return error_master, no_error_master
예제 #3
0
파일: Client.py 프로젝트: MoonRiyadh/CoCoRo
 def __init__(self, amt_trials):
     print(self.SHAPE)
     self.robot = Robot.Robot.eeg_side_quickstart(self.URI)
     self.distr = Distributor()
     self.eeg = EEG.EEG(self.PATH)
     self.net = Net.Net(self.SHAPE)
     self.labels = []
     self.datalist = []
     self.eventlist = []
     self.amt_trials = amt_trials  # Amount of trials
예제 #4
0
def trials(trial_name=''):
    error_master = []
    no_error_master = []
    trial_dicts = {
        'Offline': offline_dict,
    }
    # Create or load the data
    if not (os.path.exists(f'{trial_name}_error.npy')
            and os.path.exists(f'{trial_name}_no_error.npy')):
        trial = trial_dicts[trial_name]
        for subject in trial.keys():
            runs = trial[subject]
            #                count = 0
            for run in runs:
                path = os.path.join(root, subject, trial_name, run)
                e = EEG()
                (eeg, trig, mat) = e.open(path,
                                          channel_names=channel_names_spellers)

                theta = e.getRawEEG(channels=channels_of_interest)[0]
                theta = e.CARFilter(theta)

                stftfeature = STFTFeature()
                stft, freq, time = stftfeature.extract(theta,
                                                       window=512,
                                                       overlap=496,
                                                       pre_trigger_time=0,
                                                       fs=512,
                                                       frequency_range=[3, 9])

                error = e.splitNDArray(stft,
                                       0,
                                       1,
                                       True,
                                       fs=512,
                                       downsample=(512 - 496))
                no_error = e.splitNDArray(stft,
                                          0,
                                          1,
                                          False,
                                          fs=512,
                                          downsample=(512 - 496))

                if error_master == []:
                    error_master = error
                    no_error_master = no_error
                else:
                    error_master = np.append(error_master, error, axis=0)
                    no_error_master = np.append(no_error_master,
                                                no_error,
                                                axis=0)

        np.save(f'{trial_name}_error', error_master)
        np.save(f'{trial_name}_no_error', no_error_master)

    else:
        error_master = np.load(f'{trial_name}_error.npy')
        no_error_master = np.load(f'{trial_name}_no_error.npy')

    error_master = np.swapaxes(error_master, 2, 3)
    error_master = np.swapaxes(error_master, 1, 3)

    no_error_master = np.swapaxes(no_error_master, 2, 3)
    no_error_master = np.swapaxes(no_error_master, 1, 3)

    error_master *= 10e6  # zscore(error_master)
    no_error_master *= 10e6  # zscore(no_error_master)

    return error_master, no_error_master
예제 #5
0
        feature_vol, grand_avg, grand_var = feature.extract(
            error, window, overlap)

    return feature_vol, grand_avg, grand_var


for subject in offline_dict.keys():
    runs = offline_dict[subject]

    grand_avg_fig, grand_avg_axis = plt.subplots(len(channel_names_spellers),
                                                 3)

    count = 0
    for run in runs:
        path = os.path.join(root, subject, 'Offline', run)
        e = EEG()
        (eeg, trig, mat) = e.open(path, channel_names=channel_names_spellers)

        #theta = e.getTheta()
        theta = eeg

        error = e.getEEGTrials(
            pretime=.5,
            posttime=1,
            error=True,
            plot=False,
            gdf=theta,
        )
        no_error = e.getEEGTrials(pretime=.5,
                                  posttime=1,
                                  error=False,