dstl / Stone-Soup

A software project to provide the target tracking community with a framework for the development and testing of tracking algorithms.
https://stonesoup.rtfd.io
MIT License
384 stars 126 forks source link

Cannot slice a track when StatesLengthLimiter is used #1018

Open narykov opened 1 month ago

narykov commented 1 month ago

I'd like to use the StatesLengthLimiter wrapper for track initiation when processing a longer dataset. However, when I try slicing the resulting track, I receive this error:

Traceback (most recent call last): File "/Users/alexeynarykov/miniconda3/envs/godot_devel/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3526, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in track_slice = next(iter(tracks))[1:] File "/Users/alexeynarykov/Workspace/GitHub/Stone-Soup-ESA/stonesoup/types/state.py", line 308, in getitem return StateMutableSequence(self.states.getitem(index)) TypeError: 'slice' object cannot be interpreted as an integer

An example based on '09Initiators&_Deleters.py' is provided here. The wrapper definition is on line 173 and slicing is attempted on line 213. When the wrapper definition is suppressed, the error is not showing up and the track slicing works OK.

sdhiscocks commented 1 month ago

Seems to be a limitation of deque that states length limiter use. Work around for now would be to use track_slice = list(next(iter(tracks)))[1:]

There are other solutions as well.

sdhiscocks commented 1 month ago

If all you want to do is [1:] this would be most performant I think track_slice = next(iter(tracks)).states.copy(); track_slice.popleft()