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

Plotting non-uniformly sampled data #878

Closed Carlson-J closed 6 months ago

Carlson-J commented 8 months ago

I have some real data that I want to put into Stone-Soup and test out some different kalman filter methods. The data contains bearing and range measurements. I can create a list of Detections with

// Fill in measured covariances
cov = CovarianceMatrix([
    [azVar, 0],
    [0, rngVar]
])
// Create measurement model
meas_model = CartesianToBearingRange(
            ndim_state=4, 
            mapping=(0,2),
            noise_covar=cov)

// Create new detection
state = StateVector([az, rng])
measurements.append(Detection(
    state,
    timestamp=time,
    measurement_model=meas_model
))

The issue I am running into is when I go to plot it

from stonesoup.plotter import AnimatedPlotterly
plotter = AnimatedPlotterly(timestamps, tail_length=0.3)
plotter.plot_measurements(measurements, [0, 2])
plotter.fig

It raises an exception because the time stamps are not evenly spaced. See plotter.py:1506

        # gives the unique values of time gaps between timesteps. If this contains more than
        # one value, then timesteps are not all evenly spaced which is an issue.
        if len(time_spaces) != 1:
            raise ValueError("Ensure timesteps are equally spaced.")

Is there a reason this limitation exists? Is there a different function/class I should be using to plot this kind of data?

mharris-dstl commented 8 months ago

I believe this exists so that AnimatedPlotterly shows a linear passage of time to make physical sense. However, most other/if not all other plotting functions should be fine for you. Plotterly or AnimationPlotter are both often used. In the examples, one like https://stonesoup.readthedocs.io/en/latest/auto_examples/Multi_Tracker_Example.html uses Plotterly, and https://stonesoup.readthedocs.io/en/latest/auto_examples/TimePlotterExample.html explains how to use AnimationPlotter.

Alternatively, you could locally remove the limitation from AnimatedPlotterly, but just be aware that it hasn't been tested for this.

Carlson-J commented 8 months ago

I think adding an option to ignore the check would allow the expected behavior to persist while allowing the flexibility of overriding it. In my case, the timesteps are pretty close, but not perfect. By requiring the user to be explicit about allowing ununiform time steps, we should avoid confusion or misinterpretation of what is being plotted.

Here is an example of what it looks like.

image

The feature is being developed in Plotting Update #887