How to change mean intensity of grating stim

Hi Everyone,

I’m using psychopy.visual.GratingStim and am struggling to figure out if there is a way to change the mean intensity of the grating. For example, I would like to be able to create a grating where the mean of the dark and light cycles has a color value of 0.25, for example. I understand that the color/contrast can be changed by using GratingStim.color, but the mean always seems to remain at 0 (middle grey) no matter what I try.

Thanks for the help,
Scott

For anyone curious about this in the future, I figured out that you can change the mean value by drawing a semi-opaque rectangle over the grating. For example, if you want to change the mean of the grating to 0.5, you can do something like:

grating = visual.GratingStim(
   win,
   color = [1.0, 1.0, 1.0]
)

coverRectangle = visual.Rect(
   win,
   color = [1, 1, 1],
   opacity = 0.5
)

grating.draw()
coverRectangle.draw()
win.flip()

Now you should have a grating with mean = 0.5. You can then further adjust the contrast of the grating and the mean should remain the same.

If you want to make the grating mean less than 0, use

coverRectangle.color = [-1, -1, -1]

and then assign opacity as before (e.g. if you want the mean to be -0.75 assign the rectangle opacity to 0.75)

Cheers,
Scott