Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filters zhaw #327

Merged
merged 20 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ to be applied on every :class:`~traffic.core.Flight` in the collection
and stack them before triggering only one iteration.

.. toctree::
:maxdepth: 1

api_reference/traffic.core.aero
api_reference/traffic.core.airspace
Expand All @@ -39,3 +40,4 @@ and stack them before triggering only one iteration.
api_reference/traffic.core.sv
api_reference/traffic.core.time
api_reference/traffic.core.traffic
api_reference/traffic.algorithms.filters
93 changes: 93 additions & 0 deletions docs/api_reference/traffic.algorithms.filters.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
traffic.algorithms.filters
==========================

.. jupyter-execute::
:hide-output:
:hide-code:

import altair as alt
from traffic.core import Flight
from traffic.data.samples import noisy

raw_data = noisy.assign(type="raw data")
default = noisy.filter("default").assign(type="default")
aggressive = noisy.filter("aggressive").assign(type="aggressive")

domain = ["raw data", "default", "aggressive"]

features = [
"altitude (in ft)",
"track angle (in deg)",
"vertical_rate (in ft/min)",
"groundspeed (in kts)",
]


def chart(filtered: "Flight", titles: list[str] = features) -> alt.Chart:
def y_channel(title: str):
return alt.Y(title.split()[0], scale=alt.Scale(zero=False), title=None)

color_channel = alt.Color(
"type",
scale=alt.Scale(domain=domain),
legend=alt.Legend(title="Filter type"),
)
reference = raw_data.chart()
compared = filtered.chart()
return (
alt.vconcat(
alt.concat(
alt.layer(
reference.encode(y_channel(titles[0]), color_channel),
compared.encode(y_channel(titles[0]), color_channel),
).properties(width=300, height=150, title=titles[0]),
alt.layer(
reference.encode(y_channel(titles[1]), color_channel),
compared.encode(y_channel(titles[1]), color_channel),
).properties(width=300, height=150, title=titles[1]),
),
alt.concat(
alt.layer(
reference.encode(y_channel(titles[2]), color_channel),
compared.encode(y_channel(titles[2]), color_channel),
).properties(width=300, height=150, title=titles[2]),
alt.layer(
reference.encode(y_channel(titles[3]), color_channel),
compared.encode(y_channel(titles[3]), color_channel),
).properties(width=300, height=150, title=titles[3]),
),
)
.configure_axisX(format="%H:%M", title=None, labelFontSize=12)
.configure_axisY(labelFontSize=12)
.configure_legend(orient="bottom", labelFontSize=14, titleFontSize=14)
.configure_title(anchor="start", fontSize=16)
)

traffic comes with some pre-implemented filters to be passed to the
:meth:`~traffic.core.Flight.filter` method. The method takes either a
:class:`~traffic.algorithms.filters.FilterBase` instance, or a string parameter:

- ``"default"`` is a relatively fast option with decent performance on
trajectories extracted from the OpenSky database (with their most common
glitches)

.. jupyter-execute::
:hide-code:

chart(default)

- ``"aggressive"`` is a composition of several filters which may result in
smoother trajectories.

.. jupyter-execute::
:hide-code:

chart(aggressive)


API reference
-------------

.. automodule:: traffic.algorithms.filters
:members:
:show-inheritance:
Loading