yupidevs / yupi

Python package designed for collecting and processing trajectory data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when loading previously saved trajectories without uniformly sampled time data

jokober opened this issue · comments

commented

Hi and thanks for your work! I have a question regarding trajectories which are not uniformly sampled in time. Reading your "brief comment on time" in the documentation I thought I only have to supply a sequence of time data and optionally set dt to None. However I realized the dt value set is on creation of the Trajectory object.

points1 = [[0, 0], [1.0, 0], [0.63, 0.98]]
t1 = [0,0.5,2]
track1 = Trajectory(points=points1, t=t1,traj_id="track1")
print(track1.dt)

points2 = [[0, 0], [2.0, 0], [1, 0.98]]
t2 = [0.5,1,1.3]
track2 = Trajectory(points=points2, dt=None, t=t2,traj_id="track2")
print(track2.dt)

Trajectory.save_trajectories([track1,track2], "./demo")
trajs = Trajectory.load_folder("./demo")

output:

1.0
0.4
Ignoring: demo/trajectory_1.json
Ignoring: demo/trajectory_0.json

When saving the trajectories and loading them again this leads to a LoadTrajectoryError triggered by a ValueError:
ValueError: You are giving 'dt' and 't' but 't0' is not the same as the first value of 't'.

Am I understanding something wrong or is this a bug in the implementation?

Thanks for spotting this bug (it was a big one in the implementation of loading these kind of trajectories)

When dt is not given (or given as None) in the trajectory initialization, then its mean value is estimated (for future potential statistical applications). The bug was on saving the trajectory using the estimated dt as the actual dt. As it was an estimation and not the actual dt (due to the non uniformly time spaced characteristics of the trajectory) this value should't be used to initialize a trajectory (which was exactly what we were doing).

Note: dt value is meant to be given in initialization only when there is no time data. In this case, a time data is generated using the given dt and starting at 0.0.

The bug was already fixed in the version 0.8.4 of yupi. You just need to:

pip install -U yupi

In the latest version, there is an attribute dt_mean which represents the estimated value and dt is a property of the Trajectory class which returns the real dt value in case it was given, or returns the estimated value (dt_mean) otherwise. Also, you can access the attribute dt_std to inspect the standard deviation associated to the time sampling.

Thanks a lot for your feedback!

commented

Thanks!