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
400 stars 131 forks source link

Fixed TypeError being thrown on certain Gaussian states in the Plotter.plot_tracks function #738

Closed gawebb-dstl closed 1 year ago

gawebb-dstl commented 1 year ago

For some Gaussian states the uncertainity can't be plotted by the Plotter class. You can see if you try running the following code

from stonesoup.plotter import Plotter
from stonesoup.types.track import Track
from stonesoup.types.state import GaussianState, StateVector

track = Track([GaussianState(state_vector=[0, 0], covar=[[10, -1], [1, 10]])])
Plotter().plot_tracks(track, mapping=[0, 1], uncertainty=True)
# TypeError: ufunc 'arctan2' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

This is caused by complex eignevalues or eigenvectors from the uncertainity matrix. I've put in a check for these in the Plotter class. States which cause complex eignevalues or eigenvectors are now skipped in the plot_tracks function and a warning is raised. A test has been created for this behaviour

gawebb-dstl commented 1 year ago

I think the same error is present in the Plotterly class but haven't tested it