# -*- coding: utf-8 -*- from psychopy import event, core, visual, gui import pandas as pd import time, random, sys from psychopy import parallel address=0x0378 par=parallel.ParallelPort(address=address) core.wait(2.0) print par ## METADATA #################################################### GUI = gui.Dlg(title="LetterFlankerTask") GUI.addField('Numero Ss:') GUI.addField('Age:') GUI.addField('Sexe:', choices=["M","F"]) GUI.addField('Laterality:', choices=["Left","Right"]) GUI.addField('Stimuli:', choices=["1","2","3","4","5","6"]) GUI.addField('Condition:', choices=["1","2","3","4"]) GUI.addField('Bloc', choices=["1","2","3","4","5","6"]) GUI.show() if GUI.OK: metadata = GUI.data else: sys.exit("user cancelled") ## ENREGISTREMENT FICHIER #################################################### numSs = metadata[0] Cond = metadata[5] Stimuli = metadata[4] Bloc = metadata[6] nomExp = "FlankerTMS" output = nomExp + "_Part" + str(numSs) + "_CondTMS" + str(Cond) + "_BlocNum"+ str(Bloc) + "_" + time.strftime("%Y-%m-%d_%Hh%M") + ".csv" ## LECTURE LISTE + CREATION NV COLONNES #################################################### d = pd.read_table('Part-' + str(numSs) + '-Bloc-' + str(Bloc) + '-Cond'+ str(Stimuli)+'.txt', encoding='utf-8') t = pd.read_table('training-cond' + str(Stimuli) + '.txt', encoding='utf-8') y = pd.read_table('time.txt', encoding='utf-8') d["numSs"] = int(metadata[0]) d["age"] = int(metadata[1]) d["sexe"] = str(metadata[2]) d["lat"] = str(metadata[3]) d["cond stim"] = int(metadata[4]) d["cond tms"] = int(metadata[5]) d["bloc"] = int(metadata[6]) d["timeTMS"]=0 d["rtsTMS"]=0 d["toucheTMS"]="" d["exactitudeTMS"]=0 d["rts2"]=0 d["touche2"]="" d["exactitude2"]=0 d["rts3"]=0 d["touche3"]="" d["exactitude3"]=0 d["rts4"]=0 d["touche4"]="" d["exactitude4"]=0 d["rts5"]=0 d["touche5"]="" d["exactitude5"]=0 #d["TMS"]=0 #d["EMG2"]=0 #d["EMG3"]=0 #d["EMG4"]=0 #d["EMG5"]=0 ## RANDOM ENTRAINEMENT #################################################### t = t.ix[random.sample(t.index, len(t))] t.index = range(len(t)) ## OUVERTURE DE LA FENETRE #################################################### w = visual.Window([800,600],color="white",units='pix') ## OBJETS PSYCHOPY #################################################### cross = visual.TextStim(w, text="+", color="black", height=50) isi = visual.Rect(w, size=[800,600], fillColor="white", lineColor="white") pause = visual.ImageStim(w, image = 'Pause.jpg',size=[800,600]) fin = visual.ImageStim(w, image = 'Fin.jpg',size =(800,600)) finEnt = visual.ImageStim(w, image = 'Fin-ent.jpg',size =(800,600)) consigne1 = visual.ImageStim(w, image = 'consigne1.jpg',size =(800,600)) consigne2 = visual.ImageStim(w, image = 'consigne2.jpg',size =(800,600)) consigne3 = visual.ImageStim(w, image = 'consigneCond'+ str(Stimuli) +'.jpg',size =(800,600)) ready = visual.ImageStim(w, image = 'Ready.jpg',size =(800,600)) trois = visual.TextStim(w, text="3", color="black", height=100) deux = visual.TextStim(w, text="2", color="black", height=200) un = visual.TextStim(w, text="1", color="black", height=300) fb1 = visual.ImageStim(w, image = 'fb1.jpg',size =(300,300)) fb2 = visual.ImageStim(w, image = 'fb2.jpg',size =(300,300)) ## CONSIGNES #################################################### ## BOUCLE TRAINING #################################################### if (int(Bloc) == 1) or (int(Bloc) == 4): consigne1.draw() w.flip() event.waitKeys(keyList=["space"]) consigne2.draw() w.flip() event.waitKeys(keyList=["space"]) consigne3.draw() w.flip() event.waitKeys(keyList=["space"]) ready.draw() w.flip() event.waitKeys(keyList=["space"]) Htrois = core.Clock() while Htrois.getTime() < 1: trois.draw() w.flip() Hdeux = core.Clock() while Hdeux.getTime() < 1: deux.draw() w.flip() Hun = core.Clock() while Hun.getTime() < 1: un.draw() w.flip() for i in range (t.shape[0]): # isi HISI = core.Clock() while HISI.getTime() < 0.75: isi.draw() w.flip() #cross HCROSS = core.Clock() while HCROSS.getTime() < 0.50: cross.draw() w.flip() #stimulus stim = visual.ImageStim(w, image = t.Essai[i], size=[400,100]) stim.draw() w.flip() #reponse resp = event.waitKeys(keyList=['s','k'])[0] if (resp == "s" and t.Reponse[i] == "s") or (resp == "k" and t.Reponse[i] == "k"): HFB = core.Clock() while HFB.getTime() < 0.5: fb1.draw() w.flip() else: HFB = core.Clock() while HFB.getTime() < 0.5: fb2.draw() w.flip() finEnt.draw() w.flip() event.waitKeys(keyList=["space"]) ## BOUCLE #################################################### ready.draw() w.flip() event.waitKeys(keyList=["space"]) Htrois = core.Clock() while Htrois.getTime() < 1: trois.draw() w.flip() Hdeux = core.Clock() while Hdeux.getTime() < 1: deux.draw() w.flip() Hun = core.Clock() while Hun.getTime() < 1: un.draw() w.flip() for j in range(d.shape[0]): if (d.congruenceTMS[j] == 'neutreIncong' and d.reponseTMS[j] == 's'): EMG1=172 elif (d.congruenceTMS[j] == 'neutreCong' and d.reponseTMS[j] == 'k'): EMG1=171 if (d.congruence2[j] == 'congruent' and d.reponse2[j] == 's'): EMG2=142 elif (d.congruence2[j] == 'congruent' and d.reponse2[j] == 'k'): EMG2=141 elif (d.congruence2[j] == 'incongruent' and d.reponse2[j] == 's'): EMG2=162 elif (d.congruence2[j] == 'incongruent' and d.reponse2[j] == 'k'): EMG2=161 elif (d.congruence2[j] == 'neutre' and d.reponse2[j] == 's'): EMG2=152 elif (d.congruence2[j] == 'neutre' and d.reponse2[j] == 'k'): EMG2=151 if (d.congruence3[j] == 'congruent' and d.reponse3[j] == 's'): EMG3=142 elif (d.congruence3[j] == 'congruent' and d.reponse3[j] == 'k'): EMG3=141 elif (d.congruence3[j] == 'incongruent' and d.reponse3[j] == 's'): EMG3=162 elif (d.congruence3[j] == 'incongruent' and d.reponse3[j] == 'k'): EMG3=161 elif (d.congruence3[j] == 'neutre' and d.reponse3[j] == 's'): EMG3=152 elif (d.congruence3[j] == 'neutre' and d.reponse3[j] == 'k'): EMG3=151 if (d.congruence4[j] == 'congruent' and d.reponse4[j] == 's'): EMG4=142 elif (d.congruence4[j] == 'congruent' and d.reponse4[j] == 'k'): EMG4=141 elif (d.congruence4[j] == 'incongruent' and d.reponse4[j] == 's'): EMG4=162 elif (d.congruence4[j] == 'incongruent' and d.reponse4[j] == 'k'): EMG4=161 elif (d.congruence4[j] == 'neutre' and d.reponse4[j] == 's'): EMG4=152 elif (d.congruence4[j] == 'neutre' and d.reponse4[j] == 'k'): EMG4=151 if (d.congruence5[j] == 'congruent' and d.reponse5[j] == 's'): EMG5=142 elif (d.congruence5[j] == 'congruent' and d.reponse5[j] == 'k'): EMG5=141 elif (d.congruence5[j] == 'incongruent' and d.reponse5[j] == 's'): EMG5=162 elif (d.congruence5[j] == 'incongruent' and d.reponse5[j] == 'k'): EMG5=161 elif (d.congruence5[j] == 'neutre' and d.reponse5[j] == 's'): EMG5=152 elif (d.congruence5[j] == 'neutre' and d.reponse5[j] == 'k'): EMG5=151 # isi HISI = core.Clock() while HISI.getTime() < 0.75: isi.draw() w.flip() #cross HCROSS = core.Clock() while HCROSS.getTime() < 0.50: cross.draw() w.flip() #stimulus1 stim = visual.ImageStim(w, image = d.TMS[j], size=[400,100]) stim.draw() w.flip() H = core.Clock() z = y.time[j] core.wait(z) par.setData(199) par.setData(0) par.setData(EMG1) par.setData(0) ##### Pourquoi? #reponse1 resp = event.waitKeys(keyList=['s','k'])[0] rt = H.getTime()*1000 if (resp == 's'): par.setData(222) else: par.setData(211) #enregistrement VD d.timeTMS[j] = z d.rtsTMS[j] = rt d.toucheTMS[j] = resp if (resp == "s" and d.reponseTMS[j] == "s") or (resp == "k" and d.reponseTMS[j] == "k"): d.exactitudeTMS[j]=100 else: d.exactitudeTMS[j]=0 # isi HISI = core.Clock() while HISI.getTime() < 0.75: isi.draw() w.flip() #cross HCROSS = core.Clock() while HCROSS.getTime() < 0.50: cross.draw() w.flip() #stimulus2 stim = visual.ImageStim(w, image = d.Essai2[j], size=[400,100]) stim.draw() w.flip() H = core.Clock() par.setData(EMG2) #reponse2 resp2 = event.waitKeys(keyList=['s','k'])[0] rt2 = H.getTime()*1000 if (resp2 == 's'): par.setData(222) else: par.setData(211) #enregistrement VD d.rts2[j] = rt2 d.touche2[j] = resp2 if (resp2 == "s" and d.reponse2[j] == "s") or (resp2 == "k" and d.reponse2[j] == "k"): d.exactitude2[j]=100 else: d.exactitude2[j]=0 # isi HISI = core.Clock() while HISI.getTime() < 0.75: isi.draw() w.flip() #cross HCROSS = core.Clock() while HCROSS.getTime() < 0.50: cross.draw() w.flip() #stimulus3 stim = visual.ImageStim(w, image = d.Essai3[j], size=[400,100]) stim.draw() w.flip() H = core.Clock() par.setData(EMG3) #reponse3 resp3 = event.waitKeys(keyList=['s','k'])[0] rt3 = H.getTime()*1000 if (resp3 == 's'): par.setData(222) else: par.setData(211) #enregistrement VD d.rts3[j] = rt3 d.touche3[j] = resp3 if (resp3 == "s" and d.reponse3[j] == "s") or (resp3 == "k" and d.reponse3[j] == "k"): d.exactitude3[j]=100 else: d.exactitude3[j]=0 # isi HISI = core.Clock() while HISI.getTime() < 0.75: isi.draw() w.flip() #cross HCROSS = core.Clock() while HCROSS.getTime() < 0.50: cross.draw() w.flip() #stimulus4 stim = visual.ImageStim(w, image = d.Essai4[j], size=[400,100]) stim.draw() w.flip() H = core.Clock() par.setData(EMG4) #reponse4 resp4 = event.waitKeys(keyList=['s','k'])[0] rt4 = H.getTime()*1000 if (resp4 == 's'): par.setData(222) else: par.setData(211) #enregistrement VD d.rts4[j] = rt4 d.touche4[j] = resp4 if (resp4 == "s" and d.reponse4[j] == "s") or (resp4 == "k" and d.reponse4[j] == "k"): d.exactitude4[j]=100 else: d.exactitude4[j]=0 #1 fois sur deux x = random.uniform(0, 1) if x > 0.5: # isi HISI = core.Clock() while HISI.getTime() < 0.75: isi.draw() w.flip() #cross HCROSS = core.Clock() while HCROSS.getTime() < 0.50: cross.draw() w.flip() #stimulus5 stim = visual.ImageStim(w, image = d.Essai5[j], size=[400,100]) stim.draw() w.flip() H = core.Clock() par.setData(EMG5) #reponse5 resp5 = event.waitKeys(keyList=['s','k'])[0] rt5 = H.getTime()*1000 if (resp5 == 's'): par.setData(222) else: par.setData(211) #enregistrement VD d.rts5[j] = rt5 d.touche5[j] = resp5 if (resp5 == "s" and d.reponse5[j] == "s") or (resp5 == "k" and d.reponse5[j] == "k"): d.exactitude5[j]=100 elif(resp5 == "s" and d.reponse5[j] == "k") or (resp5 == "k" and d.reponse5[j] == "s"): d.exactitude5[j]=0 else: continue if j == 71: pause.draw() w.flip() resp = event.waitKeys(keyList=['space']) Htrois = core.Clock() while Htrois.getTime() < 1: trois.draw() w.flip() Hdeux = core.Clock() while Hdeux.getTime() < 1: deux.draw() w.flip() Hun = core.Clock() while Hun.getTime() < 1: un.draw() w.flip() d .to_csv(output, index=False, header=True, sep=";") fin.draw() w.flip() event.waitKeys(keyList=["space"]) w.close() core.quit()