Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when loading previously saved trajectories without uniformly sampled time data #88

Closed
jokober opened this issue Jan 29, 2022 · 2 comments
Labels
bug ❗ Something isn't working

Comments

@jokober
Copy link

jokober commented Jan 29, 2022

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?

@gvieralopez gvieralopez added the bug ❗ Something isn't working label Jan 29, 2022
@jmorgadov
Copy link
Member

jmorgadov commented Jan 29, 2022

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!

@jmorgadov jmorgadov changed the title Trajectories without uniformly sampled in time Error when loading previously saved trajectories without uniformly sampled time data Jan 29, 2022
@jokober
Copy link
Author

jokober commented Feb 1, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ❗ Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants