Time

Describing and handling time is a core functionality of bewegung. While the library works with discrete frame numbers (also referred to as the index) internally, a user may want to interact with time in seconds. bewegung.Time objects allow to do both. They handle the conversion between the two based on their internal frames per second state. bewegung.Time objects support basic arithmetic.

Note

bewegung.Time objects are expected to have an identical frames per second state across a video. The bewegung.Time.time() and bewegung.Time.time_from_seconds() methods offer facilities for generating new bewegung.Time objects while “inheriting” the frames per second state from an existing bewegung.Time object. The bewegung.Video.time() and bewegung.Video.time_from_seconds() methods do exactly the same thing based on a bewegung.Video object’s frames per second state.

Warning

Operations between bewegung.Time objects with a different frames per second state will fail, i.e. raise an exception.

An animation is very likely representing real-world data in some slowed-down or accelerated way, i.e. as a form of a slow-motion or time-lapse video. bewegung allows to convert time from custom formats to its internal system via the bewegung.TimeScale class.

The Time Class

class bewegung.Time(fps=60, index=0)

This class represents time both as number of frames (the index) and time in seconds. For conversion, it has an internal frames per second state. Operators for basic arithmetic such as add and substract are implemented. Comparison operators are implemented. Operations can only be performed on Time objects with equal frames per second. If frames per second are unequal, an exception will be raised.

Immutable.

Parameters
  • fps (int) – Frames per second

  • index (int) – Number of frames

__float__()

If converted to a floating point number, the time in seconds will be exposed.

Return type

float

__int__()

If converted to an integer, the frame number (index) will be exposed.

Return type

int

property fps: int

Frames per second

Return type

int

classmethod from_seconds(cls, fps=60, seconds=1.0)

Constructs a new Time object from frames per second and seconds.

Parameters
  • fps (int) – Frames per second

  • seconds (Union[float, int]) – Time in seconds

Return type

TimeABC

property index: int

Time as number of frames

Return type

int

classmethod range(cls, start, stop)

Generator function, similar to Python’s range. Generates Time objects instead, frame by frame.

Parameters
  • start (TimeABC) – Start time of range. start.fps must be equal to stop.fps.

  • stop (TimeABC) – Stop time of range (not included). start.fps must be equal to stop.fps.

Return type

Generator[TimeABC, None, None]

property seconds: float

Time in seconds

Return type

float

time(index)

Generates a new Time object from a given number of frames based on the time’s frames per second.

Parameters

index (int) – Number of frames

Return type

TimeABC

time_from_seconds(seconds)

Generates a new Time object from a given time in seconds based on the time’s frames per second.

Parameters

seconds (Union[float, int]) – Time in seconds

Return type

TimeABC

The TimeScale Class

class bewegung.TimeScale(start, start_scaled, stop, stop_scaled)

Convert between Time objects and custom integer & floating point time values.

Immutable.

Parameters
  • start (TimeABC) – The time of start in the animation

  • start_scaled (Number) – A number representing the begin of the the scaled time interval. Must have the same datatype as stop_scaled.

  • stop (TimeABC) – The time of stop in the animation

  • stop_scaled (Number) – A number representing the end of the the scaled time interval. Must have the same datatype as start_scaled.

static dt2msint(dt)

Converts a Python datetime.datetime object to milliseconds

Parameters

dt (datetime) – Date with (optionally) time and (optionally) time zone information attached

Return type

int

property dtype: Type

Exposes dtype of object

Return type

Type

property fps: int

Frames per second

Return type

int

static iso2dt(isodate)

Converts a ISO-formatted date to a Python datetime.datetime object

Parameters

isodate (str) – A date (and time) following the ISO date format

Return type

datetime

scaled2time(scaled_time)

Converts scaled time to time in animation

Parameters

scaled_time (Number) – A number representing scaled time

Return type

TimeABC

property start: bewegung.animation._abc.TimeABC

Start animation time

Return type

TimeABC

property start_scaled: numbers.Number

Scaled start time

Return type

Number

property stop: bewegung.animation._abc.TimeABC

Stop animation time

Return type

TimeABC

property stop_scaled: numbers.Number

Scaled stop time

Return type

Number

time2scaled(time)

Converts time in animation to scaled time

Parameters

time (TimeABC) – Time in animation

Return type

Number