Hi!
I’m making a simple psychophysics experiment. The problem is that the screen changes overall gamma (or brightness) after each run making it impossible to find a threshold across runs. I found this other thread where the gamma or luminance decreased after each run but for me, it both decreases and increases randomly between runs.
I include this minimal working example with a slider to select the opacity of a graded annulus. Sometimes i barely see it at 0.03 and sometimes it is completely visible at 0.03 and the threshold is rather somewhere around 0.01 which is a huge difference.
Is there something wrong with my code (how colors or the window is defined)? Or is it some other problem?
I get this error when running the file:
\path_blabla\anaconda3\envs\psychopy\lib\site-packages\pyglet\image\codecs\wic.py:289: UserWarning: [WinError -2147417850] Cannot change thread mode after it is set warnings.warn(str(err))
I used anaconda to install psychopy according to the instructions on the psychopy website.
psychopy version: 2021.2.3
from psychopy import visual
import numpy as np
# Change these (exit program by selecting the maximum value on the slider.)
resolution = [1920, 1080]
hz = 144 # screen refresh rate
conds = [-45, 45]
def make_objects():
win = visual.Window(allowGUI=False, fullscr=False, size=[1920, 1080], monitor='testMonitor', units='height', color='black')
txt = visual.TextStim(win, color='white', height = 0.02, text = '', pos=(0,-0.4))
myGabor = visual.GratingStim(win, tex='sin', mask='circle', sf=20, color='white',
size=(.1, .1), pos=(0,0))
respGabor = visual.GratingStim(win, tex='sin', mask='circle', sf=4, color='white', size=(.03, .03), contrast=1)
cir = visual.Circle(win, radius=.1*0.4, fillColor='black', lineColor='black')
fix1 = visual.Circle(win, radius=.004, fillColor='white', lineColor='white', opacity=0.7) # inner circle
fix2 = visual.Circle(win, radius=.01, fillColor=None, lineColor='white', opacity=0.7) # outer circle
square = visual.Rect(win, width=.05, height=.05, opacity=1, fillColor='#141414') # fillColor=[-.95]*3
photo = visual.Rect(win, width=.015, height=.015, fillColor='white', lineColor='white', opacity=1, pos=(0.88, 0.49))
return win, txt, myGabor, cir, fix1, fix2, respGabor, square, photo
def show_slider(start=None, text='', scale=(0,1), gran=0.01):
t = visual.TextStim(WIN, color='white', height = 0.05, text = '', pos=(-0.55,-0.4))
slider = visual.Slider(WIN, ticks=np.linspace(*scale,11), labels=list(np.linspace(*scale,11).round(len(str(gran))-2)), pos=(0,-0.4),
granularity=gran, style='rating', labelHeight=0.01, startValue=start, size=(0.9,0.02), opacity=0.1)
slider.draw()
t.text = text
t.draw()
WIN.flip()
while True:
response = slider.getMouseResponses()
if response != None:
break
WIN.flip()
return response
def gabor(ori, opacity):
assert type(opacity) == float
GABOR.ori = ori
GABOR.opacity = opacity
for _ in range(np.random.choice([int(hz * i) for i in [1.0, 1.1, 1.2]])): # jittered blank
FIX1.draw()
FIX2.draw()
WIN.flip()
for _ in range(int(hz*0.05)): # gabor
PHOTO.draw()
GABOR.draw()
CIR.draw()
FIX1.draw()
FIX2.draw()
WIN.flip()
for _ in range(np.random.choice([int(hz * i) for i in [0.6, 0.7, 0.8]])): # jittered blank
FIX1.draw()
FIX2.draw()
WIN.flip()
def practice(slidermax=1):
response = None
WIN.setMouseVisible(True)
while response != slidermax:
response = show_slider(response, response, (0,slidermax),0.001)
WIN.setMouseVisible(False)
gabor(np.random.choice(conds, 1)[0], response)
WIN.setMouseVisible(True)
WIN.setMouseVisible(False)
WIN, TXT, GABOR, CIR, FIX1, FIX2, RESPG, SQUARE, PHOTO = make_objects()
practice(0.1)
WIN.close()