Spatial frequency for visual.ElementArrayStim: gratings not accurate

Hello,

I am trying to use visual.ElementArrayStim to produce many gabor patches.
The code I have is as below:

from psychopy import visual, core, data, event, logging, sound, gui
import numpy as np 
from numpy import sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray
from numpy.random import random, randint, normal, shuffle    


win = visual.Window(size=(900, 900), fullscr=False, screen=0, allowGUI=False, allowStencil=False,
color=[0,0,0], colorSpace='rgb',
blendMode='avg', useFBO=True,
)

import math
from random import randrange
from random import randint

nEls = 50


tex='sin'
mask='gauss'
sizes = [15,15]
sfs = 2

elements = visual.ElementArrayStim(win, nElements=nEls,
                            sizes=sizes, sfs=sfs, units='pix',
                            elementTex=tex, elementMask=mask,
                            fieldShape='sqr')

xys = random([nEls,2])*465-232.5
oris = random()*180

elements.setXYs(xys)

elements.setOris(oris)


for frameN in range(160):
elements.draw()
win.flip()

This code (with sfs = 2) produces nice looking gabors, like the image on the left.
But since the units='pix' for my ElementArrayStim, the sfs value should actually be lower (within 0.2-0.001 according to the PsychoPy documentation).
But when I do uses sfs=0.002, the gabors don’t look correct (image on the right)

I’m not sure what i’m doing wrong.
*I made sure that the units were set to pixels in the Preference box (general) too.

Thanks in advance.

Shouldn’t this depend on the size of your stimuli? i.e. I’m not too familiar with this, but wouldn’t a spatial frequency of 0.002 mean one cycle per 500 pixels? Yours are relatively tiny (15 pixels), and so the frequency should be adjusted upwards accordingly so that one or more cycles can actually be expressed across the small visible width of the stimulus. i.e. go up a couple of orders of magnitude from 0.002, to (at least) the other end of the scale mentioned in the documentation.

I tried doing what you said, and even at sfs=0.2, which would mean that it is 1 cycle for every 5 pixels, the gabor’s still aren’t looking okay.

But when sfs=4, i’m getting double the gratings from before. But that would mean that it is 4 cycles per pixel, which should give me 60 cycles for 15 pixels.

I’m pretty sure sfs is in cycles per element for ElementArrayStim.

1 Like

I see - that makes sense.

Thank you!