yupidevs / yupi

Python package designed for collecting and processing trajectory data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to overwrite time or component attributes of Trajectory objects

LuisAbelRT opened this issue · comments

After creating a Trajectory object, traj, it is possible to successfully overwrite traj.r by using +=. For instance:

import yupi
x = [2, 5, 3]
traj = yupi.Trajectory(x)

traj.r += 1
traj.r
# Vector([[3.],
          [6.],
          [4.])

However, one gets an Attribute Error when trying to do the analogous change with time or component attributes, as indicted bellow:

traj.t += 1
# Attribute Error: can't set attribute 't'
traj.r.x += 1
# Attribute Error: can't set attribute 'x'

It would be great if one could overwrite other Trajectory's attributes as well.

I also suggest that when overwriting traj.r with a np.ndarray, yupi automatically converts it to a Vector object in order to prevent attribute errors:

traj = yupi.Trajectory([2, 5, 3])
traj.r = np.array([5,3,4])[:,None]
print(traj.r.x)
# AttributeError: 'numpy.ndarray' object has no attribute 'x'
traj.r = yupi.Vector([5,3,4])[:,None]
print(traj.r.x)
# Vector([5, 3, 4])