How to get the absolute time for each stimuli onset time

Hello,

I’m trying to record the absolute time(the time elapsed since 1970 Jan 1) for each of my stimuli, in order to sync the data time with external programs.

so I tried using the time.time() in the begin experiment section which was successful in printing out the absolute time for when the experiment starts.

import time
thisExp.addData('exp_time', time.time())

however, I tried repeating this on the routines or a specific stimuli by putting

trials.addData('movie_time', time.time())

in the begin routine tab, but I would not record anything.

Thus, what I was to achieve is

1) the absolute time for each stimuli << this would be the best option

or

  1. the absolute time for when the routine starts in each loop

as the stimuli I’m using(movie) equals the routine.

I tried using getAbsTime() but had similar results(which was no data recorded in the csv file)

Thank you in advance :slight_smile:

What happens if you use thisExp.addData rather than trials.addData? That should add it to the object from which the csv output is constructed

I tried using

thisExp.addData(‘movie_time’, time.time())

but it doesnt do anything to the csv file :frowning:

which is weird bc it worked fine for recording the experiment onset time

Hm… Maybe you’re missing a thisExp.nextEntry() afterwards, so it’s continually overriding the row? If it’s not storing anything at all then that is strange, even if time.time() wasn’t working it should be storing None or throwing an error

As the column ‘movie.time’ is not added in the csv file at all, I dont think it is overiding the row.

Is there a way to use getAbsTime()?

If it was throwing an error, it would be easier to fix the problem. The experiment works fine, except for the time stamp. It is really strange…as the experiment is running smoothly…but not producing the data points it should be

If there’s no error then what’s probably happening is it’s succeeding in doing whatever it’s trying to do, but whatever it’s trying to do isn’t what we want it to. Could you share the .psyexp file with me? I’ll look deeper into the code and see what’s going on

Thank you so much for your help. :smiley:

movie_1012_time.psyexp (31.2 KB)

there are a lot of files…as I’m using video stimuli so sorry for the inconvenience :cry:

when the lines of code regarding the time.time() is disabled #thisExp.addData('time', time.time())
the experiment works fine.

When the time.time() function is used in the ‘begin experiment’ tab,

it will print out the time.

However, the experiment crashes(with no warning) when the same line of code is used in the ‘begin routine’ tab.

It did not crash before, but now the time.time() is hindering the entire loop

I really need to get the timestamp of absolute times for each of the movie stimuli in order to integrate it with external devices.

It doesn’t have to be time.time() function. If there is a way to log the timestamp for each routine/stimuli in the form of abs time, it would be the best option.

Aha, I see the problem! You’ve imported time just fine, which is why it work in Begin Experiment, but you’ve overwritten it later by creating a list called time! To fix it you just need to either call the list something else, or import the package under a different name (e.g. import time as gettime)

1 Like

I changed the list name time to timeset, like you suggested and now the experiment runs perfectly!

It fixed the problem, and everything seems to be where I want them to be!

Thank you so much for your help!! :smiley: you are a life saver