Multi-Target Tracking in 3D Using Platform Simulation
In the Stone Soup library, simulations can be set up and run using special
Sensor objects. Simulated data can be preferable to
real data as the user has more control over the tracking scenario and real
data can be difficult or costly to acquire.
Creating the Sensor
We will begin by importing many relevant packages for the simulation.
from datetime import datetime from datetime import timedelta import numpy as np import random # Stone Soup imports: from stonesoup.types.state import State, GaussianState from stonesoup.types.array import StateVector, CovarianceMatrix from stonesoup.models.transition.linear import ( CombinedLinearGaussianTransitionModel, ConstantVelocity) from stonesoup.models.measurement.nonlinear import \ CartesianToElevationBearingRange from stonesoup.deleter.time import UpdateTimeStepsDeleter from stonesoup.tracker.simple import MultiTargetMixtureTracker from matplotlib import pyplot as plt
We set the start time to be the moment when we begin the simulation; for simulations, the actual time doesn’t matter, only the time delta between the start and the point in question. We also set a random seed to ensure a standard outcome. At the end, you can try changing this value to see how the stochastic nature of the simulation and tracker can produce very different tracking scenarios with the same parameters.
Create the Stationary Platform
Next, we will create a platform that will hold our radar sensor. In this case, the platform is stationary and located at the point (0, 0, 0), though in general it need not be.
Define the initial platform position, in this case the origin
Create the initial state (position, time). Notice that the time is set to the simulation start time defined earlier
Create our fixed platform
Create a Sensor
Now that our sensor platform has been created, we can create a sensor to attach to it. In this case, we will be using a radar that takes measurements of range, bearing, and elevation of the targets.
First we create a covariance matrix which is a suitable measurement accuracy for the radar sensor. This radar measures range with an accuracy of +/- 25m, elevation accuracy +/- 0.15, degrees and bearing accuracy of +/- 0.15 degrees.
The radar needs to be informed of where x, y, and z are in the target state space. In Stone Soup the states are often of the form [x, vx, y, vy, z, vz].
radar_mapping = (0, 2, 4)
A newer feature of the Stone Soup platform simulations are the ability to
generate clutter directly from the sensors using the
class. Using the clutter models, we can simulate realistic clutter
originating from the measurement model. Clutter is defined in the Cartesian
plane and converted to the correct measurement types according to the
sensor. We will now add a clutter model to the radar sensor. This clutter
model will use a uniform distribution over the defined ranges in each
Instantiate the radar and finally, attach the sensor to the stationary platform we defined above.
Create the Simulation
For this example, we wish to have a simulation of multiple airborne targets.
We will use the
MultiTargetGroundTruthSimulator class to simulate
the target paths, and then the
to handle the radar simulation.
Set a constant velocity transition model for the targets
Define the Gaussian State from which new targets are sampled on initialisation
And create the truth simulator for the targets
from stonesoup.simulator.simple import MultiTargetGroundTruthSimulator groundtruth_sim = MultiTargetGroundTruthSimulator( transition_model=transition_model, # target transition model initial_state=initial_target_state, # add our initial state for targets timestep=timedelta(seconds=1), # time between measurements number_steps=120, # 2 minutes birth_rate=0.05, # 5% chance of a new target being born every second death_probability=0.05 # 5% chance of a target being killed )
With our truth data generated and our sensor platform placed, we can now construct a simulator to generate measurements of the targets from each of the sensors in the simulation; in this case, just the stationary radar.
Set Up the Tracking Algorithm
For this example, we will be using the JPDA algorithm to perform “soft” associations of the measurements to the targets. This is necessary as we have multiple airborne targets whose paths may intersect - a “hard” or “greedy” association algorithm such as the GNN may have issues in these cases.
First, we create a Kalman predictor using the transition model from the target simulation. In real situations, you may not know the actual transition model.
Next, we define a measurement model for the Kalman updater. Here we have altered the noise covariance matrix slightly to make it harder for the tracker.
Using the measurement model, we make a Kalman updater which we will pass into our JPDA tracker.
The hypothesiser will assume that there is a 95% chance to measure any given target at any given timestep. In real life, this probability is based on the SNR of the target signals. The clutter spatial density of the hypothesiser can be changed to check what happens when there is a mismatch between the estimated clutter rate and actual clutter rate.
Using the hypothesiser, we can make a data associator. Other MTT algorithms may use different association algorithms (like GNN)
We implement a simple deleter algorithm to delete tracks if no measurements have fallen within the JPDA gating region in 3 time steps.
We will now set up a track initiator. In real life, targets may enter the measurement zone at any time during the collection period, and may leave at any point as well. To distinguish new targets from random clutter, we use a track initiator. This specific algorithm is a multi-measurement initiator; it utilises features of the tracker to initiate and hold tracks temporarily within the initiator itself, releasing them to the tracker once there are multiple detections associated with them enough to determine that they are “sure” tracks. In this case, the tracks are released after 3 appropriate detections in a row.
from stonesoup.initiator.simple import MultiMeasurementInitiator from stonesoup.dataassociator.neighbour import NearestNeighbour min_detections = 3 # number of detections required to begin a track initiator_prior_state = GaussianState( state_vector=np.array([, , , , , ]), covar=np.diag([0, 10, 0, 10, 0, 10])**2 ) initiator_meas_model = CartesianToElevationBearingRange( ndim_state=6, mapping=np.array([0, 2, 4]), noise_covar=noise_covar ) initiator = MultiMeasurementInitiator( prior_state=initiator_prior_state, measurement_model=meas_model, deleter=deleter, data_associator=NearestNeighbour(hypothesiser), updater=updater, min_points=min_detections, updates_only=True )
Now we are ready to Create a JPDA multi-target tracker.
Run the Simulation and Tracker
Since the JPDA tracker holds the simulation variables, we can easily iterate through the tracker. Each time it will update the groundtruth simulation, generate detections using our fixed platform and radar, and run the tracking algorithm.
# Create lists to hold the information we want to plot later tracks_plot = set() tracks_id = set() groundtruth_plot = set() detections_plot = set() # Run the simulation and tracker for time, ctracks in JPDA_tracker: print(time) # allows us to see the progress of the tracking simulation for track in ctracks: tracks_plot.add(track) for truth in groundtruth_sim.current: groundtruth_plot.add(truth) for detection in sim.detections: detections_plot.add(detection)
2023-03-03 07:48:47.030694 2023-03-03 07:48:48.030694 2023-03-03 07:48:49.030694 2023-03-03 07:48:50.030694 2023-03-03 07:48:51.030694 2023-03-03 07:48:52.030694 2023-03-03 07:48:53.030694 2023-03-03 07:48:54.030694 2023-03-03 07:48:55.030694 2023-03-03 07:48:56.030694 2023-03-03 07:48:57.030694 2023-03-03 07:48:58.030694 2023-03-03 07:48:59.030694 2023-03-03 07:49:00.030694 2023-03-03 07:49:01.030694 2023-03-03 07:49:02.030694 2023-03-03 07:49:03.030694 2023-03-03 07:49:04.030694 2023-03-03 07:49:05.030694 2023-03-03 07:49:06.030694 2023-03-03 07:49:07.030694 2023-03-03 07:49:08.030694 2023-03-03 07:49:09.030694 2023-03-03 07:49:10.030694 2023-03-03 07:49:11.030694 2023-03-03 07:49:12.030694 2023-03-03 07:49:13.030694 2023-03-03 07:49:14.030694 2023-03-03 07:49:15.030694 2023-03-03 07:49:16.030694 2023-03-03 07:49:17.030694 2023-03-03 07:49:18.030694 2023-03-03 07:49:19.030694 2023-03-03 07:49:20.030694 2023-03-03 07:49:21.030694 2023-03-03 07:49:22.030694 2023-03-03 07:49:23.030694 2023-03-03 07:49:24.030694 2023-03-03 07:49:25.030694 2023-03-03 07:49:26.030694 2023-03-03 07:49:27.030694 2023-03-03 07:49:28.030694 2023-03-03 07:49:29.030694 2023-03-03 07:49:30.030694 2023-03-03 07:49:31.030694 2023-03-03 07:49:32.030694 2023-03-03 07:49:33.030694 2023-03-03 07:49:34.030694 2023-03-03 07:49:35.030694 2023-03-03 07:49:36.030694 2023-03-03 07:49:37.030694 2023-03-03 07:49:38.030694 2023-03-03 07:49:39.030694 2023-03-03 07:49:40.030694 2023-03-03 07:49:41.030694 2023-03-03 07:49:42.030694 2023-03-03 07:49:43.030694 2023-03-03 07:49:44.030694 2023-03-03 07:49:45.030694 2023-03-03 07:49:46.030694 2023-03-03 07:49:47.030694 2023-03-03 07:49:48.030694 2023-03-03 07:49:49.030694 2023-03-03 07:49:50.030694 2023-03-03 07:49:51.030694 2023-03-03 07:49:52.030694 2023-03-03 07:49:53.030694 2023-03-03 07:49:54.030694 2023-03-03 07:49:55.030694 2023-03-03 07:49:56.030694 2023-03-03 07:49:57.030694 2023-03-03 07:49:58.030694 2023-03-03 07:49:59.030694 2023-03-03 07:50:00.030694 2023-03-03 07:50:01.030694 2023-03-03 07:50:02.030694 2023-03-03 07:50:03.030694 2023-03-03 07:50:04.030694 2023-03-03 07:50:05.030694 2023-03-03 07:50:06.030694 2023-03-03 07:50:07.030694 2023-03-03 07:50:08.030694 2023-03-03 07:50:09.030694 2023-03-03 07:50:10.030694 2023-03-03 07:50:11.030694 2023-03-03 07:50:12.030694 2023-03-03 07:50:13.030694 2023-03-03 07:50:14.030694 2023-03-03 07:50:15.030694 2023-03-03 07:50:16.030694 2023-03-03 07:50:17.030694 2023-03-03 07:50:18.030694 2023-03-03 07:50:19.030694 2023-03-03 07:50:20.030694 2023-03-03 07:50:21.030694 2023-03-03 07:50:22.030694 2023-03-03 07:50:23.030694 2023-03-03 07:50:24.030694 2023-03-03 07:50:25.030694 2023-03-03 07:50:26.030694 2023-03-03 07:50:27.030694 2023-03-03 07:50:28.030694 2023-03-03 07:50:29.030694 2023-03-03 07:50:30.030694 2023-03-03 07:50:31.030694 2023-03-03 07:50:32.030694 2023-03-03 07:50:33.030694 2023-03-03 07:50:34.030694 2023-03-03 07:50:35.030694 2023-03-03 07:50:36.030694 2023-03-03 07:50:37.030694 2023-03-03 07:50:38.030694 2023-03-03 07:50:39.030694 2023-03-03 07:50:40.030694 2023-03-03 07:50:41.030694 2023-03-03 07:50:42.030694 2023-03-03 07:50:43.030694 2023-03-03 07:50:44.030694 2023-03-03 07:50:45.030694 2023-03-03 07:50:46.030694
Plot the Results
Now that all of the relevant information has been extracted, the results can
be plotted using the 3D plotting functionality provided by the
[<mpl_toolkits.mplot3d.art3d.Line3D object at 0x7f7b2f1e6990>, <mpl_toolkits.mplot3d.art3d.Line3D object at 0x7f7b2f14d1d0>, <matplotlib.legend.Legend object at 0x7f7b2fc30390>]
We will also make a plot without measurements/clutter to better see the tracks.
[<mpl_toolkits.mplot3d.art3d.Line3D object at 0x7f7b2f31cbd0>, <mpl_toolkits.mplot3d.art3d.Line3D object at 0x7f7b2f31e150>, <mpl_toolkits.mplot3d.art3d.Line3D object at 0x7f7b2fa41790>, <mpl_toolkits.mplot3d.art3d.Line3D object at 0x7f7b2fc7d150>, <mpl_toolkits.mplot3d.art3d.Line3D object at 0x7f7b2fc7c050>, <mpl_toolkits.mplot3d.art3d.Line3D object at 0x7f7b2f9b35d0>, <mpl_toolkits.mplot3d.art3d.Line3D object at 0x7f7b2fc7dc50>, <mpl_toolkits.mplot3d.art3d.Line3D object at 0x7f7b2fc7e690>, <matplotlib.legend.Legend object at 0x7f7b2f478fd0>]
To analyse the tracker performance, we will use the OSPA, SIAP, and uncertainty metrics. For each of these metrics, we make a generator object which gets put into a metric manager.
# OSPA metric from stonesoup.metricgenerator.ospametric import OSPAMetric ospa_generator = OSPAMetric(c=40, p=1) # SIAP metrics from stonesoup.metricgenerator.tracktotruthmetrics import SIAPMetrics from stonesoup.measures import Euclidean SIAPpos_measure = Euclidean(mapping=np.array([0, 2])) SIAPvel_measure = Euclidean(mapping=np.array([1, 3])) siap_generator = SIAPMetrics( position_measure=SIAPpos_measure, velocity_measure=SIAPvel_measure ) # Uncertainty metric from stonesoup.metricgenerator.uncertaintymetric import \ SumofCovarianceNormsMetric uncertainty_generator = SumofCovarianceNormsMetric()
The metric manager requires us to define an associator. Here we want to compare the track estimates with the ground truth.
Since we saved the groundtruth and tracks before, we can easily add them to the metric manager now, and then tell it to generate the metrics.
The first metric we will look at is the OSPA metric.
Next are the SIAP metrics. Specifically, we will look at the position and velocity accuracy.
position_accuracy = metrics['SIAP Position Accuracy at times'] velocity_accuracy = metrics['SIAP Velocity Accuracy at times'] times = metric_manager.list_timestamps() # Make a figure with 2 subplots. fig, axes = plt.subplots(2) # The first subplot will show the position accuracy axes.set(title='Positional Accuracy Over Time', xlabel='Time', ylabel='Accuracy') axes.plot(times, [metric.value for metric in position_accuracy.value]) # The second subplot will show the velocity accuracy axes.set(title='Velocity Accuracy Over Time', xlabel='Time', ylabel='Accuracy') axes.plot(times, [metric.value for metric in velocity_accuracy.value]) plt.tight_layout()
Finally, we will examine a general uncertainty metric. This is calculated as the sum of the norms of the covariance matrices of each estimated state. Since the sum is not normalized for the number of estimated states, it is most important to look at the trends of this graph rather than the values.
Total running time of the script: ( 0 minutes 2.313 seconds)