-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSP_Orca18_DistractorOnly.py
More file actions
152 lines (104 loc) · 4.88 KB
/
SP_Orca18_DistractorOnly.py
File metadata and controls
152 lines (104 loc) · 4.88 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import sys
import time
##add path so do not need to replicate sound files
rootpath = 'C:\\VENLAB data\\shared_modules'
sys.path.append(rootpath)
#Purpose of File is to pilot cognitive load task.
#File interfaces with module 'Count_Adjustable', which serves to load a trial at a time.
#Experiment name: Orca18
import viz # vizard library
import vizact # vizard library for timers
import numpy as np # numpy library - such as matrix calculation
import random # python library
import vizdriver_Orca18_pilotnosteering as vizdriver # vizard library
import viztask # vizard library
import math as mt # python library
import Count_Adjustable #distractor task
viz.go()
viz.window.setFullscreenMonitor(2)
viz.window.setFullscreen(viz.ON)
# Prompt for filename
ExpID = "Orca19_Distractor_Baseline_"
DEG_SYM = unichr(176).encode("latin-1")
pname = viz.input('Participant code: ')
########### CHANGE HERE TO TOGGLE PRACTICE ANDS BLOCK #############
#SP CHANGE HERE
PRACTICE = False #if practice, they only do one of each.
DISTRACTOR_TYPE = "Middle" #(2 targets)# "Hard" #"Easy" (1 target) or "Hard" (3 targets).
#Will change here
BLOCK = 2 #1 or 2. #switch to not save over previous file.
#### ORDER TRIALS #####
#previous data was 40%, 2 targets
#A short pilot experiment suggested that target number, not target occurence, should be manipulated.
##Create array of trials.
if PRACTICE:
TrialsPerCondition = 1 #for practice, do one trial each
ExpID = ExpID + '_' + 'PRAC' #file name
if DISTRACTOR_TYPE == "Easy":
FACTOR_targetnumber = [1] #number of targets to keep count of.
elif DISTRACTOR_TYPE == "Middle":
FACTOR_targetnumber = [2] #number of targets to keep count of.
elif DISTRACTOR_TYPE == "Hard":
FACTOR_targetnumber = [3] #number of targets to keep count of.
else:
raise Exception("Distractor Type must be Easy or Hard. Case sensitive")
else:
TrialsPerCondition = 3 #for the isolated task, do three trials each.
ExpID = ExpID + '_' + str(BLOCK)
#FACTOR_targetnumber = [1, 3] #number of targets to keep count of.
FACTOR_targetnumber = [2] #number of targets to keep count of.
FACTOR_targetoccurence_prob = [.4] #probability of response frequency
##################
file_prefix = str(ExpID) + "_" + str(pname)
NCndts = len(FACTOR_targetoccurence_prob) * len(FACTOR_targetnumber)
ConditionList = range(NCndts)
#automatically generate factor lists so you can adjust levels using the FACTOR variables
ConditionList_targetoccurence_prob = np.repeat(FACTOR_targetoccurence_prob, len(FACTOR_targetnumber) )
ConditionList_targetnumber = np.tile(FACTOR_targetnumber, len(FACTOR_targetoccurence_prob) )
print (ConditionList_targetoccurence_prob)
print (ConditionList_targetnumber)
TotalN = NCndts * TrialsPerCondition
TRIALSEQ = range(0,NCndts)*TrialsPerCondition
np.random.shuffle(TRIALSEQ)
#### SETUP DRIVER & DISTRACTOR MODULES ######
TrialTime = 15
StartScreenTime = 2
TotalTrialTime = TrialTime+StartScreenTime
Distractor = Count_Adjustable.Distractor(file_prefix, max(FACTOR_targetnumber), pname, triallength= TrialTime, ntrials = TrialsPerCondition, startscreentime = StartScreenTime)
driver = vizdriver.Driver(Distractor) #initialise driver
global waitButton1, waitButton2
#wait for a gear pad press.
driverjoy = driver.getJoy() #Set joystick gear pad callbacks
waitButton1 = vizdriver.waitJoyButtonDown(5,driverjoy)
waitButton2 = vizdriver.waitJoyButtonDown(6,driverjoy)
def runtrials():
for i, trialtype in enumerate(TRIALSEQ):
print("Trial: ", str(i))
print("TrialType: ", str(i))
trial_targetoccurence_prob = ConditionList_targetoccurence_prob[trialtype] #set occurence parameter for the trial.
trial_targetnumber = ConditionList_targetnumber[trialtype] #set target number for the trial.
print(str([trial_targetoccurence_prob, trial_targetnumber]))
Distractor.StartTrial(trial_targetoccurence_prob, trial_targetnumber, trialn = i) #starts trial
print ("Called Start Trial, now waiting")
#yield viztask.waitTime(TotalTrialTime+.5) #this should always wait a little longer than the TrialTime, allowing the EndOfTrial function to get called in Count_Adjustable.
def MonitorDistactor():
"""will return true if it is the end of trial"""
EoTFlag = Distractor.getFlag() # True if it's the end of the trial
return (EoTFlag)
yield viztask.waitTrue(MonitorDistactor)
###interface with End of Trial Screen
pressed = 0
while pressed < trial_targetnumber:
#keep looking for gearpad presses until pressed reaches trial_targetnumber
print ("waiting for gear press")
d = yield viztask.waitAny([waitButton1, waitButton2])
pressed += 1
print('pressed ' + str(pressed))
Distractor.gearpaddown(d.condition) #call gearpaddown.
yield viztask.waitTime(.5)
#Distractor.EoTScreen_Visibility(viz.OFF)
Distractor.RecordCounts()
#Finished = True
else:
viz.quit() ##otherwise keeps writting data onto last file untill ESC
viztask.schedule(runtrials())