Ejemplo n.º 1
0
def get_data():
    datax = []
    datay = []
    for i in tqdm(range(1, 60)):
        try:
            data_score = get_score(i)[0]
            data_state = get_state(i, 5)
            data_eeg = get_epoch_eeg(i).drop(["condition"], axis=1)
            if not (len(data_score) == len(data_eeg["epoch"].value_counts())
                    and len(data_score) == len(
                        data_state[data_state["markerText"] == "ShotOps"])):
                continue

            print("yes")
            for shoot in range(len(data_score)):
                datax.append(
                    get_aeraeeg_psd(data_eeg[data_eeg["epoch"] == i][-1000:]))
            datay.extend(data_score)
            """
            data=get_raw_eeg(i)
            events,event_id=mne.events_from_annotations(data)
            epochs=mne.Epochs(data,events,event_id,tmin=-5,tmax=0,event_repeated='drop',preload=True)
            first,second=get_score(i+1)
            rest_eeg=epochs["s1001"][0]
            total_shot_num=len(first)+len(second)
            first_shoot_eeg=epochs["s1002"][-total_shot_num:-len(second)]
            first_shoot_eeg["s1002"][0].plot_psd(fmin=2., fmax=40., average=True, spatial_colors=False,picks=["Fz"])
            plt.show()
            """
        except Exception as e:
            traceback.print_exc()
            pass
    return datax, datay
def get_data():
    datax = []
    datay = []
    high, low = 0, 0
    for i in tqdm(range(1, 60)):
        if i == 32: continue
        try:
            data_score = get_score(i)[0]
            data_state = get_state(i, 3)
            data_eeg = get_epoch_eeg(i).drop(["condition"], axis=1)
            data_aimtrack = get_aimtrack(i)
            data_aimtrack.drop(
                data_aimtrack[data_aimtrack["exp_num"] == 2].index,
                inplace=True)
            data_aimtrack.drop(["exp_num"], axis=1, inplace=True)
            """
            extract aimtrack data
            """
            if not (len(data_score) == len(data_eeg["epoch"].value_counts())
                    and len(data_score) == len(
                        data_state[data_state["markerText"] == "ShotOps"])
                    and len(data_score) == len(
                        data_aimtrack["shoot_num"].value_counts())):
                continue
            print("yes")
            for j in range(len(data_score)):
                if data_score[j] > 9.5:
                    curaimtrackx = data_aimtrack[data_aimtrack["shoot_num"] ==
                                                 j + 1]["x"][-40:].tolist()
                    curaimtracky = data_aimtrack[data_aimtrack["shoot_num"] ==
                                                 j + 1]["y"][-40:].tolist()
                    if len(curaimtrackx) != 40 or len(curaimtracky) != 40:
                        continue
                    datax.append([curaimtrackx, curaimtracky])
                    datay.append(0)
                    print(data_score[j])
                    high += 1

                if data_score[j] < 7.5:
                    curaimtrackx = data_aimtrack[data_aimtrack["shoot_num"] ==
                                                 j + 1]["x"][-40:].tolist()
                    curaimtracky = data_aimtrack[data_aimtrack["shoot_num"] ==
                                                 j + 1]["y"][-40:].tolist()
                    if len(curaimtrackx) != 40 or len(curaimtracky) != 40:
                        continue
                    datax.append([curaimtrackx, curaimtracky])
                    datay.append(1)
                    low += 1

            print(len(datay), len(datax))
            #if len(datay)!=len(datax):
            #    raise Exception("length not matched")
        except Exception as e:
            traceback.print_exc()
            pass
    print(low, high)
    return datax, datay
Ejemplo n.º 3
0
def get_data():
    datax = []
    datay = []
    high, low = 0, 0
    for i in tqdm(range(1, 60)):
        if i == 32: continue
        try:
            data_score = get_score(i)[0]
            data_state = get_state(i, 3)
            data_eeg = get_epoch_eeg(i).drop(["condition"], axis=1)
            if not (len(data_score) == len(data_eeg["epoch"].value_counts())
                    and len(data_score) == len(
                        data_state[data_state["markerText"] == "ShotOps"])):
                continue
            print("yes")
            for j in range(len(data_score)):
                if data_score[j] > 9.5:
                    datay.append(0)
                    c6 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-3000:-2500])
                    c5 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-2500:-2000])
                    c4 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-2000:-1500])
                    c3 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-1500:-1000])
                    c2 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-1000:-500])
                    c1 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-500:])
                    datax.append([c6, c5, c4, c3, c2, c1])
                    high += 1

                if data_score[j] < 7.5:
                    datay.append(1)
                    c6 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-3000:-2500])
                    c5 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-2500:-2000])
                    c4 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-2000:-1500])
                    c3 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-1500:-1000])
                    c2 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-1000:-500])
                    c1 = get_aeraeeg_corr(
                        data_eeg[data_eeg["epoch"] == j][-500:])
                    datax.append([c6, c5, c4, c3, c2, c1])
                    low += 1
            print(len(datay), len(datax))
            #if len(datay)!=len(datax):
            #    raise Exception("length not matched")
        except Exception as e:
            traceback.print_exc()
            pass
    print(low, high)
    return datax, datay
Ejemplo n.º 4
0
def get_data():
    datax=[]
    datay=[]
    high,low=0,0
    for i in tqdm(range(1,60)):
        if i==32: continue
        try:
            data_score=get_score(i)[0]
            data_state=get_state(i,3)
            data_eeg=get_epoch_eeg(i).drop(["condition"],axis=1)
            if not (len(data_score)==len(data_eeg["epoch"].value_counts()) and len(data_score)==len(data_state[data_state["markerText"]=="ShotOps"])): continue
            print("yes")
            for j in range(len(data_score)):
                if data_score[j]>9.5:
                    datay.append(0)
                    high+=1
                    d6=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-3000:-2500])
                    d5=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-2500:-2000])
                    d4=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-2000:-1500])
                    d3=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-1500:-1000])
                    d2=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-1000:-500])
                    d1=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-500:])
                    datax.append([d6,d5,d4,d3,d2,d1])
                
                if data_score[j]<7.5:
                    datay.append(1)
                    low+=1
                    d6=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-3000:-2500])
                    d5=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-2500:-2000])
                    d4=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-2000:-1500])
                    d3=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-1500:-1000])
                    d2=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-1000:-500])
                    d1=get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==j][-500:])
                    datax.append([d6,d5,d4,d3,d2,d1])
            
            print(len(datay),len(datax))
            #if len(datay)!=len(datax):
            #    raise Exception("length not matched")
            """
            data=get_raw_eeg(i)
            events,event_id=mne.events_from_annotations(data)
            epochs=mne.Epochs(data,events,event_id,tmin=-5,tmax=0,event_repeated='drop',preload=True)
            first,second=get_score(i+1)
            rest_eeg=epochs["s1001"][0]
            total_shot_num=len(first)+len(second)
            first_shoot_eeg=epochs["s1002"][-total_shot_num:-len(second)]
            first_shoot_eeg["s1002"][0].plot_psd(fmin=2., fmax=40., average=True, spatial_colors=False,picks=["Fz"])
            plt.show()
            """
        except Exception as e:
            traceback.print_exc()
            pass
    print(low,high)
    return datax,datay
Ejemplo n.º 5
0
def discover_channel_psd_difference():
    highscore_epoch, lowscore_epoch = None, None
    highscorenum, lowscorenum = 0, 0
    for i in range(1, 60):
        try:
            data_score = get_score(i)[0]
            data_state = get_state(i, 3)
            data_eeg = get_epoch_eeg(i).drop(["condition"], axis=1)
            data_raw_eeg = get_raw_eeg(i)
            if not (len(data_score) == len(data_eeg["epoch"].value_counts())
                    and len(data_score) == len(
                        data_state[data_state["markerText"] == "ShotOps"])):
                continue
            print("yes")
            events, event_id = mne.events_from_annotations(data_raw_eeg)
            epochs = mne.Epochs(data_raw_eeg,
                                events,
                                event_id,
                                tmin=-3,
                                tmax=0,
                                event_repeated='drop',
                                preload=True)
            first, second = get_score(i + 1)
            rest_eeg = epochs["s1001"][0]
            total_shot_num = len(first) + len(second)
            first_shoot_eeg = epochs["s1002"][-total_shot_num:-len(second)]
            for j in range(len(data_score)):
                if data_score[j] > 9:
                    if highscore_epoch == None:
                        highscore_epoch = first_shoot_eeg["s1002"][j]
                    else:
                        highscore_epoch = mne.concatenate_epochs(
                            [highscore_epoch, first_shoot_eeg["s1002"][j]])
                    highscorenum += 1

                if data_score[j] < 8:
                    if lowscore_epoch == None:
                        lowscore_epoch = first_shoot_eeg["s1002"][j]
                    else:
                        lowscore_epoch = mne.concatenate_epochs(
                            [lowscore_epoch, first_shoot_eeg["s1002"][j]])
                    lowscorenum += 1
            print(highscorenum)
            print(lowscorenum)
        except Exception as e:
            traceback.print_exc()
    channelnames = ["Fz", "F3", "F4", "P3", "Pz", "P4", "O1", "O2", "POz"]
    print("test")
    for channelname in channelnames:
        plot_channel_psd(highscore_epoch, channelname)

    for channelname in channelnames:
        plot_channel_psd(lowscore_epoch, channelname)
Ejemplo n.º 6
0
def discover_event_difference():
    highscore_epoch, lowscore_epoch = None, None
    highscorenum, lowscorenum = 0, 0
    for i in range(1, 60):
        try:
            data_score = get_score(i)[0]
            data_state = get_state(i, 3)
            data_eeg = get_epoch_eeg(i).drop(["condition"], axis=1)
            data_raw_eeg = get_raw_eeg(i)
            if not (len(data_score) == len(data_eeg["epoch"].value_counts())
                    and len(data_score) == len(
                        data_state[data_state["markerText"] == "ShotOps"])):
                continue
            print("yes")

            events, event_id = mne.events_from_annotations(data_raw_eeg)
            #print(events)
            epochs = mne.Epochs(data_raw_eeg,
                                events,
                                event_id,
                                tmin=-3,
                                tmax=0,
                                event_repeated='drop',
                                preload=True)
            first, second = get_score(i + 1)
            rest_eeg = epochs["s1001"][0]
            total_shot_num = len(first) + len(second)
            first_shoot_eeg = epochs["s1002"][-total_shot_num:-len(second)]
            for j in range(len(data_score)):
                if data_score[j] > 9:
                    if highscore_epoch == None:
                        highscore_epoch = first_shoot_eeg["s1002"][j]
                    else:
                        highscore_epoch = mne.concatenate_epochs(
                            [highscore_epoch, first_shoot_eeg["s1002"][j]])
                    highscorenum += 1

                if data_score[j] < 8:
                    if lowscore_epoch == None:
                        lowscore_epoch = first_shoot_eeg["s1002"][j]
                    else:
                        lowscore_epoch = mne.concatenate_epochs(
                            [lowscore_epoch, first_shoot_eeg["s1002"][j]])
                    lowscorenum += 1
            print(highscorenum)
            print(lowscorenum)
            #fig1=highscore_epoch.plot_psd_topomap(show=False,normalize=True)
            #fig2=lowscore_epoch.plot_psd_topomap(show=False,normalize=True)
            #fig1.savefig(r"C:\Users\zhou\Desktop\毕业设计\mechanical\最终论文\pic\high_score_3s_test\high_score{}.jpg".format(i))
            #fig2.savefig(r"C:\Users\zhou\Desktop\毕业设计\mechanical\最终论文\pic\low_score_3s_test\low_score{}.jpg".format(i))
        except Exception as e:
            traceback.print_exc()

    freq_low = [0, 4, 8, 12, 30]
    freq_high = [4, 8, 12, 30, 45]
    for j in range(len(freq_low)):
        highscore_epoch.load_data().filter(l_freq=freq_low[j],
                                           h_freq=freq_high[j])
        highscoredata = highscore_epoch.get_data()
        corr_matrix = mne.connectivity.envelope_correlation(highscoredata,
                                                            combine="mean")
        plt.imshow(corr_matrix)
        plt.colorbar()
        plt.title("highscore_({}Hz-{}Hz)".format(freq_low[j], freq_high[j]))
        plt.savefig(
            r"C:\Users\zhou\Desktop\毕业设计\mechanical\最终论文\pic\diff\corr\high_score\high_score({}Hz-{}Hz).jpg"
            .format(freq_low[j], freq_high[j]))
        plt.close()

        lowscore_epoch.load_data().filter(l_freq=freq_low[j],
                                          h_freq=freq_high[j])
        lowscoredata = lowscore_epoch.get_data()
        corr_matrix = mne.connectivity.envelope_correlation(lowscoredata,
                                                            combine="mean")
        plt.imshow(corr_matrix)
        plt.colorbar()
        plt.title("lowscore_({}Hz-{}Hz)".format(freq_low[j], freq_high[j]))
        plt.savefig(
            r"C:\Users\zhou\Desktop\毕业设计\mechanical\最终论文\pic\diff\corr\low_score\low_score({}Hz-{}Hz).jpg"
            .format(freq_low[j], freq_high[j]))
        plt.close()
    #fig1.savefig(r"C:\Users\zhou\Desktop\毕业设计\mechanical\最终论文\pic\diff\event\high_score.jpg")
    #fig2.savefig(r"C:\Users\zhou\Desktop\毕业设计\mechanical\最终论文\pic\diff\event\low_score.jpg")
    print(highscorenum)
    print(lowscorenum)
Ejemplo n.º 7
0
def discover_psd_difference():
    highscore_epoch, lowscore_epoch = None, None
    highscorenum, lowscorenum = 0, 0
    for i in range(1, 60):
        try:
            data_score = get_score(i)[0]
            data_state = get_state(i, 3)
            data_eeg = get_epoch_eeg(i).drop(["condition"], axis=1)
            data_raw_eeg = get_raw_eeg(i)
            if not (len(data_score) == len(data_eeg["epoch"].value_counts())
                    and len(data_score) == len(
                        data_state[data_state["markerText"] == "ShotOps"])):
                continue
            print("yes")

            events, event_id = mne.events_from_annotations(data_raw_eeg)
            #print(events)
            epochs = mne.Epochs(data_raw_eeg,
                                events,
                                event_id,
                                tmin=-3,
                                tmax=0,
                                event_repeated='drop',
                                preload=True)
            first, second = get_score(i + 1)
            rest_eeg = epochs["s1001"][0]
            total_shot_num = len(first) + len(second)
            first_shoot_eeg = epochs["s1002"][-total_shot_num:-len(second)]
            for j in range(len(data_score)):
                if data_score[j] > 9:
                    if highscore_epoch == None:
                        highscore_epoch = first_shoot_eeg["s1002"][j]
                    else:
                        highscore_epoch = mne.concatenate_epochs(
                            [highscore_epoch, first_shoot_eeg["s1002"][j]])
                    highscorenum += 1

                if data_score[j] < 8:
                    if lowscore_epoch == None:
                        lowscore_epoch = first_shoot_eeg["s1002"][j]
                    else:
                        lowscore_epoch = mne.concatenate_epochs(
                            [lowscore_epoch, first_shoot_eeg["s1002"][j]])
                    lowscorenum += 1
            print(highscorenum)
            print(lowscorenum)
            fig1 = highscore_epoch.plot_psd_topomap(show=False,
                                                    normalize=False,
                                                    cmap="RdBu_r")
            fig2 = lowscore_epoch.plot_psd_topomap(show=False,
                                                   normalize=False,
                                                   cmap="RdBu_r")
            fig1.savefig(
                r"C:\Users\zhou\Desktop\毕业设计\mechanical\最终论文\pic\high_low1\high_score{}.jpg"
                .format(i))
            fig2.savefig(
                r"C:\Users\zhou\Desktop\毕业设计\mechanical\最终论文\pic\high_low1\low_score{}.jpg"
                .format(i))
            break
        except Exception as e:
            traceback.print_exc()
            break
    #fig1=highscore_epoch.plot_psd_topomap(show=False,cmap="RdBu_r",normalize=True)
    #fig2=lowscore_epoch.plot_psd_topomap(show=False,cmap="RdBu_r",normalize=True)
    #fig1.savefig(r"C:\Users\zhou\Desktop\毕业设计\mechanical\最终论文\pic\high_low\high_score.jpg")
    #fig2.savefig(r"C:\Users\zhou\Desktop\毕业设计\mechanical\最终论文\pic\high_low\low_score.jpg")
    print(highscorenum)
    print(lowscorenum)
Ejemplo n.º 8
0
def draw_pic():
    data_eeg=get_epoch_eeg(1).drop(["condition"],axis=1)
    get_aeraeeg_psd(data_eeg[data_eeg["epoch"]==0][-2000:])