From 0fa18c9bfc7a7744c2877bbdc3d2bb312c21bfd4 Mon Sep 17 00:00:00 2001 From: G Webb <29946934+gawebb-dstl@users.noreply.github.com> Date: Wed, 12 Oct 2022 19:31:55 +0100 Subject: [PATCH] Added check for complex eignevalues or eigenvectors in uncertainity, plus added tests for it --- stonesoup/plotter.py | 4 ++++ stonesoup/tests/test_plotter.py | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/stonesoup/plotter.py b/stonesoup/plotter.py index c0dc2f5ff..750402b01 100644 --- a/stonesoup/plotter.py +++ b/stonesoup/plotter.py @@ -343,6 +343,10 @@ def plot_tracks(self, tracks, mapping, uncertainty=False, particle=False, track_ HH = np.eye(track.ndim)[mapping, :] # Get position mapping matrix for state in track: w, v = np.linalg.eig(HH @ state.covar @ HH.T) + if np.iscomplexobj(w) or np.iscomplexobj(v): + warnings.warn("Can not plot uncertainty for all states due to complex " + "eignevalues or eigenvectors", UserWarning) + continue max_ind = np.argmax(w) min_ind = np.argmin(w) orient = np.arctan2(v[1, max_ind], v[0, max_ind]) diff --git a/stonesoup/tests/test_plotter.py b/stonesoup/tests/test_plotter.py index d58c54ea6..cbcbf33fe 100644 --- a/stonesoup/tests/test_plotter.py +++ b/stonesoup/tests/test_plotter.py @@ -196,3 +196,16 @@ def test_plot_density_equal_x_y(): timestamp=start_time + timedelta(seconds=k + 1))) with pytest.raises(ValueError): plotter.plot_density({truth}, index=None) + + +def test_plot_complex_uncertainty(): + plotter = Plotter() + track = Track([ + GaussianState( + state_vector=[0, 0], + covar=[[10, -1], [1, 10]]) + ]) + with pytest.warns(UserWarning, match="Can not plot uncertainty for all states due to complex " + "eignevalues or eigenvectors"): + + plotter.plot_tracks(track, mapping=[0, 1], uncertainty=True)