Skip to content

Commit f670d1a

Browse files
committed
examples for kalman filters
1 parent 1cf10d6 commit f670d1a

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

docs/api_reference/traffic.algorithms.filters.rst

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ traffic.algorithms.filters
1313
default = noisy_landing.filter("default").assign(type="default")
1414
aggressive = noisy_landing.filter("aggressive").assign(type="aggressive")
1515

16-
domain = ["raw data", "default", "aggressive"]
16+
domain = ["raw data", "default", "aggressive", "Kalman filter", "Kalman smoother"]
1717

1818
features = [
1919
"altitude (in ft)",
@@ -71,6 +71,10 @@ traffic comes with some pre-implemented filters to be passed to the
7171
trajectories extracted from the OpenSky database (with their most common
7272
glitches)
7373

74+
.. code:: python
75+
76+
noisy_landing.filter()
77+
7478
.. jupyter-execute::
7579
:hide-code:
7680

@@ -79,11 +83,55 @@ traffic comes with some pre-implemented filters to be passed to the
7983
- ``"aggressive"`` is a composition of several filters which may result in
8084
smoother trajectories.
8185

86+
.. code:: python
87+
88+
noisy_landing.filter("aggressive")
89+
8290
.. jupyter-execute::
8391
:hide-code:
8492

8593
chart(aggressive)
8694

95+
- :class:`~traffic.algorithms.filters.kalman.KalmanFilter6D` is a Kalman filter
96+
applied to the 6D state vector (latitude, longitude, altitude, track angle,
97+
groundspeed, vertical rate)
98+
99+
.. code:: python
100+
101+
from traffic.algorithms.filters.kalman import KalmanFilter6D
102+
103+
# The Kalman filter needs first a projection in x, y
104+
from cartes.crs import EuroPP
105+
106+
noisy_landing.compute_xy(EuroPP()).filter(KalmanFilter6D())
107+
108+
.. jupyter-execute::
109+
:hide-code:
110+
111+
from traffic.algorithms.filters.kalman import KalmanFilter6D
112+
113+
noisy_landing_xy = noisy_landing.compute_xy()
114+
kalman = noisy_landing_xy.filter(KalmanFilter6D()).assign(type="Kalman filter")
115+
chart(kalman)
116+
117+
- :class:`~traffic.algorithms.filters.kalman.KalmanSmoother6D` is a Kalman
118+
smoother (a two-pass filter averaging the covariance of the errors on both
119+
sides) applied to the 6D state vector (latitude, longitude, altitude, track
120+
angle, groundspeed, vertical rate)
121+
122+
.. code:: python
123+
124+
from traffic.algorithms.filters.kalman import KalmanSmoother6D
125+
126+
noisy_landing.compute_xy(EuroPP()).filter(KalmanSmoother6D())
127+
128+
.. jupyter-execute::
129+
:hide-code:
130+
131+
from traffic.algorithms.filters.kalman import KalmanSmoother6D
132+
133+
smoother = noisy_landing_xy.filter(KalmanSmoother6D()).assign(type="Kalman smoother")
134+
chart(smoother)
87135

88136
API reference
89137
-------------

src/traffic/algorithms/filters/kalman.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def apply(self, data: pd.DataFrame) -> pd.DataFrame:
440440
x2_cor = np.array(self.tracked_variables["x2_cor"][::-1])
441441
p2_cor = np.array(self.tracked_variables["p2_cor"][::-1])
442442

443-
for i in range(1, df.shape[0]):
443+
for i in range(df.shape[0]):
444444
s1 = np.linalg.inv(p1_cor[i])
445445
s2 = np.linalg.inv(p2_cor[i])
446446
self.ps = np.linalg.inv(s1 + s2)

src/traffic/data/samples/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def assign_id(t: Union[Traffic, Flight], name: str) -> Union[Traffic, Flight]:
6666
full_flight_short: Flight
6767
lfbo_tma: Airspace
6868
noisy: Flight
69+
noisy_landing: Flight
6970
quickstart: Traffic
7071
landing_denver: Flight
7172
sample_dump1090: Path

0 commit comments

Comments
 (0)