psychopy.core
- basic functions (clocks etc.)¶Basic functions, including timing, rush (imported), quit
psychopy.core.
getTime
()¶Get the current time since psychopy.core was loaded.
Version Notes: Note that prior to PsychoPy 1.77.00 the behaviour of
getTime() was platform dependent (on OSX and linux it was equivalent to
psychopy.core.getAbsTime()
whereas on windows it returned time since loading of the module, as now)
psychopy.core.
getAbsTime
()¶Return unix time (i.e., whole seconds elapsed since Jan 1, 1970).
This uses the same clock-base as the other timing features, like getTime(). The time (in seconds) ignores the time-zone (like time.time() on linux). To take the timezone into account, use int(time.mktime(time.gmtime())).
Absolute times in seconds are especially useful to add to generated file names for being unique, informative (= a meaningful time stamp), and because the resulting files will always sort as expected when sorted in chronological, alphabetical, or numerical order, regardless of locale and so on.
Version Notes: This method was added in PsychoPy 1.77.00
psychopy.core.
wait
(secs, hogCPUperiod=0.2)¶Wait for a given time period.
If secs=10 and hogCPU=0.2 then for 9.8s python’s time.sleep function will be used, which is not especially precise, but allows the cpu to perform housekeeping. In the final hogCPUperiod the more precise method of constantly polling the clock is used for greater precision.
If you want to obtain key-presses during the wait, be sure to use
pyglet and to hogCPU for the entire time, and then call
psychopy.event.getKeys()
after calling
wait()
If you want to suppress checking for pyglet events during the wait, do this once:
core.checkPygletDuringWait = False
This will preserve terminal-window focus during command line usage.
psychopy.core.
Clock
¶A convenient class to keep track of time in your experiments. You can have as many independent clocks as you like (e.g. one to time responses, one to keep track of stimuli...)
This clock is identical to the MonotonicClock
except that it can also be reset to 0 or another value at any point.
add
(t)¶Add more time to the clock’s ‘start’ time (t0).
Note that, by adding time to t0, you make the current time appear less. Can have the effect that getTime() returns a negative number that will gradually count back up to zero.
e.g.:
timer = core.Clock()
timer.add(5)
while timer.getTime()<0:
# do something
reset
(newT=0.0)¶Reset the time on the clock. With no args time will be set to zero. If a float is received this will be the new time on the clock
psychopy.core.
CountdownTimer
(start=0)¶Similar to a Clock
except that time counts down
from the time of last reset
Typical usage:
timer = core.CountdownTimer(5)
while timer.getTime() > 0: # after 5s will become negative
# do stuff
getTime
()¶Returns the current time left on this timer in secs (sub-ms precision)
psychopy.core.
MonotonicClock
(start_time=None)¶A convenient class to keep track of time in your experiments using a sub-millisecond timer.
Unlike the Clock
this cannot be reset to
arbitrary times. For this clock t=0 always represents the time that
the clock was created.
Don’t confuse this class with core.monotonicClock which is an instance of it that got created when PsychoPy.core was imported. That clock instance is deliberately designed always to return the time since the start of the study.
Version Notes: This class was added in PsychoPy 1.77.00
getLastResetTime
()¶Returns the current offset being applied to the high resolution timebase used by Clock.
getTime
()¶Returns the current time on this clock in secs (sub-ms precision)
psychopy.core.
StaticPeriod
(screenHz=None, win=None, name='StaticPeriod')¶A class to help insert a timing period that includes code to be run.
Typical usage:
fixation.draw()
win.flip()
ISI = StaticPeriod(screenHz=60)
ISI.start(0.5) # start a period of 0.5s
stim.image = 'largeFile.bmp' # could take some time
ISI.complete() # finish the 0.5s, taking into account one 60Hz frame
stim.draw()
win.flip() # the period takes into account the next frame flip
# time should now be at exactly 0.5s later than when ISI.start()
# was called
Parameters: |
|
---|
complete
()¶Completes the period, using up whatever time is remaining with a call to wait()
Returns: | 1 for success, 0 for fail (the period overran) |
---|
start
(duration)¶Start the period. If this is called a second time, the timer will be reset and starts again
Parameters: | duration – The duration of the period, in seconds. |
---|