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: object

Interactive polygon-based filter for coordinated scientific visualizations.

The PolygonFilter class 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 ui and state objects. It assumes the UI exposes view widgets (v0, v1, v3, v4), point-drawing objects (pd* and pl*), and GS/CC visual objects (gs* and cc*). Filtering results are written back to obj.state.update along with visualization changes.

Parameters:
  • obj (Any, optional) – Parent object that must define ui and state attributes, where ui provides the plotting widgets and state holds boolean masks and pandas data. If None, 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 ui and state.

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 pos and button attributes.

  • 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.state and update visuals.

Returns:

Returns the boolean mask for the plot when update=False. Returns None when applying updates.

Return type:

ndarray or None

update_filter(new)[source]

Set whether polygon selection includes or excludes points.

Parameters:

new (bool) – If True, selected points are removed instead of included.

Return type:

None