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

Methods
Create a new playback for a trajectory.
Check if a task has thrown an exception, and reraise it if so.
Create a FrameData representation, with the given fields present if available.
Check background tasks to ensure they have not encountered an exception.
Pause this object if it is running.
Play the given object.
Restart this back to its initial state.
Run this object, potentially in a background thread.
An alias for run().
Step forward by one step, and then pause the simulation.
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.
-
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.
-
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 of the current frame in the trajectory.
Is this currently running but paused?
Is this currently playing and not paused?
Is this currently running?
Should playback restart from the beginning when the end is reached?
Time in seconds between individual steps of this playable.
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.
-