Polygon Module
Interactive polygon-based filtering utilities for linked scientific plots.
This module provides the PolygonFilter class, which enables
click-driven polygon selection across multiple coordinated views such
as time-altitude, longitude-altitude, longitude-latitude, and
altitude-latitude plots. Users can draw polygons or ranges directly
on the plots, and the module computes corresponding boolean masks for
both the main dataset and a supplementary GSD dataset.
The module also handles updating plot visuals, hiding GS or CC layers when they become empty, and writing updated masks back into the application state.
- class polygon.PolygonFilter(obj, remove=False)[source]
Bases:
objectInteractive polygon-based filter for coordinated scientific visualizations.
The
PolygonFilterclass listens for mouse events across several linked views, records user clicks, renders temporary polygon shapes, and computes selection masks based on either range constraints or true 2D polygon inclusion tests. The resulting masks are used to filter both the main trajectory dataset and a secondary GSD dataset (GS/CC types), with full visual updates applied when requested.The class supports both inclusion and exclusion modes and integrates with an external application that provides
uiandstateobjects. It assumes the UI exposes view widgets (v0,v1,v3,v4), point-drawing objects (pd*andpl*), and GS/CC visual objects (gs*andcc*). Filtering results are written back toobj.state.updatealong with visualization changes.- Parameters:
obj (Any, optional) – Parent object that must define
uiandstateattributes, whereuiprovides the plotting widgets andstateholds boolean masks and pandas data. IfNone, event registration will not occur.remove (bool, default False) – If True, polygon selection excludes (removes) points from the mask; otherwise it includes points.
- obj
Parent application object containing
uiandstate.- Type:
Any or None
- ui
UI container providing plot canvases, views, and visual elements.
- Type:
Any
- remove
Whether polygon selection removes points instead of including them.
- Type:
bool
- prev_ax
The last active view index where clicking occurred.
- Type:
int or None
- clicks
Accumulated polygon vertices in the active view.
- Type:
list of tuple of float
- view_index
Currently active view for receiving click events.
- Type:
int or None
- handle_poly_plot()[source]
Update the temporary polygon drawing in the active view.
This draws the clicked vertices as red dots and, once at least two points exist, draws the connecting red lines. Clears visuals if no points remain.
- Return type:
None
- on_click(event, view_index)[source]
Handle a mouse click event on one of the linked views.
This records the click position, updates temporary polygon drawings, and when a right-click completes a polygon, triggers filtering.
This is intended to be connected to a VisPy canvas
- Parameters:
event (Any) – Mouse event containing
posandbuttonattributes.view_index (int) – Index of the plot/view where the click occurred.
- Return type:
None
- polygon(num, update=False)[source]
Compute a polygon-based mask for the active plot, and optionally update all visuals and the application state.
Depending on the active view, the selection is interpreted as a range filter (time-altitude, lon-altitude, alt-latitude) or a 2D polygon (lon-latitude). When
update=True, the method updates plot masks, GSD masks, and redraws GS/CC visuals.- Parameters:
num (int) – Identifier of the active plot type (e.g. TIME_ALT_PLOT).
update (bool, default False) – If True, apply the masks to
obj.stateand update visuals.
- Returns:
Returns the boolean mask for the plot when
update=False. Returns None when applying updates.- Return type:
ndarray or None