Skip to content

Commit

Permalink
ADD example experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
andycon committed Dec 3, 2020
1 parent c24bd66 commit 02c2149
Show file tree
Hide file tree
Showing 24 changed files with 554 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Examples/exp-alpha/code/dbic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from psychopy import event, visual, core, clock
import qrcode
import time

def waitTrigger(win, runNum, acqNum, qrDur=.05, qrPos=(-.5,-.5), qrSize=.2):


data = {"acqNum": acqNum,
"runNum": runNum,
"trialStart": time.time()
}

print("Waiting for trigger pulse ... or key stroke '5'")
event.waitKeys(keyList=['5'])
clk = clock.Clock()
data["runStart"] = time.time()

qr = visual.ImageStim(win,
qrcode.make(str(data)),
pos=qrPos
)
qr.size = qr.size*qrSize
qr.draw()
win.flip()
core.wait(qrDur)
return clk

def endRun(win, qrDur=.05, qrPos=(-.5,-.5), qrSize=.2):

data = {"runEnd": time.time()}

qr = visual.ImageStim(win,
qrcode.make(str(data)),
pos=qrPos
)
qr.size = qr.size*qrSize
qr.draw()
win.flip()
core.wait(qrDur)

40 changes: 40 additions & 0 deletions Examples/exp-alpha/code/exp-alpha/dbic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from psychopy import event, visual, core, clock
import qrcode
import time

def waitTrigger(win, runNum, acqNum, qrDur=.05, qrPos=(-.5,-.5), qrSize=.2):


data = {"acqNum": acqNum,
"runNum": runNum,
"trialStart": time.time()
}

print("Waiting for trigger pulse ... or key stroke '5'")
event.waitKeys(keyList=['5'])
clk = clock.Clock()
data["runStart"] = time.time()

qr = visual.ImageStim(win,
qrcode.make(str(data)),
pos=qrPos
)
qr.size = qr.size*qrSize
qr.draw()
win.flip()
core.wait(qrDur)
return clk

def endRun(win, qrDur=.05, qrPos=(-.5,-.5), qrSize=.2):

data = {"runEnd": time.time()}

qr = visual.ImageStim(win,
qrcode.make(str(data)),
pos=qrPos
)
qr.size = qr.size*qrSize
qr.draw()
win.flip()
core.wait(qrDur)

75 changes: 75 additions & 0 deletions Examples/exp-alpha/code/exp-alpha/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
arabic-reshaper==2.1.0
astunparse==1.6.3
certifi==2020.6.20
cffi==1.14.3
chardet==3.0.4
cryptography==3.1.1
cycler==0.10.0
decorator==4.4.2
dukpy==0.2.3
esprima==4.0.1
et-xmlfile==1.0.1
freetype-py==2.2.0
future==0.18.2
gevent==20.9.0
gitdb==4.0.5
GitPython==3.1.8
glfw==1.12.0
greenlet==0.4.17
idna==2.10
imageio==2.9.0
imageio-ffmpeg==0.4.2
javascripthon==0.11
jdcal==1.4.1
jedi==0.17.2
json-tricks==3.15.3
kiwisolver==1.2.0
macropy3==1.1.0b2
matplotlib==3.3.2
moviepy==1.0.3
msgpack==1.0.0
msgpack-numpy==0.4.7
numexpr==2.7.1
numpy==1.19.2
opencv-python==4.4.0.44
openpyxl==3.0.5
pandas==1.1.2
parso==0.7.1
Pillow==7.2.0
proglog==0.1.9
psutil==5.7.2
PsychoPy==2020.2.4.post1
pycparser==2.20
pyglet==1.5.7
pyobjc-core==6.2.2
pyobjc-framework-Cocoa==6.2.2
pyobjc-framework-Quartz==6.2.2
PyOpenGL==3.1.5
pyOpenSSL==19.1.0
pyosf==1.0.5
pyparsing==2.4.7
PyQt5==5.15.1
PyQt5-sip==12.8.1
pyserial==3.4
python-bidi==0.4.2
python-dateutil==2.8.1
python-gitlab==2.5.0
pytz==2020.1
PyYAML==5.3.1
pyzmq==19.0.2
questplus==2019.4
requests==2.24.0
scipy==1.5.2
six==1.15.0
smmap==3.0.4
sounddevice==0.4.1
SoundFile==0.10.3.post1
tables==3.6.1
tqdm==4.50.0
urllib3==1.25.10
websocket-client==0.57.0
wxPython==4.1.0
xarray==0.16.1
xlrd==1.2.0
zope.event==4.5.0
zope.interface==5.1.0
162 changes: 162 additions & 0 deletions Examples/exp-alpha/code/exp-alpha/run_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@

from psychopy import visual, core, event, clock
import glob
import numpy as np
from time import time
import dbic
import sys
import os


acqNum = sys.argv[1]
runNum = int(sys.argv[2])

try:
os.mkdir("../data/{}".format(acqNum))
except:
pass

logfn = "../data/{0}/run{1}_logfile.csv".format(acqNum, runNum)
f = open(logfn,"w")
f.write("{}\tStart Experiment\n".format(time()))
f.close()

win = visual.Window(fullscr=True,screen=0)
win.mouseVisible = False # hides the mouse pointer

message = visual.TextStim(win, text="""Waiting for scanner trigger.\nInstructions
for Participant...""")
message.draw()

fixation = visual.TextStim(win, text='+')
reproinMessage = visual.TextStim(win, text="", pos=(0, -.7),
height=.05)


win.flip()




########### wait for trigger here
#
c = dbic.waitTrigger(win, runNum, acqNum)
#################################





fixation.draw() # Change properties of existing stim
win.flip()

spd = 1.000 # Stimulus Presentation Duration
soa = 6.000 # Stimulus Onset Asynchrony
ntrials = ([27, 39, 48])[runNum-1]
iwt = ([16.5,16.,12.])[runNum-1] # Initial Wait Time between scanner trigger and first stimulus

stim_list = glob.glob("../stim/tarantula/*")
#stim_list = stim_list + glob.glob("../stim/scorpion/*")
#np.random.shuffle(stim_list)

stim_images = []
stim_names = []


while len(stim_images) < ntrials:
np.random.shuffle(stim_list)
for stim_fn in stim_list:
stim_names.append(stim_fn)
im = visual.ImageStim(win,stim_fn)
im.size = im.size*.5
stim_images.append(im)


tnum = 1 # Trial number

stim_images[0].draw()

while c.getTime() < iwt:
pass


stim_images = stim_images[0:(ntrials)]

for i in range(len(stim_images)):
open(logfn,"a").write("{0:.3f}\t{1}\n".format(np.round(c.getTime(),decimals=3),
stim_names[i]))
resp = []
event.clearEvents()
win.flip()
fixation.draw()

while (c.getTime() - iwt) < (soa*tnum - (soa-spd)):
resp = event.getKeys(keyList=['q','p'],timeStamped=c)
if len(resp) > 0:
print(resp)
open(logfn,"a").write("{0:.3f}\t{1}\n".format(np.round(resp[0][1],decimals=3),resp[0][0]))
break

while (c.getTime() - iwt) < (soa*tnum - (soa-spd)):
pass

open(logfn,"a").write("{0:.3f}\t{1}\toff\n".format(np.round(c.getTime(),decimals=3), stim_names[i]))
win.flip()

if i < ntrials-1:
stim_images[i+1].draw()


if len(resp) == 0:
while (c.getTime() - iwt) < soa*tnum:
resp = event.getKeys(keyList=['q','p'],timeStamped=c)
if len(resp) > 0:
print(resp)
open(logfn,"a").write("{0:.3f}\t{1}\n".format(np.round(resp[0][1],decimals=3),resp[0][0]))

break


while (c.getTime() - iwt) < soa*tnum:
pass
tnum += 1



"""
open(logfn,"a").write("{0:.3f}\t{1}\n".format(np.round(c.getTime(), decimals=3),
stim_list[tnum-1]))
resp = []
event.clearEvents()
win.flip()
fixation.draw()
while (c.getTime() - iwt) < (soa*tnum - (soa-spd)):
resp = event.getKeys(keyList=['q','p'],timeStamped=c)
if len(resp) > 0:
print(resp)
open(logfn,"a").write("{0:.3f}\t{1}\n".format(np.round(resp[0][1], decimals=3),resp[0][0]))
break
while (c.getTime() - iwt) < (soa*tnum - (soa-spd)):
pass
print(len(stim_list))
print(tnum-1)
open(logfn,"a").write("{0:.3f}\t{1} off\n".format(np.round(c.getTime(), decimals=3), stim_list[tnum-1]))
win.flip()
if len(resp) == 0:
while (c.getTime() - iwt) < soa*tnum:
resp = event.getKeys(keyList=['q','p'],timeStamped=c)
if len(resp) > 0:
print(resp)
open(logfn,"a").write("{0:.3f}\t{1}\n".format(np.round(resp[0][1],
decimals=3),resp[0][0]))
break
while (c.getTime() - iwt) < soa*tnum:
pass
"""
##### print QR stamp for end of video
dbic.endRun(win)
75 changes: 75 additions & 0 deletions Examples/exp-alpha/code/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
arabic-reshaper==2.1.0
astunparse==1.6.3
certifi==2020.6.20
cffi==1.14.3
chardet==3.0.4
cryptography==3.1.1
cycler==0.10.0
decorator==4.4.2
dukpy==0.2.3
esprima==4.0.1
et-xmlfile==1.0.1
freetype-py==2.2.0
future==0.18.2
gevent==20.9.0
gitdb==4.0.5
GitPython==3.1.8
glfw==1.12.0
greenlet==0.4.17
idna==2.10
imageio==2.9.0
imageio-ffmpeg==0.4.2
javascripthon==0.11
jdcal==1.4.1
jedi==0.17.2
json-tricks==3.15.3
kiwisolver==1.2.0
macropy3==1.1.0b2
matplotlib==3.3.2
moviepy==1.0.3
msgpack==1.0.0
msgpack-numpy==0.4.7
numexpr==2.7.1
numpy==1.19.2
opencv-python==4.4.0.44
openpyxl==3.0.5
pandas==1.1.2
parso==0.7.1
Pillow==7.2.0
proglog==0.1.9
psutil==5.7.2
PsychoPy==2020.2.4.post1
pycparser==2.20
pyglet==1.5.7
pyobjc-core==6.2.2
pyobjc-framework-Cocoa==6.2.2
pyobjc-framework-Quartz==6.2.2
PyOpenGL==3.1.5
pyOpenSSL==19.1.0
pyosf==1.0.5
pyparsing==2.4.7
PyQt5==5.15.1
PyQt5-sip==12.8.1
pyserial==3.4
python-bidi==0.4.2
python-dateutil==2.8.1
python-gitlab==2.5.0
pytz==2020.1
PyYAML==5.3.1
pyzmq==19.0.2
questplus==2019.4
requests==2.24.0
scipy==1.5.2
six==1.15.0
smmap==3.0.4
sounddevice==0.4.1
SoundFile==0.10.3.post1
tables==3.6.1
tqdm==4.50.0
urllib3==1.25.10
websocket-client==0.57.0
wxPython==4.1.0
xarray==0.16.1
xlrd==1.2.0
zope.event==4.5.0
zope.interface==5.1.0
Loading

0 comments on commit 02c2149

Please sign in to comment.