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
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()
.
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)} >>> coll = traja.TrajaCollection(trjs) >>> coll.plot()
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”]
