Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Gabor (Grating) size and colors in OpenSesame 4

edited October 2023 in OpenSesame

Hey all,


I'm running OpenSesame 4 and I've been having some trouble getting circular grating stimuli with exactly the size I want. Running the following in psychopy gives me a grating stimulus that is just a tiny bit bigger than the circle. The difference seems to scale with stimulus size, and I'm not sure where this factor could be coming from.

# this is in my simple, single inline script item:
x  = Canvas()


x.gabor(0,0, size=60, env='circular',orient=10,freq=1)
x.circle(0, 0, 30,color='darkred')
x.show()

kb=Keyboard()
kb.get_key()

This is happening with psychopy; I dove all the way to the psychopy source, but was not able to find out where the additional size came from.

I tried to test this with different backends, but then I'm running into a different problem. In both legacy & Expyriment, the code crashes on the fact that whatever color I'm providing for col1, it states it's not a valid color format (white, #ffffff, 255, or tuples). I don't have this problem for other stimuli that I'm trying to give a color; x.fixdot(color='white') runs perfectly fine.

Any help is appreciated!

Wouter

Comments

  • I've done some digging in the psychopy documentation, and my eye landed on a sentence that the underlying texture of a gratingStim should be a square 'power-of-two' image; and in the source I saw comments that pointed to this as well.

    I started to suspect that maybe psychopy scales the texture first, and then draws the size of the mask as a function of the size of the texture; For gabors this isn't a problem, but for circular gratings it means that the size is dependent on the nearest power of two.

    An updated version of my script shows that this indeed seems to be happening; it draws gratings at increasing sizes, and draws a red circle at the expected size on top of it.

    # this is in my simple, single inline script item:
    import numpy as np
    x  = Canvas()
    
    sizes = np.arange(50, 512) ## watch the size of the gabor increase in jumps.
    # sizes = 2**np.array([4,5,6,7,8,9,10]) ## for 2**[even numbers] it actually seems to match
    for gsz in sizes :
        x.gabor(0,0, size=gsz, env='circular',
                orient=10, freq=0.05)
        x.circle(0, 0, gsz//2,color='darkred',penwidth=3)
        x.show()
        
        print (gsz)
        kb=Keyboard()
        # cycle faster or slower, dependent on the number of size-steps
        kb.get_key(timeout=(7500//sizes.size))
    kb.get_key()
    


    As for the color issue: I have no idea why, but it seems like the error is raised in opensesame's Legacy color backend, line 99. That suggests that for whatever reason neither 'white' nor '#ffffff' are passed down as strings.

  • About psychopy and sizes of circular gratings

    I did some digging and got the suspicion that psychopy scales the size of the texture that is underlying a grating up to the nearest power of 2, and then determines the size of the circular mask based on the size of the texture. I couldn't find exactly where this happens, but I saw comments like this in the source

    I tested it with the following script, and there seems to be some truth to this... the size of the red circle here grows smoothly, whereas the size of the grating changes in increasingly big jumps:

    # this is in my simple, single inline script item:
    import numpy as np
    x  = Canvas()
    
    sizes = np.arange(50, 512) ## watch the size of the gabor increase in jumps.
    # sizes = 2**np.array([4,5,6,7,8,9,10]) ## for 2**[even numbers] it actually seems to match
    for gsz in sizes :
        x.gabor(0,0, size=gsz, env='circular',
                orient=10, freq=0.05)
        x.circle(0, 0, gsz//2,color='darkred',penwidth=3)
        x.show()
        
        print (gsz)
        kb=Keyboard()
        # cycle faster or slower, dependent on the number of size-steps
        kb.get_key(timeout=(5500//sizes.size))
    kb.get_key()
    

    About colors in legacy/xpyriment:

    I can't understand why, but the error is triggered in the legacy color module, line 99 . Somehow this means that my color strings are at some point no longer strings..

  • Hi Wouter,

    Can you hack the source code to find out what your color strings changed to before the exception is thrown?

    Also, it sounds as if these problems are specific to OS 4. Is this the case, or do they also occur in OS3? I'd be surprised if the weird gabor behavior occurred only in OS4.

    Eduard

    Buy Me A Coffee

  • edited November 2023

    Hi Edu! Thanks for your response. I'm indeed not entirely sure these things are OS4 specific. But I suspect they have to be 'recent'.

    Size in psychopy

    I suspect this isn't OS4-specific, but I'm surprised no one seems to have brought it up before. Maybe it's something that was introduced with psychopy 3 ?

    If I'm correct about what's happening here, I was going to propose that we could create a custom numpy mask for circular gratings, and pass that to psychopy rather than the label 'circ'. In general, the circular mask created by default seems to scale poorly (very jagged edges with larger gratings). That could then be improved in a single go. Cons are that there's something ugly about making 'circular' gratings an exception, and it'll probably affect the speed at which they are drawn.

    Within the experiment we're building, we're now hacking around this by drawing a fat open circle around the grating in the color of the background. It's ugly, but it works.

    An alternative would be to bother Jon Pierce about this to get a better understanding (and maybe ask them to clarify the documentation).

    But before I'd start developing a solution, I wanted to post it here first and see whether there's something weird about my installation or about my thinking.

    Gabor/Noisepatch Colors in Legacy & Expyriment

    print(type(colorspec)) returns a <class 'openexp._color.legacy.Legacy'>. colorspec is the second argument in the constructor. I suspect something is going wrong in the steps leading up to it, when passing around *args.

    I tried to pinpoint it, but I get very lost in the modern way (👴) that canvas elements are drawn. I suspect @sebastiaan would know exactly where to look.

  • An alternative would be to bother Jon Pierce about this to get a better understanding (and maybe ask them to clarify the documentation).

    +1

    Though, I guess, the power of 2 setup of Psychopy is something they wouldn't want to change all too lightly. But all that can be done here is hacky in one way or another, no?

    Buy Me A Coffee

  • Hi @Wouter and @eduard ,

    Thanks for spotting these issues. Both the color-conversion issue with the legacy and xpyriment backends and the size issue with the psycho backend are related to OpenSesame, not PsychoPy. I will publish a bugfix release (4.0.13) to address them later today!

    — Sebastiaan

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games