RatInABox-Lab / RatInABox

A python package for modelling locomotion in complex environments and spatially/velocity selective cell activity.
MIT License
172 stars 31 forks source link

history not loaded when importing trajectory #104

Closed jquinnlee closed 4 months ago

jquinnlee commented 5 months ago

Hello!

While recently using this timeless toolbox I have run into an issue when importing trajectories and updating the agent and neurons with the imported data. I first loaded the position data, and then hand these data off the agent as such:

position = joblib.load("position_file")
fps = 30 # frames per second in Hz
Ag.import_trajectory(times=[i / fps for i in range(position[-1])], positions=position, interpolate=False)

Problem is, when I then try to iterate through the updates like this:

T = position.shape[-1]
for i in range(int(T)):
     Ag.update()
     BVC.update()

It kicks the following error:

Traceback (most recent call last): ... \ratinabox\Agent.py", line 262, in _update_position_along_imported_trajectory old_time = self.history['t'][-1] IndexError: list index out of range

I have a work-around that simply adds a zero value first to the history attribute and the updates seem to work, but why not just fill the history values or compute this when doing the trajectory import?

Thanks Tom and the team!!

jquinnlee commented 5 months ago

To be clear, this was not an issue I faced with some earlier versions of the software - it seems to have cropped up when installing the latest and greatest version.

TomGeorge1234 commented 5 months ago

Oh! Good spot Quinn. Sorry about that.

This makes total sense, I recently refactored the Agent.update(). I must have not tested trajectory importing. Looks easy enough to fix, I'll do it on monday.

I'll also add a new test to catch basic trajectory import stuff like this down the line.

TomGeorge1234 commented 4 months ago

@jquinnlee should be fixed in v1.12.1 (just pushed), let me know if you still experience any issues.