TrajectoryPlayback

class narupatools.frame.trajectory_playback.TrajectoryPlayback(trajectory: Union[narupatools.frame.frame_source.TrajectorySource, Any], *, playback_interval: float = 0.1, looping: bool = True)

Allows trajectories to be played back.

Inheritance

Inheritance diagram of TrajectoryPlayback

Methods

__init__

Create a new playback for a trajectory.

check_task

Check if a task has thrown an exception, and reraise it if so.

get_frame

Create a FrameData representation, with the given fields present if available.

health_check

Check background tasks to ensure they have not encountered an exception.

pause

Pause this object if it is running.

play

Play the given object.

restart

Restart this back to its initial state.

run

Run this object, potentially in a background thread.

start

An alias for run().

step

Step forward by one step, and then pause the simulation.

stop

Stop the object if it is running.

__init__(trajectory: Union[narupatools.frame.frame_source.TrajectorySource, Any], *, playback_interval: float = 0.1, looping: bool = True)

Create a new playback for a trajectory.

Parameters
  • playback_interval – The interval between consecutive trajectory frames as it is played back, in seconds.

  • looping – Should playback restart from the beginning when the end of the trajectory is reached.

classmethod check_task(task: Optional[concurrent.futures._base.Future])None

Check if a task has thrown an exception, and reraise it if so.

Parameters

task – Background task to check for an exception.

get_frame(fields: infinite_sets.infinite_sets.InfiniteSet[str] = everything())narupa.trajectory.frame_data.FrameData

Create a FrameData representation, with the given fields present if available.

Parameters

fields – Collection of fields that should be added to FrameData if available.

health_check()None

Check background tasks to ensure they have not encountered an exception.

Calling this allows exceptions raised on background threads to be thrown on the main thread. It is a useful tool for checking if an object has crashed silently in the background.

It is recommended to call this periodically from the main thread to ensure an object is healthy. If no exceptions have occurred, this method will do nothing.

pause(wait: bool = True)None

Pause this object if it is running.

This will not cancel the current run if present, merely suspend it until a subsequent call to play() is made.

Parameters

wait – Wait until the pause has actually occurred.

play()None

Play the given object.

If this is not running, run this on a background thread. Else, unpause if this is paused.

restart()None

Restart this back to its initial state.

run(block: bool = True)Union[bool, concurrent.futures._base.Future[bool]]

Run this object, potentially in a background thread.

If block is True (as is the default), this object will run in the calling thread. If block is False, it will be run in a background thread.

Parameters

block – Should this block?

Raises

PlayableAlreadyRunningError – Playable is running on another thread.

Returns

If run in blocking mode, returns True if the playable completed and False if it was stopped. If run in non-blocking mode, returns a Future with the same result.

start(block: bool = True)None

An alias for run().

Parameters

block – Should this block?

step()None

Step forward by one step, and then pause the simulation.

stop(wait: bool = True)None

Stop the object if it is running.

If this is running, this object will stop executing at the next available point.

Parameters

wait – Should this call wait until this object has stopped running before returning?

Attributes

index

Index of the current frame in the trajectory.

is_paused

Is this currently running but paused?

is_playing

Is this currently playing and not paused?

is_running

Is this currently running?

looping

Should playback restart from the beginning when the end is reached?

on_field_changed

playback_interval

Time in seconds between individual steps of this playable.

playback_rate

Number of steps this playable goes through in 1 second.

index

Index of the current frame in the trajectory.

is_paused

Is this currently running but paused?

is_playing

Is this currently playing and not paused?

is_running

Is this currently running?

This is True even if the playback is paused.

looping

Should playback restart from the beginning when the end is reached?

on_field_changed
playback_interval

Time in seconds between individual steps of this playable.

playback_rate

Number of steps this playable goes through in 1 second.