diff --git a/Examples/exp-alpha/code/dbic.py b/Examples/exp-alpha/code/dbic.py new file mode 100644 index 0000000..a4ac1be --- /dev/null +++ b/Examples/exp-alpha/code/dbic.py @@ -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) + diff --git a/Examples/exp-alpha/code/exp-alpha/dbic.py b/Examples/exp-alpha/code/exp-alpha/dbic.py new file mode 100644 index 0000000..a4ac1be --- /dev/null +++ b/Examples/exp-alpha/code/exp-alpha/dbic.py @@ -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) + diff --git a/Examples/exp-alpha/code/exp-alpha/requirements.txt b/Examples/exp-alpha/code/exp-alpha/requirements.txt new file mode 100644 index 0000000..a56d72e --- /dev/null +++ b/Examples/exp-alpha/code/exp-alpha/requirements.txt @@ -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 diff --git a/Examples/exp-alpha/code/exp-alpha/run_experiment.py b/Examples/exp-alpha/code/exp-alpha/run_experiment.py new file mode 100644 index 0000000..a332de5 --- /dev/null +++ b/Examples/exp-alpha/code/exp-alpha/run_experiment.py @@ -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) diff --git a/Examples/exp-alpha/code/requirements.txt b/Examples/exp-alpha/code/requirements.txt new file mode 100644 index 0000000..a56d72e --- /dev/null +++ b/Examples/exp-alpha/code/requirements.txt @@ -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 diff --git a/Examples/exp-alpha/code/run_experiment.py b/Examples/exp-alpha/code/run_experiment.py new file mode 100644 index 0000000..a332de5 --- /dev/null +++ b/Examples/exp-alpha/code/run_experiment.py @@ -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) diff --git a/Examples/exp-alpha/stim/scorpion/sco01.png b/Examples/exp-alpha/stim/scorpion/sco01.png new file mode 100644 index 0000000..683ebe4 Binary files /dev/null and b/Examples/exp-alpha/stim/scorpion/sco01.png differ diff --git a/Examples/exp-alpha/stim/scorpion/sco02.png b/Examples/exp-alpha/stim/scorpion/sco02.png new file mode 100644 index 0000000..259520b Binary files /dev/null and b/Examples/exp-alpha/stim/scorpion/sco02.png differ diff --git a/Examples/exp-alpha/stim/scorpion/sco03.png b/Examples/exp-alpha/stim/scorpion/sco03.png new file mode 100644 index 0000000..55088d0 Binary files /dev/null and b/Examples/exp-alpha/stim/scorpion/sco03.png differ diff --git a/Examples/exp-alpha/stim/scorpion/sco04.png b/Examples/exp-alpha/stim/scorpion/sco04.png new file mode 100644 index 0000000..9ec4544 Binary files /dev/null and b/Examples/exp-alpha/stim/scorpion/sco04.png differ diff --git a/Examples/exp-alpha/stim/scorpion/sco05.png b/Examples/exp-alpha/stim/scorpion/sco05.png new file mode 100644 index 0000000..ccf757a Binary files /dev/null and b/Examples/exp-alpha/stim/scorpion/sco05.png differ diff --git a/Examples/exp-alpha/stim/scorpion/sco06.png b/Examples/exp-alpha/stim/scorpion/sco06.png new file mode 100644 index 0000000..770ac34 Binary files /dev/null and b/Examples/exp-alpha/stim/scorpion/sco06.png differ diff --git a/Examples/exp-alpha/stim/scorpion/sco07.png b/Examples/exp-alpha/stim/scorpion/sco07.png new file mode 100644 index 0000000..ab36880 Binary files /dev/null and b/Examples/exp-alpha/stim/scorpion/sco07.png differ diff --git a/Examples/exp-alpha/stim/scorpion/sco08.png b/Examples/exp-alpha/stim/scorpion/sco08.png new file mode 100644 index 0000000..a37579b Binary files /dev/null and b/Examples/exp-alpha/stim/scorpion/sco08.png differ diff --git a/Examples/exp-alpha/stim/scorpion/sco09.png b/Examples/exp-alpha/stim/scorpion/sco09.png new file mode 100644 index 0000000..b0e1aeb Binary files /dev/null and b/Examples/exp-alpha/stim/scorpion/sco09.png differ diff --git a/Examples/exp-alpha/stim/tarantula/tar01.png b/Examples/exp-alpha/stim/tarantula/tar01.png new file mode 100644 index 0000000..1ecad71 Binary files /dev/null and b/Examples/exp-alpha/stim/tarantula/tar01.png differ diff --git a/Examples/exp-alpha/stim/tarantula/tar02.png b/Examples/exp-alpha/stim/tarantula/tar02.png new file mode 100644 index 0000000..380630f Binary files /dev/null and b/Examples/exp-alpha/stim/tarantula/tar02.png differ diff --git a/Examples/exp-alpha/stim/tarantula/tar03.png b/Examples/exp-alpha/stim/tarantula/tar03.png new file mode 100644 index 0000000..cfac352 Binary files /dev/null and b/Examples/exp-alpha/stim/tarantula/tar03.png differ diff --git a/Examples/exp-alpha/stim/tarantula/tar04.png b/Examples/exp-alpha/stim/tarantula/tar04.png new file mode 100644 index 0000000..ab752c2 Binary files /dev/null and b/Examples/exp-alpha/stim/tarantula/tar04.png differ diff --git a/Examples/exp-alpha/stim/tarantula/tar05.png b/Examples/exp-alpha/stim/tarantula/tar05.png new file mode 100644 index 0000000..2b28cd3 Binary files /dev/null and b/Examples/exp-alpha/stim/tarantula/tar05.png differ diff --git a/Examples/exp-alpha/stim/tarantula/tar06.png b/Examples/exp-alpha/stim/tarantula/tar06.png new file mode 100644 index 0000000..4cc09cc Binary files /dev/null and b/Examples/exp-alpha/stim/tarantula/tar06.png differ diff --git a/Examples/exp-alpha/stim/tarantula/tar07.png b/Examples/exp-alpha/stim/tarantula/tar07.png new file mode 100644 index 0000000..f3cdd6e Binary files /dev/null and b/Examples/exp-alpha/stim/tarantula/tar07.png differ diff --git a/Examples/exp-alpha/stim/tarantula/tar08.png b/Examples/exp-alpha/stim/tarantula/tar08.png new file mode 100644 index 0000000..cedec09 Binary files /dev/null and b/Examples/exp-alpha/stim/tarantula/tar08.png differ diff --git a/Examples/exp-alpha/stim/tarantula/tar09.png b/Examples/exp-alpha/stim/tarantula/tar09.png new file mode 100644 index 0000000..29c3de3 Binary files /dev/null and b/Examples/exp-alpha/stim/tarantula/tar09.png differ