-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestingState.py
More file actions
131 lines (111 loc) · 5.24 KB
/
restingState.py
File metadata and controls
131 lines (111 loc) · 5.24 KB
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
122
123
124
125
126
127
128
129
130
131
# resting state
# opens a grey window for two five-minutes session
from psychopy import visual, core, event, monitors, data, tools
import random, datetime, time,itertools, sys, os
from pylink import *
def restingState(subjectID):
#event.globalKeys.add(key='q',modifiers = ['ctrl'], func = core.quit)
currentTime=str('%.0f' % time.time())
currentDirectory=os.path.dirname(os.path.realpath(__file__))
fileName = currentDirectory + '/data/ETRP_' + str(subjectID) +'/ETRP_' + currentTime + '_' + str(subjectID)
if not os.path.isdir('data/ETRP_' + str(subjectID)):
os.makedirs('data/ETRP_'+ str(subjectID))
print('Error: subject data folder not found.Making a new one.')
#core.quit()
win = visual.Window(monitor = "testMonitor", fullscr=True, mouseVisible = False)
mon = monitors.Monitor('testMonitor')
winSize = mon.getSizePix()
event.Mouse(visible=False)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Set up eyelinktracker
eyelinktracker = EyeLink() #was EyeLink
RIGHT_EYE = 1
LEFT_EYE = 0
BINOCULAR = 2
foreground = (250,250,250) #???
background = (int(254/2),int(254/2),int(254/2))# check background color on testing date, change if color doesn't match
screenColor = (192,192,192) #???
edfFileName = "RPRS" + str(subjectID)
if len(edfFileName) > 8:
edfFileName = edfFileName[0:8]
getEYELINK().openDataFile(edfFileName)
#Eyelink - set idle mode
getEYELINK().setOfflineMode();
#Eyelink - Gets the display surface and sends a mesage to EDF file;
getEYELINK().sendCommand("screen_pixel_coords = 0 0 %d %d"%(winSize[0]-1, winSize[1]-1))
getEYELINK().sendMessage("Resolution %d %d" %((winSize[0]-1, winSize[1]-1)))
getEYELINK().sendMessage("EyeToScreen %d" %(mon.getDistance()))
getEYELINK().sendMessage("MonitorWidth %d" %(mon.getWidth()))
#EyeLink - Set data file contents
getEYELINK().sendCommand("file_sample_data = LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS,HTARGET,INPUT")
getEYELINK().sendCommand("link_sample_data = LEFT,RIGHT,GAZE,GAZERES,AREA,STATUS,HTARGET,INPUT")
#EyeLink - Set Filter contents
getEYELINK().sendCommand("file_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,MESSAGE,BUTTON,INPUT")
getEYELINK().sendCommand("link_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,BUTTON,INPUT")
#EyeLink - Set Calibration Environment
#getEYELINK().sendCommand("button_function 5 'accept_target_fixation'");
setCalibrationColors(foreground, background); #Sets the calibration target and background color - background color should match testing background
#setTargetSize(int(win.size[0]/20), int(win.size[0]/100)); #select best size for calibration target
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# eyetracker setup
flushGetkeyQueue()
getEYELINK().setOfflineMode()
winX = int(winSize[0])
winY = int(winSize[1])
openGraphics((winX,winY),32)
#openGraphicsEx(genv)
getEYELINK().doTrackerSetup()
closeGraphics()
setCalibrationSounds("", "", "");
setDriftCorrectSounds("", "off", "off");
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
message = visual.TextStim(win,text=u"Ready", height = 0.2, wrapWidth = 1,font='Courier New',
alignHoriz = 'center', alignVert = 'center', color = 'Green',units = 'norm')
for n in range (1,3):
Rsp = False
event.clearEvents()
while Rsp == False:
message.text = 'Ready'
message.color = 'green'
message.draw()
win.flip()
buttonPress=event.getKeys(keyList = ['5'])
if len(buttonPress)>0:
Rsp = True
Clock = core.Clock()
while Clock.getTime() < 300: #300
# # # # # # # # # # # # # # # # # #
getEYELINK().sendMessage('RestingState'+str(n))
# # # # # # # # # # # # # # # # # #
win.flip()
Rsp = False
event.clearEvents()
while Rsp == False:
message.text = 'End of part' + str(n)
message. color = 'white'
message.draw()
win.flip()
buttonPress=event.getKeys(keyList = ['9'])
if len(buttonPress)>0:
Rsp = True
#dataFile.close()
message.text='Thank you for participating!'
for frame in range(60):
message.draw()
win.flip()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if getEYELINK() != None:
# File transfer and cleanup!
getEYELINK().setOfflineMode()
pumpDelay(500)
#Close the file and transfer it to Display PC
getEYELINK().closeDataFile()
transferFileName = fileName + '.edf' # fileName
getEYELINK().receiveDataFile(edfFileName, transferFileName)
getEYELINK().close()
#matFileName = fileName + '.mat'
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#check matlab on the experiment computer
#os.system('DYLD_LIBRARY_PATH=C:/Users/levylab/Documents/Reward and Punishment/edfmat_mac64 %s %s'%(transferFileName,matFileName))
win.close()
core.quit()