Howdy, Stranger!

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

Supported by

[solved] Screen Timing in OpenSesame

edited January 2012 in OpenSesame

Hi Sebastiaan!

A quick question about the timing of screens in OpenSesame: is it possible to log the exact time a screen has been displayed? I noticed that the build-in logfunction 'time_objectname' doesn't take the screen's refresh rate into account (for example: when one would present screen1 for 10 ms and screen2 right after screen1, the logged value for time_screen2 minus time_screen1 would produce about 10 to 12, instead of 16 or 17, which would be the correct value on a 60 Hz monitor).
Many thanks in advance!

Kind regards,
Edwin Dalmaijer

Comments

  • edited 11:48PM

    Hi Edwin,

    Yes, if you use the psycho back-end you should get exact timestamps.

    The full story is a bit more complicated though. As you can imagine, canvas.show() must block the program until an image is shown in order to return an exact timestamp. This blocking is obviously highly inefficient (cpu time going to waste), so usually canvas.show() will simply return right away, after the canvas has been queued.

    The behaviour of OpenSesame depends on the back-end, though. The psycho back-end should return exact timestamps, but at the cost of inefficiency.

    See also the waitBlanking variable in the PsychoPy docs and this discussion.

    Hope this helps!

    Regards,
    Sebastiaan

  • edited December 2011

    Hi Sebastiaan!

    Thanks for the quick reply. Sorry I didn't respond sooner! I've tried using the psycho back-end, but the values still seem off a bit:

    time_beeld1 _____ time_beeld2 _____ difference _____ [aanbiedingstijd]
    344,15819_____345,925806_____1,767616_____0
    449,228697_____460,926933_____11,698236_____10
    563,959499_____585,15134_____21,191841_____20
    689,152282_____721,427409_____32,275127_____30
    824,902857_____865,886035_____40,983178_____40
    968,988015_____1020,100768_____51,112753_____50
    1124,0978_____1185,071269_____60,973469_____60

    EDIT: I should've know a copy-pasted table gets messed up pretty bad. Added the table above, although it's a bit messy, since I don't know html... :-S

    time_beeld1 time_beeld2 difference [aanbiedingstijd]
    344,15819 345,925806 1,767616 0
    449,228697 460,926933 11,698236 10
    563,959499 585,15134 21,191841 20
    689,152282 721,427409 32,275127 30
    824,902857 865,886035 40,983178 40
    968,988015 1020,100768 51,112753 50
    1124,0978 1185,071269 60,973469 60
    1288,042243 1359,114491 71,072248 70
    1462,214027 1544,109991 81,895964 80
    1647,196329 1739,290304 92,093975 90
    1842,972528 1944,18664 101,214112 100

    The first column is for the (onset)time of an empty sketchpad, with a duration of [aanbiedingstijd] (the fourth column). The second column is the (onset)time of a second blank sketchpad. The difference between the onset of both sketchpads should be the amount of time the first sketchpad spent on screen, correct?
    Since I've used a 60 Hz monitor, one screen should last about 16,67 ms, or an integer multiplication of 16,67. In light of this, pretty much all values in the third row couldn't be correct. Am I overseeing something? Is there a way of logging and/or calculating the correct values (e.g. 16,67; 16,67; 33,33; 33,33; 50 etc.).

    Thanks again!

    Regards,
    Edwin

  • edited December 2011

    Hi Edwin,

    Thanks for doing these tests!

    Yes, you're right, these values are not possible given your refresh rate. They are what you would expect from a non-blocking mechanism, such as the legacy back-end, where the timestamps reflect the moment of queueing, rather than the moment of actual presentation.

    Just to be sure, I verified that the Psycho backend gives accurate timestamps on my own system (Ubuntu 11.10 Laptop) using this script (paste as inline_script item): https://gist.github.com/1536868. For me, using the Psycho back-end in fullscreen, this gives the expected result in the sense that the observed duration between two displays is a multiple of 16.7 ms.

    I'm not sure why it doesn't work for you. Could you provide some more details on the system that you're using? These things are highly system dependent, so it could be that. And perhaps you could send me the experiment that you used for testing (upload it somewhere or send via email, but please keep the discussion to the forum)?

    Regards,
    Sebastiaan

    (BTW, to get preserve formatting you can use the <PRE> my_code </PRE> tags)

  • edited 11:48PM

    Hey Sebastiaan!

    Sorry for yet another late reply! I've checked it on a different computer (PC, win XP, OpenSesame 0.25; mine was laptop, win7, OpenSesame 0.25) and now the psycho back-end did give exact timestamps, taking the refresh rate into account beautifully!

    Thanks for the help!
    Edwin

  • edited 11:48PM

    Hmm, I suspect that the Aero desktop effects (or whatever the graphical effects are called) are the cause of the issue on Windows 7. I can imagine that Aero is a layer that lies between OpenSesame and the video drivers. I know the same thing happens on Linux when you enable desktop effects.

    Perhaps the problem disappears if you disable the Aero effects (if they were enabled to begin with)?

    Anyhow, good that you got it working properly on the XP machine.

  • edited September 2015

    Hi Sebastiaan,
    I am having a similar issue.
    I try to check the timing of my stimuli and there is a slight difference between the automatic time stamps of opensesame and a variable that I create.
    So I have an inline script called fix_point.
    in the prepare section:

    import random
    from openexp.canvas import canvas
    my_dot = canvas(exp, auto_prepare=False)
    my_dot.fixdot()
    my_dot2 = canvas(exp, auto_prepare=False)
    random_time = random.randint(1700,2500)
    exp.set("randomfixdot", random_time)
    

    and in the run section:

    from openexp.keyboard import keyboard
    my_keyboard = keyboard(exp, keylist=['m', 'q'], timeout = random_time)
    my_keyboard.flush()
    my_dot.show()
    exp.set('fix_point_time',self.time())
    

    Now, the time stamp that open sesame gives me is for instance time_fix_point=5485.21640755but the variable fix_point_time=5514.4769879 and the difference between the two is not a multiple of 16.67 (I am using a 60hz screen).
    I assume that time_fix_point takes the time at which the run part of the inline script is performed and since not much is done before the variable fix_point_time is created I thought they should match. What I would like to know in the end is which of the two is more reliable, if the timestamp created by open sesame or the variable I create.
    Thank you and see you around :)
    Stefania

    Stefania Ficarella, PhD
    Fédération de Recherche 3C
    3, place Victor Hugo Case 32
    site Saint-Charles
    13331 Marseille CEDEX 3

  • edited 11:48PM

    sorry I made a mistake in the numbers.
    fix_point_time =5514.4769879
    time_fix_point_odd = 5485.21640755

    or fix_point_time = 9679.64263587
    time_fix_point_odd = 9662.31744122

  • edited 11:48PM

    Also I tried on a different computer and the differences in time are a bit better but on average still 10 ms which is a bit too much. I would just like to know which of the two times are more reliable. Thank you
    Stefania

  • edited 11:48PM

    Hi Stefania,

    The variable time_fix_point (i.e. the one that OpenSesame creates automatically) indicates when the run phase of the inline_script starts. In this script, a few things happen:

    • You import the keyboard module
    • You create a keyboard object and flush the event buffer
    • You show a previously created canvas. Importantly, this will pause until the display is actually shown, at least if a blocking flip is enabled. (See here: ) Also, you have disabled auto_prepare, which means that a few preparatory things are done too.
    • You log the current time as fix_point_time

    So it makes sense that fix_point_time doesn't correspond to the time that the script was started. In your case, you're probably more interested in the onset time of the canvas, so you'll want to use fix_point_time.

    Some general remarks:

    • You'll probably want to use a different name for your own variable, because you're bound to confuse fix_point_time and time_fix_point!
    • The script doesn't seem to do anything that you couldn't do with a sketchpad and keyboard_response, right?

    Cheers!
    Sebastiaan

  • edited 11:48PM

    Thanks Sebastiaan :)
    yes I thought about that, just wanted to make sure I was seeing things right.
    The script does not end there, I show a few other canvas (warning signal, stimulus) later on. In this case, would you recommend to have separate inline scripts for each one of them or it doesn't make any difference if I create a new time variable after each canvas is shown? Finally, how can I present stimuli on the screen for a fixed amount of time while still checking for key presses? I tried to remove the timeout from the keyboard function but it doesn't seem to work. Thanks!!
    Stefania

  • edited 11:48PM

    In this case, would you recommend to have separate inline scripts for each one of them or it doesn't make any difference if I create a new time variable after each canvas is shown?

    It usually doesn't really matter whether you use one long inline_script, or divide your code over multiple inline_script items. However, dividing the code can make your experiment more structured and easier to understand. So, from a style-perspective, I'd say it's preferable.

    Finally, how can I present stimuli on the screen for a fixed amount of time while still checking for key presses? I tried to remove the timeout from the keyboard function but it doesn't seem to work. Thanks!!

    This depends on what your trial sequence looks like. What exactly do you want to do?

    In general, doing response collection and stimulus presentation in parallel can be a bit tricky in OpenSesame, because OpenSesame uses a very serial approach. But it can be done, and it has come up quite often on this forum. (If you search for keywords like 'multiple key presses', 'parallel responses', etc.)

    Cheers!
    Sebastiaan

  • edited September 2015

    Hi Sebastiaan,
    the thing is that I am presenting different objects in a sequence (fixation point, warning signal, fixation point, stimulus) and while I present each object I want to check for responses and also interrupt the trial if a response occurs before the stimulus presentation.
    So to optimize all of this I wrote one inline script that does everything but I would like the stimulus to stay on the screen for 1 second even if a button was pressed during this time.

    from openexp.keyboard import keyboard
    my_keyboard4 = keyboard(exp, keylist=['m', 'q'],timeout =1000)
    my_keyboard4.flush()
    my_stim.show()
    exp.set('stim_time',self.time())
    start_time4 = self.time()
    key4, end_time4 = my_keyboard4.get_key()
    

    so this is the part of the script that does this but the timeout interrupts the presentation of my_stim if a response is detected before 1 sec. I tried to put 'None' there and add a self.sleep(1000) at the end but in case of no-response the stimulus stays on the screen indefinitely (don't really know why).
    Thank you for your help
    Stefania

  • edited 11:48PM

    I see. That's quite a common problem that people run into. I don't know the details of your experiment, but the basic idea is the following.

    You have two canvas objects, c1 and c2. You want to present c1 for exactly 1000 ms (regardless of the RT), and present c2 afterwards. Right? So two things can happen:

    • Participants press a key within 1000 ms of c1 presentation. In that case, you have to sleep for the remainder of the time, and then present c2.
    • Participants press a key after 1000 ms of c1 presentation. In that case, you have to stop collecting key presses, show c2, and then resume collecting key presses.

    Do you see the logic? The script below shows the basic idea.

    from openexp.canvas import canvas
    from openexp.keyboard import keyboard
    
    # Create two canvas objects. c1 will be presented for 1000 ms, and c2 will
    # be presented afterwards, until a response has been collected
    c1_dur = 1000
    c1 = canvas(exp)
    c1.text('canvas 1')
    c2 = canvas(exp)
    c2.text('canvas 2')
    
    kb = keyboard(exp)
    
    # Show the first canvas and collect a keypress with a timeout that corresponds
    # to the duration of c1
    t1 = c1.show()
    resp, t_resp = kb.get_key(timeout=c1_dur)
    # If a response was given, sleep for the remaining duration, so that c1 stays
    # on the screen for the intended time.
    if resp is not None:
        rt = t_resp - t1
        self.sleep(c1_dur - rt)
    # Show c2, and, if no response was collected yet, wait for a keypress again.
    c2.show()
    if resp is None:
        resp, t_resp = kb.get_key()
        rt = t_resp - t1
    
    exp.set('response', resp)
    exp.set('rt', rt)
    
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