qsrlib_io.world_trace module

class qsrlib_io.world_trace.Object_State(name, timestamp, x=nan, y=nan, z=nan, xsize=nan, ysize=nan, zsize=nan, rotation=(), *args, **kwargs)[source]

Bases: object

Data class structure that is holding various information about an object.

args = None

Optional args.

kwargs = None

Optional kwargs.

name = None

str: Name of the object.

return_bounding_box_2d(xsize_minimal=0, ysize_minimal=0)[source]

Compute the 2D bounding box of the object.

Parameters:
  • xsize_minimal (positive int or float) – If object has no x-size (i.e. a point) then compute bounding box based on this minimal x-size.
  • ysize_minimal (positive int or float) – If object has no y-size (i.e. a point) then compute bounding box based on this minimal y-size.
Returns:

The 2D coordinates of the first (closest to origin) and third (farthest from origin) corners of the bounding box.

Return type:

list of 4 int or float

rotation

tuple or list of float: Rotation of the object in roll-pitch-yaw form (r,p,y) or quaternion (x,y,z,w) one.

timestamp = None

float: Timestamp of the object state, which matches the corresponding key t in World_Trace.trace[t].

x = None

int or float: x-coordinate of the center point.

xsize

positive int or float: Total x-size.

y = None

int or float: y-coordinate of the center point.

ysize

positive int or float: Total y-size.

z = None

int or float: z-coordinate of the center point.

zsize

positive int or float: Total z-size.

class qsrlib_io.world_trace.World_State(timestamp, objects=None)[source]

Bases: object

Data class structure that is holding various information about the world at a particular time.

add_object_state(object_state)[source]

Add/Overwrite an object state.

Parameters:object_state (Object_State) – Object state to be added in the world state.
objects = None

dict: Holds the state of the objects that exist in this world state, i.e. a dict of objects of type Object_State with the keys being the objects names.

timestamp = None

float: Timestamp of the object, which matches the corresponding key t in World_Trace.trace[t].

class qsrlib_io.world_trace.World_Trace(description='', trace=None)[source]

Bases: object

Data class structure that is holding a time series of the world states.

add_object_state(object_state, timestamp=None)[source]

Add/Overwrite an Object_State object.

Parameters:
  • object_state (Object_State) – The object state.
  • timestamp (int or float) – The timestamp where the object state is to be inserted, if not given it is added in the timestamp of the object state.
add_object_state_series(object_states)[source]

Add a series of object states.

Parameters:object_states (list or tuple) – The object states, i.e. a list of Object_State objects.
add_object_track_from_list(track, obj_name, t0=0, **kwargs)[source]

Add the objects data to the world_trace from a list of values.

It is capable of handling 2D and 3D points, 2D and 3D bounding boxes.

Basically:

  • 2D points: tuples have length of 2 (x, y).
  • 3D points: tuples have length of 3 (x, y, z).
  • 2D bounding boxes: tuples have length of 4 (x, y, xsize,y_size).
  • 3D bounding boxes: tuples have length of 6 (x, y, z, xsize, ysize, zsize).
Parameters:
  • track (list or tuple of list(s) or tuple(s)) – List of tuples of data.
  • obj_name (str) – Name of the object.
  • t0 (int or float) – First timestamp to offset timestamps.
  • kwargs – kwargs arguments.
description = None

str: Optional description of the world.

get_at_timestamp_range(start=None, stop=None, istep=1, copy_by_reference=False, include_finish=True)[source]

Return a subsample between start and stop timestamps.

Parameters:
  • start (int or float) – Start timestamp.
  • stop (int or float) – Finish timestamp. If empty then stop is set to the last timestamp.
  • istep (int) – subsample based on step measured in timestamps list index
  • copy_by_reference (bool) – Return a copy or by reference.
  • include_finish (bool) – Whether to include or not the world state at the stop timestamp.
Returns:

Subsample between start and stop.

Return type:

World_Trace

get_for_objects(objects_names, copy_by_reference=False)[source]

Return a subsample for requested objects.

Parameters:
  • objects_names (list or tuple of str) – Requested objects names.
  • copy_by_reference (bool) – Return a copy or by reference.
Returns:

Subsample for the requested objects.

Return type:

World_Trace

get_last_state(copy_by_reference=False)[source]

Get the last world state.

Parameters:copy_by_reference (bool) – Return a copy or by reference.
Returns:The last state in self.trace.
Return type:World_State
get_sorted_timestamps()[source]

Return a sorted list of the timestamps.

Returns:Sorted list of the timestamps.
Return type:list
trace = None

dict: Time series of world states, i.e. a dict of objects of type World_State with the keys being the timestamps.