-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemporalExpansionrun .py
125 lines (96 loc) · 2.99 KB
/
temporalExpansionrun .py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 27 01:20:03 2022
@author: yu
"""
import numpy as np
import os
import random
import itertools
import random
import numpy as np
import psychopy
from psychopy import visual, core, event, data, gui
from psychopy.hardware import keyboard
import glob
import random
ddir = 'C:\\Users\yu\Desktop\img3'
os.chdir(ddir)
print(os.getcwd())
# get name of all png files in directory
filelist=os.listdir(ddir)
for fichier in filelist[:]: # filelist[:] makes a copy of filelist.
if not(fichier.endswith(".jpg")):
filelist.remove(fichier)
# get the last four scrambled files
filelist4s = filelist[-4:]
#rand the filelist
random.shuffle(filelist)
# append the two lists together
# to make the first four items as a baseline 5 sec duration training
print(filelist)
expInfo = {'subjnum':''}
expInfo['dateStr'] = data.getDateStr()
dlg = gui.DlgFromDict(expInfo, title='UTP', fixed=['expInfo'])
filenameMain = expInfo['subjnum'] + '_' + expInfo['dateStr']
dataFile = open(filenameMain+'.csv', 'w',encoding='utf-8')
dataFile.write('trial_num, img, response, RT \n')
kb = keyboard.Keyboard()
event.globalKeys.clear()
def byebye():
win.close()
core.quit()
event.globalKeys.add(key='q',func=byebye)
filelist = filelist[-16:] #be ware for weird .jpg hidden files
jitList_ITI = np.random.uniform(0.1, 1.5, 50)
refreshRate = 60
# Open Window
colorspace= 'rgb255'
win = visual.Window([1920,1080],monitor='MSI 240Hz',
units="pix",color = [0, 0, 0],colorSpace='rgb255',
fullscr=True, screen =1)
#training session
nTrial = 0
for k in range(len(filelist4s)):
stim = psychopy.visual.ImageStim(win,filelist4s[k])
stim.draw()
win.flip()
core.wait(5)
win.flip()
print(jitList_ITI[k])
core.wait(jitList_ITI[k])
event.waitKeys(keyList=['r'], modifiers=False, timeStamped=False, clearEvents=True)################ added for break
# testing session
nTrial = 0
for k in range(len(filelist)):
stim = psychopy.visual.ImageStim(win,filelist[k])
stim.draw()
win.flip()
core.wait(5)
win.flip()
print(jitList_ITI[k])
core.wait(jitList_ITI[k])
key =[]
keyPressed = 0
kb.clearEvents()
kb.clock.reset()
framecounter =0
while keyPressed == 0:
win.flip()
thisKey = kb.getKeys(['left','right'])
if len(thisKey) > 0:
key = thisKey[0]
if key.name == 'left':
dataFile.write('%d, %s, %s, %.5f\n' %(nTrial, filelist[k], 's', thisKey[0].rt))
keyPressed =1
print('Response made:','Shorter Pressed')
break
elif key.name == 'right':
dataFile.write('%d, %s, %s, %.5f\n' %(nTrial, filelist[k], 'l', thisKey[0].rt))
keyPressed =1
print('Response made:','Longer Pressed')
break
nTrial+=1
dataFile.close()
win.close()
core.quit()