Howdy, Stranger!

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

Supported by

System time for each sketchpad


Need some assistance to create system timestamps in the logger associated with each image I present on Opensesame.
To give a little context, I am running Opensesame along with an facial emotion detection software. The emotion software give me the system time followed by emotion intensity at each frame taken henceforth. I want to analyze the emotions elicited by the images shown in Opensesame. For this I will need to make sure that I know the timepoints at which each image is displayed in Opensesame so that I can use the data from emotion detection software. I do not have access to any serial/parallel port to send triggers. So I believe that timestamping might work best for me. Any other suggestions are welcome too.

Thanks in advance,


  • Hi Asma,

    How is your experiment structured? Do you present your images via sketchpads or inline_scripts? Normally, OpenSesame logs automatically the time when each of its elements are called. Check out the log file and you should see many variables in the style of time_<item_name>.

    If you present everything in an inline_script, every time you show a canvas, you can save the time of this call to a variable, e.g., var.time_c1 = In doing so, you also get your time stamps.

    Good luck.


  • Hi guys,

    Just to avoid confusion: The timestamps that OpenSesame uses are not the system time, but some relative time measure that depends on the backend. (Such as the number of milliseconds since PyGame was initialized.)

    If you want to get the system time, you can do so with Python's datetime package.

    For example, say that you want to log the system time after showing my_canvas, you could do so as follows:

    from datetime import datetime
    var.my_system_time ='%d-%m-%y %H:%M:%f')

    This will set my_system_time to something like 27-07-16 09:53:387064, where the last value corresponds to microseconds.

    Important: If you must rely on the system time, the two programs (the emotion detection software and OpenSesame) should run on the same computer, so that they use the same system clock. You should not assume that the system clock's of two different computer are perfectly in sync.


  • Thanks for the reply Sebastiaan and Eduaard,

    I am running both the programs on the same system so system time is what I need. I tried the time_ but it gives the relative time as Sebastiaan suggested. I will try the script suggested by you. But where do I place this code? Do I need to program the whole experiment in Python? Or could I use it in OS inline script?

    Best wishes,

  • After the sketchpad that you want to timestamp, you can insert a short inline_script with just this:

    from datetime import datetime
    var.my_system_time ='%d-%m-%y %H:%M:%f')

    If you do this, make sure that the duration of the sketchpad is set to 0, so that the experiment moves on to the timestamp script immediately. If necessary, you can then insert an advanced_delay again after the inline_script. Does that make sense?

  • Dear Sebastiaan,

    Thanks very much for your detailed response. I have made changes as you described and added a custom variable my_system_time in the logger, but still getting NA and not system timestamp.

  • Could you upload the experiment?

  • Here is the script in pastebin.

    Thanks in advance.

  • edited August 2016

    Right, the problem is that you're not setting the time as an experimental variable, that is, not as a property of the var object.

    You're doing:

    from datetime import datetime
    my_sysytem_time'%d-%m-%y %H:%M:%f')

    Whereas you should be doing:

    from datetime import datetime
    var.my_system_time ='%d-%m-%y %H:%M:%f')

    See also:

  • Hi @sebastiaan.
    Thanks for your help here.
    I just noticed something, aren't we missing the "Seconds" in the code here?
    having microseconds without having seconds seems to be not useful.
    shouldn't it be like this: '%d-%m-%y %H:%M:%S:%f' instead?
    please correct me if I misunderstood the calculation.


  • shouldn't it be like this: '%d-%m-%y %H:%M:%S:%f' instead?


Sign In or Register to comment.