Re: [psychopy-users] weird spatial frequency for GratingStim when units = 'pix'?

200 views
Skip to first unread message

Jonathan Peirce

unread,
Jul 16, 2012, 8:52:36 AM7/16/12
to psychop...@googlegroups.com
Actually when the units are pixels the sf units are cycles/pixel (and
when the units are degrees the sf units are c/deg etc). You probably
want a setting more like sf=0.1 so you get one cycle per 10 pixels. The
effects you're getting are due to aliasing. At 0.99 you're completing
most of a grating cycle per pixel, at 1.0 you complete an entire cycle
per pixe;, so you get a uniform field.

Hopefully that makes sense.

Jon

On 16/07/2012 11:23, Matthew Johnson wrote:
> Hi all. I'm an experienced coder but semi-new to Python and brand-new
> to PsychoPy, so apologies in advance for stupid questions.
>
> I'm on 1.74.00 on Windows 7 (using the Coder). I'm trying to do
> Tutorial 1 from the website (that's how new I am) but playing around
> with it a bit.
>
> I'm currently running the tutorial code tweaked to look something like
> this:
>
> from psychopy import visual, core
> mywin =
> visual.Window([1440,900],monitor='MJOffice',fullscr=True,units='pix')
> grating = visual.GratingStim(win=mywin, mask='circle', size=250,
> pos=[-200,0], sf=0.990, ori=90)
> grating.draw()
> mywin.update()
> core.wait(2.0)
>
> It's not clear from the documentation what the expected behavior of a
> GratingStim is if units are set to 'pix', but I am semi-sure this is
> weird no matter what.
>
> Basically, reasonable values for the sf parameter appear to be from
> about 0.9 to 0.999 (but not exactly 1.0). Any other value appears to
> yield a solid patch.
>
> After some trial and error, I found that the displayed spatial
> frequency relates to the height of the screen and bears no relation to
> the size of the grating. The exact formula appears to be:
>
> sf = 1.0 - (cyc / screenHeight)
>
> if I want a spatial frequency that completes cyc cycles in
> screenHeight pixels (and because my actual screen height is 900
> pixels, that means reasonable values are in the .9-.999 range or so).
> Of course one could do a few calculations and get the right spatial
> frequency, but this seems like it is not the intended behavior.
> Presumably if units are 'pix', you'd want sf to indicate something
> like cycles per [grating size].
>
> FYI, I interrogated the value of self._cycles within
> _calcCyclesPerStim of the GratingStim class, and it is spitting out
> values that change with the size parameter of the grating, even though
> the actual spatial frequency you see onscreen doesn't change when you
> alter the size parameter. Unfortunately, that's about as far as my
> current PsychoPy knowledge can take me, debugging-wise.
>
> This isn't a critical issue for me, but thought you'd like to know.
> Keep up the good work!
>
> Cheers,
> Matt Johnson
>
>
> PS #1: To Jon and Jeremy -- this is the Matt Johnson you may recognize
> from Nottingham-Malaysia and Yale, respectively. Hello!
>
> PS #2: As of v1.74, some of the online docs are now a bit out-of-date
> (e.g., Tutorial 1 and psychopy.visual still link to PatchStim), and
> some behavior appears not to be documented (e.g., neither the old
> PatchStim page nor the "Units for the window and stimuli" page
> describe the expected behavior for units of 'pix' in a grating). Just
> an FYI. I'll be happy to help out with code/documentation
> contributions once I get some more knowledge under my belt!
> --
> You received this message because you are subscribed to the Google
> Groups "psychopy-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/psychopy-users/-/oyKO7eZLbxwJ.
> To post to this group, send email to psychop...@googlegroups.com.
> To unsubscribe from this group, send email to
> psychopy-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/psychopy-users?hl=en.

--
Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk


This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

Matthew Johnson

unread,
Jul 16, 2012, 9:51:07 PM7/16/12
to psychop...@googlegroups.com
Ah, yes, that's completely it. Not sure why it didn't occur to me earlier (end of a long day, I suppose). I tried various values between 0-1 but I suppose I stumbled on the aliased range before I stumbled on the range (0 to .3 or so) that is actually correct usage for cycles/pixel.

At any rate, now that you've pointed it out, that's of course 100% reasonable behavior, given the way 'cm' and 'deg' operate. (I suppose an argument could be made that cycles/stimulus, as with 'norm' and 'height', could be a slightly more common use case for pixel people -- at least, it's what first occurred to me to try -- but either way it's no trouble to convert from one to the other.)

I'm sure it's a complete pain keeping the documentation up to date with PsychoPy under active development, but whenever the next round of documentation updates occurs, might I humbly suggest adding in a bit about 'pix' in the Units page (http://www.psychopy.org/general/units.html)? It's the only unit not documented yet, and I suspect others (like myself) who are migrating from PsychToolbox might be stuck in a pixel frame of mind too.

Thanks for the help. I'm sure I'll be pestering you for more retroactively-obvious answers soon.

Cheers,
Matt
> To post to this group, send email to psychopy-users@googlegroups.com.
> To unsubscribe from this group, send email to
> psychopy-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages