Trajectory Collections

TrajaCollection

When handling multiple trajectories, Traja allows plotting and analysis simultaneously.

Initialize a TrajaCollection() with a dictionary or DataFrame and id_col.

Initializing with Dictionary

The keys of the dictionary can be used to identify types of objects in the scene, eg, “bus”, “car”, “person”:

dfs = {"car0":df0, "car1":df1, "bus0: df2, "person0": df3}

Or, arbitrary numbers can be used to initialize

class traja.frame.TrajaCollection(trjs: Union[traja.frame.TrajaDataFrame, pandas.core.frame.DataFrame, dict], id_col: Optional[str] = None, **kwargs)[source]

Collection of trajectories.

Initializing with a DataFrame

A dataframe containing an id column can be passed directly to TrajaCollection(), as long as the id_col is specified:

trjs = TrajaCollection(df, id_col="id")

Grouped Operations

Operations can be applied to each trajectory with apply_all().

TrajaCollection.apply_all(method, **kwargs)[source]

Applies method to all trajectories

Parameters:method
Returns:dataframe or series
>>> trjs = {ind: traja.generate(seed=ind) for ind in range(3)} # doctest: +SKIP
>>> coll = traja.TrajaCollection(trjs) # doctest: +SKIP
>>> angles = coll.apply_all(traja.calc_angle) # doctest: +SKIP

Plottting Multiple Trajectories

Plotting multiple trajectories can be achieved with plot().

TrajaCollection.plot(colors=None, **kwargs)[source]

Plot collection of trajectories with colors assigned to each id.

>>> trjs = {ind: traja.generate(seed=ind) for ind in range(3)} # doctest: +SKIP
>>> coll = traja.TrajaCollection(trjs) # doctest: +SKIP
>>> coll.plot() # doctest: +SKIP

Colors can be specified for ids by supplying colors with a lookup dictionary:

or with a substring lookup:

colors = [“car”:”red”,
“bus”:”orange”, “12”:”red”, “13”:”orange”, “14”:”orange”]
https://raw.githubusercontent.com/justinshenk/traja/master/docs/images/collection_plot.png