Commit 8b0b20cb authored by Ruben van Bergen's avatar Ruben van Bergen

Fixed PsychoJS compatibility bugs

Mainly removed all references to numpy and replaced them with alternative code.
parent d0c55250
participant,session,date,expName,psychopyVersion,frameRate,
2.1761 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['sounddevice', 'PTB', 'pyo', 'pygame'] (in that order).
7.8958 WARNING User requested fullscreen with size [1024 768], but screen is actually [1366, 768]. Using actual size
9.3213 EXP Created window1 = Window(allowGUI=False, allowStencil=False, autoLog=True, backendConf=UNKNOWN, bitsMode=UNKNOWN, blendMode='avg', bpc=(8, 8, 8), color=array([0, 0, 0]), colorSpace='rgb', depthBits=8, fullscr=<method-wrapper '__getattribute__' of attributeSetter object at 0x00000228E2173198>, gamma=None, gammaErrorPolicy='raise', lms=UNKNOWN, monitor=<psychopy.monitors.calibTools.Monitor object at 0x00000228E21A50F0>, multiSample=False, name='window1', numSamples=2, pos=[0.0, 0.0], screen=0, size=array([1366, 768]), stencilBits=0, stereo=False, units='height', useFBO=True, useRetina=False, viewOri=0.0, viewPos=None, viewScale=None, waitBlanking=True, winType='pyglet')
9.3215 EXP window1: mouseVisible = True
9.3216 EXP window1: recordFrameIntervals = False
9.4853 EXP window1: recordFrameIntervals = True
9.6701 EXP window1: recordFrameIntervals = False
10.0238 EXP window1: mouseVisible = True
trials.thisRepN,trials.thisTrialN,trials.thisN,trials.thisIndex,participant,session,date,expName,psychopyVersion,frameRate,
0,0,0,0,adf,001,2021_Aug_03_1621,doodle,2021.2.0,59.79509416858733,
1,0,1,0,adf,001,2021_Aug_03_1621,doodle,2021.2.0,59.79509416858733,
2,0,2,0,adf,001,2021_Aug_03_1621,doodle,2021.2.0,59.79509416858733,
3,0,3,0,adf,001,2021_Aug_03_1621,doodle,2021.2.0,59.79509416858733,
4,0,4,0,adf,001,2021_Aug_03_1621,doodle,2021.2.0,59.79509416858733,
This diff is collapsed.
participant,session,date,expName,psychopyVersion,frameRate,
This source diff could not be displayed because it is too large. You can view the blob instead.
trials.thisRepN,trials.thisTrialN,trials.thisN,trials.thisIndex,participant,session,date,expName,psychopyVersion,frameRate,
This source diff could not be displayed because it is too large. You can view the blob instead.
participant,session,date,expName,psychopyVersion,frameRate,
2.1783 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['sounddevice', 'PTB', 'pyo', 'pygame'] (in that order).
7.3324 WARNING User requested fullscreen with size [1024 768], but screen is actually [1366, 768]. Using actual size
8.7505 EXP Created window1 = Window(allowGUI=False, allowStencil=False, autoLog=True, backendConf=UNKNOWN, bitsMode=UNKNOWN, blendMode='avg', bpc=(8, 8, 8), color=array([0, 0, 0]), colorSpace='rgb', depthBits=8, fullscr=<method-wrapper '__getattribute__' of attributeSetter object at 0x0000012F707060F0>, gamma=None, gammaErrorPolicy='raise', lms=UNKNOWN, monitor=<psychopy.monitors.calibTools.Monitor object at 0x0000012F70735080>, multiSample=False, name='window1', numSamples=2, pos=[0.0, 0.0], screen=0, size=array([1366, 768]), stencilBits=0, stereo=False, units='height', useFBO=True, useRetina=False, viewOri=0.0, viewPos=None, viewScale=None, waitBlanking=True, winType='pyglet')
8.7506 EXP window1: mouseVisible = True
8.7507 EXP window1: recordFrameIntervals = False
8.9185 EXP window1: recordFrameIntervals = True
9.1020 EXP window1: recordFrameIntervals = False
9.4728 EXP window1: mouseVisible = True
participant,session,date,expName,psychopyVersion,frameRate,
This source diff could not be displayed because it is too large. You can view the blob instead.
trials.thisRepN,trials.thisTrialN,trials.thisN,trials.thisIndex,participant,session,date,expName,psychopyVersion,frameRate,
This source diff could not be displayed because it is too large. You can view the blob instead.
trials.thisRepN,trials.thisTrialN,trials.thisN,trials.thisIndex,participant,session,date,expName,psychopyVersion,frameRate,
This source diff could not be displayed because it is too large. You can view the blob instead.
trials.thisRepN,trials.thisTrialN,trials.thisN,trials.thisIndex,participant,session,date,expName,psychopyVersion,frameRate,
0,0,0,0,asdf,001,2021_Aug_03_1709,doodle,2021.2.0,59.57899101822194,
1,0,1,0,asdf,001,2021_Aug_03_1709,doodle,2021.2.0,59.57899101822194,
This source diff could not be displayed because it is too large. You can view the blob instead.
participant,session,date,expName,psychopyVersion,frameRate,
2.2113 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['sounddevice', 'PTB', 'pyo', 'pygame'] (in that order).
8.9710 WARNING User requested fullscreen with size [1024 768], but screen is actually [1366, 768]. Using actual size
10.3988 EXP Created window1 = Window(allowGUI=False, allowStencil=False, autoLog=True, backendConf=UNKNOWN, bitsMode=UNKNOWN, blendMode='avg', bpc=(8, 8, 8), color=array([0, 0, 0]), colorSpace='rgb', depthBits=8, fullscr=<method-wrapper '__getattribute__' of attributeSetter object at 0x0000025E00143198>, gamma=None, gammaErrorPolicy='raise', lms=UNKNOWN, monitor=<psychopy.monitors.calibTools.Monitor object at 0x0000025E001750F0>, multiSample=False, name='window1', numSamples=2, pos=[0.0, 0.0], screen=0, size=array([1366, 768]), stencilBits=0, stereo=False, units='height', useFBO=True, useRetina=False, viewOri=0.0, viewPos=None, viewScale=None, waitBlanking=True, winType='pyglet')
10.3990 EXP window1: mouseVisible = True
10.4000 EXP window1: recordFrameIntervals = False
10.5627 EXP window1: recordFrameIntervals = True
10.7459 EXP window1: recordFrameIntervals = False
11.0880 EXP window1: mouseVisible = True
trials.thisRepN,trials.thisTrialN,trials.thisN,trials.thisIndex,participant,session,date,expName,psychopyVersion,frameRate,
0,0,0,0,asdf,001,2021_Aug_03_1719,doodle,2021.2.0,59.42663989250852,
1,0,1,0,asdf,001,2021_Aug_03_1719,doodle,2021.2.0,59.42663989250852,
2,0,2,0,asdf,001,2021_Aug_03_1719,doodle,2021.2.0,59.42663989250852,
3,0,3,0,asdf,001,2021_Aug_03_1719,doodle,2021.2.0,59.42663989250852,
4,0,4,0,asdf,001,2021_Aug_03_1719,doodle,2021.2.0,59.42663989250852,
This diff is collapsed.
trials.thisRepN,trials.thisTrialN,trials.thisN,trials.thisIndex,participant,session,date,expName,psychopyVersion,frameRate,
0,0,0,0,asdf,001,2021_Aug_03_1729,doodle,2021.2.0,59.94891153765253,
1,0,1,0,asdf,001,2021_Aug_03_1729,doodle,2021.2.0,59.94891153765253,
2,0,2,0,asdf,001,2021_Aug_03_1729,doodle,2021.2.0,59.94891153765253,
3,0,3,0,asdf,001,2021_Aug_03_1729,doodle,2021.2.0,59.94891153765253,
4,0,4,0,asdf,001,2021_Aug_03_1729,doodle,2021.2.0,59.94891153765253,
This diff is collapsed.
trials.thisRepN,trials.thisTrialN,trials.thisN,trials.thisIndex,participant,session,date,expName,psychopyVersion,frameRate,
0,0,0,0,asf,001,2021_Aug_03_1543,doodle,2021.2.0,60.056777681722394,
1,0,1,0,asf,001,2021_Aug_03_1543,doodle,2021.2.0,60.056777681722394,
2,0,2,0,asf,001,2021_Aug_03_1543,doodle,2021.2.0,60.056777681722394,
3,0,3,0,asf,001,2021_Aug_03_1543,doodle,2021.2.0,60.056777681722394,
4,0,4,0,asf,001,2021_Aug_03_1543,doodle,2021.2.0,60.056777681722394,
This diff is collapsed.
trials.thisRepN,trials.thisTrialN,trials.thisN,trials.thisIndex,participant,session,date,expName,psychopyVersion,frameRate,
0,0,0,0,fg,001,2021_Aug_03_1714,doodle,2021.2.0,59.371387621950916,
1,0,1,0,fg,001,2021_Aug_03_1714,doodle,2021.2.0,59.371387621950916,
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy3 Experiment Builder (v2021.2.0),
on augustus 03, 2021, at 14:44
on augustus 03, 2021, at 16:15
If you publish work using this script the most relevant publication is:
Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019)
......@@ -85,12 +85,14 @@ defaultKeyboard = keyboard.Keyboard()
# Initialize components for Routine "trial"
trialClock = core.Clock()
from math import random
font='Arial'
stim_size=0.25
fix_size=0.05
stim_win_size = stim_size*1.25 #Size of (square) window in which digits can appear (window applies to digit borders - not digit centers)
frame_rate = np.asarray([win.getActualFrameRate() for i in range(5)]).mean()
frame_rate = win.getActualFrameRate()
frame_dur = 1/frame_rate
slack = frame_dur*0.25
......@@ -127,16 +129,14 @@ for d in range(10):
image_path = 'digit_ims/font_' + font + '-size_512x512-digit_' + str(d) +'.png'
digit_stims.append(visual.ImageStim(win=win, image=image_path, interpolate=True)) #Opening stims without size specification loads them in original aspect ratio
siz = digit_stims[-1].size #This allows us to change the height of the digit while maintaining the aspect ratio
siz /= siz.max()*stim_size #Because of python weirdness this also modifies the size property of the stimulus
siz /= siz[1]/stim_size #Because of python weirdness this also modifies the size property of the stimulus
crop_path = image_path.replace('.png', '') + '_crops/'
for crop_file in os.listdir(crop_path):
if '.png' in crop_file:
crop_stims.append(visual.ImageStim(win=win, image=crop_path+crop_file, size=stim_size*crop_frac, interpolate=True))
digit_sizes = np.asarray([digit_stims[d].size for d in range(10)], dtype=np.float64)
print(digit_sizes)
digit_sizes = [digit_stims[d].size for d in range(10)]
fixation = visual.ShapeStim(win,
vertices=((0, -fix_size), (0, fix_size), (0,0), (-fix_size,0), (fix_size, 0)),
......@@ -145,7 +145,7 @@ fixation = visual.ShapeStim(win,
lineColor="white"
)
digit_center_wins = stim_win_size-digit_sizes/2
digit_center_wins = [stim_win_size-d/2 for d in digit_sizes]
rsp_prompt = visual.TextStim(win, text='Digits recognized:', height=0.03, pos=(0, 0.05))
rsp_bar = visual.Rect(win, rsp_prompt.boundingBox[0]*1, rsp_prompt.boundingBox[1]*1.5, fillColor=1, units='pix')
......@@ -198,12 +198,13 @@ for thisTrial in trials:
"""
tic = core.getTime()
crop_indices = np.random.randint(0, len(crop_stims), mask_num_crops)
crop_pos = np.random.rand(len(crop_indices),2)*crop_center_win-crop_center_win/2
crop_indices = [random.randint(0, len(crop_stims)) for i in range(mask_num_crops)]
crop_pos_x = [random.random()*crop_center_win[0]-crop_center_win[0]/2 for i in range(mask_num_crops)]
crop_pos_y = [random.random()*crop_center_win[1]-crop_center_win[1]/2 for i in range(mask_num_crops)]
for i in range(mask_num_crops):
this_ind = crop_indices[i]
crop_stims[this_ind].setPos(crop_pos[i])
crop_stims[this_ind].setPos((crop_pos_x[i],crop_pos_y[i]))
crop_stims[this_ind].draw()
t = core.getTime()
......@@ -265,7 +266,7 @@ for thisTrial in trials:
prog_bar.draw()
win.flip()
if stop_exp: break
#if stop_exp: break
rsp_int = np.unique(np.asarray([int(c) for c in keystr]))
......
......@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy3 Experiment Builder (v2021.2.0),
on augustus 03, 2021, at 14:46
on augustus 03, 2021, at 17:29
If you publish work using this script the most relevant publication is:
Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019)
......@@ -85,12 +85,16 @@ defaultKeyboard = keyboard.Keyboard()
# Initialize components for Routine "trial"
trialClock = core.Clock()
import random
random.seed(1234) #This needs to be removed!!
font='Arial'
stim_size=0.25
fix_size=0.05
stim_win_size = stim_size*1.25 #Size of (square) window in which digits can appear (window applies to digit borders - not digit centers)
frame_rate = np.asarray([win.getActualFrameRate() for i in range(5)]).mean()
frame_rate = win.getActualFrameRate()
frame_dur = 1/frame_rate
slack = frame_dur*0.25
......@@ -127,14 +131,14 @@ for d in range(10):
image_path = 'digit_ims/font_' + font + '-size_512x512-digit_' + str(d) +'.png'
digit_stims.append(visual.ImageStim(win=win, image=image_path, interpolate=True)) #Opening stims without size specification loads them in original aspect ratio
siz = digit_stims[-1].size #This allows us to change the height of the digit while maintaining the aspect ratio
siz /= siz.max()/stim_size #Because of python weirdness this also modifies the size property of the stimulus
siz /= siz[1]/stim_size #Because of python weirdness this also modifies the size property of the stimulus
crop_path = image_path.replace('.png', '') + '_crops/'
for crop_file in os.listdir(crop_path):
if '.png' in crop_file:
crop_stims.append(visual.ImageStim(win=win, image=crop_path+crop_file, size=stim_size*crop_frac, interpolate=True))
digit_sizes = np.asarray([digit_stims[d].size for d in range(10)], dtype=np.float64)
digit_sizes = [digit_stims[d].size for d in range(10)]
fixation = visual.ShapeStim(win,
vertices=((0, -fix_size), (0, fix_size), (0,0), (-fix_size,0), (fix_size, 0)),
......@@ -143,7 +147,7 @@ fixation = visual.ShapeStim(win,
lineColor="white"
)
digit_center_wins = stim_win_size-digit_sizes/2
digit_center_wins = [stim_win_size-d/2 for d in digit_sizes]
rsp_prompt = visual.TextStim(win, text='Digits recognized:', height=0.03, pos=(0, 0.05))
rsp_bar = visual.Rect(win, rsp_prompt.boundingBox[0]*1, rsp_prompt.boundingBox[1]*1.5, fillColor=1, units='pix')
......@@ -180,12 +184,14 @@ for thisTrial in trials:
win.flip()
core.wait(1)
this_digits = np.random.choice(pos_digits, num_digits)
digit_pos = np.random.rand(num_digits,2)*digit_center_wins[this_digits] - digit_center_wins[this_digits]/2
this_digits = random.sample(pos_digits, num_digits)
#digit_pos = np.random.rand(num_digits,2)*digit_center_wins[this_digits] - digit_center_wins[this_digits]/2
digit_pos_x = [random.random()*digit_center_wins[d][0] - digit_center_wins[d][0]/2 for d in this_digits]
digit_pos_y = [random.random()*digit_center_wins[d][1] - digit_center_wins[d][1]/2 for d in this_digits]
for di in range(len(this_digits)):
this_digit = this_digits[di]
digit_stims[this_digit].setPos(digit_pos[di])
digit_stims[this_digit].setPos((digit_pos_x[di],digit_pos_y[di]))
digit_stims[this_digit].draw()
stim_tstart = win.flip() #Flip screen and record estimated time
......@@ -194,14 +200,13 @@ for thisTrial in trials:
Pre-draw the mask stimulus since we presumably have some time to do so while we're
waiting for the stimulus to stop being on screen.
"""
tic = core.getTime()
crop_indices = np.random.randint(0, len(crop_stims), mask_num_crops)
crop_pos = np.random.rand(len(crop_indices),2)*crop_center_win-crop_center_win/2
crop_indices = [random.randint(0, len(crop_stims)-1) for i in range(mask_num_crops)]
crop_pos_x = [random.random()*crop_center_win-crop_center_win/2 for i in range(mask_num_crops)]
crop_pos_y = [random.random()*crop_center_win-crop_center_win/2 for i in range(mask_num_crops)]
for i in range(mask_num_crops):
this_ind = crop_indices[i]
crop_stims[this_ind].setPos(crop_pos[i])
crop_stims[this_ind].setPos((crop_pos_x[i],crop_pos_y[i]))
crop_stims[this_ind].draw()
t = core.getTime()
......@@ -244,13 +249,13 @@ for thisTrial in trials:
visual.TextStim(win, 'Really quit (y/n)?', height=0.03).draw()
win.flip()
keys2 = kb.waitKeys(keyList=['y','n'])
for kk in keys2:
for kk in keys2:
if kk=='y': stop_exp=True
if not stop_exp:
confirmed=False
if not confirmed:
if np.isin(thisKey.name, numKeys):
if thisKey.name in numKeys:
keystr+=thisKey.name
if thisKey=='backspace':
keystr=keystr[:-1]
......@@ -263,14 +268,19 @@ for thisTrial in trials:
prog_bar.draw()
win.flip()
if stop_exp: break
#if stop_exp: break
rsp_int = np.unique(np.asarray([int(c) for c in keystr]))
#rsp_int = np.unique(np.asarray([int(c) for c in keystr]))
rsp_int = list(set([int(c) for c in keystr]))
################# Feedback ################
all_d = np.unique(np.concatenate((rsp_int, this_digits)))
num_correct = np.isin(rsp_int, this_digits).sum()
#all_d = np.unique(np.concatenate((rsp_int, this_digits)))
all_d = list(set(rsp_int + this_digits))
num_correct=0
for x in rsp_int:
if x in this_digits: num_correct+=1
#num_correct = np.isin(rsp_int, this_digits).sum()
perc_correct = num_correct/len(all_d)
fbstr = str(round(perc_correct*100)) + '% correct'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment