Visualization#

Asynchronous plot consumer and radar plotter. Runs in a background thread to keep visualization off the critical processing path.

Radar segmentation and projection visualization.

Renders reflectivity + cell segmentation + motion projections to PNG. Supports threaded queue-based processing for pipeline integration.

class adapt.visualization.plotter.PlotConsumer(collection, run_id, stop_event, output_dir, config=None, poll_interval=2.0, show_live=False, name='PlotConsumer')#

Bases: Thread

Store-driven plot consumer thread.

Polls the collection catalog for new analysis artifacts and generates visualizations. This consumer is completely decoupled from the processing pipeline — it only reads from the store, and plots are written to a user-directed directory OUTSIDE the store root.

Graceful Shutdown:

Call stop() to signal shutdown. The thread will complete any in-progress plot and exit cleanly within one poll_interval.

Parameters:
  • run_id (str)

  • stop_event (Event)

  • output_dir (Path)

  • config (InternalConfig | None)

  • poll_interval (float)

  • show_live (bool)

  • name (str)

run()#

Main consumer loop - poll repository and generate plots.

stop()#

Signal consumer to stop.

class adapt.visualization.plotter.RadarPlotter(config=None, show_plots=False)#

Bases: object

Generates segmentation and projection visualizations from radar data.

Renders publication-quality PNG plots showing:

  • Left Panel: Reflectivity field with optical flow vectors (motion field)

  • Right Panel: Segmented storm cells with projected future positions

Reflectivity Display:

Uses dBZ color scale (ChaseSpectral colormap). Values below minimum threshold masked out. Optional basemap overlay shows geographic context (OpenStreetMap).

Cell Segmentation Overlay:

Thin black contours outline detected cells in right panel. Cell ID labeling can be configured. Cells shown only where reflectivity exceeds minimum threshold.

Motion Projections:

Colored contours show predicted cell positions at future timesteps (1-5 steps ahead). Line style and alpha transparency decrease with projection distance (recent projections more opaque, distant projections faint).

Configuration:

All appearance settings (DPI, figure size, colors, thresholds) controlled via config[“visualization”] section. Enables consistent multi-radar visualization without code changes.

Output:

Saves PNG to plots/{radar}_{scan_time}_{plot_type}.png by default. Supports custom paths and output formats (PNG, PDF, etc).

Example usage:

plotter = RadarPlotter(config=config)
plot_path = plotter.plot_from_netcdf(
    segmentation_nc="analysis/KDIX_20250305_000310_analysis_segmentation.nc",
    output_path="plots/KDIX_20250305_000310.png"
)
print(f"Plot saved to {plot_path}")
Parameters:
plot_from_netcdf(segmentation_nc, output_path=None)#

Load analysis NetCDF and generate visualization.

Waits for file with retries (handles processor write delays).

Parameters:
  • segmentation_nc (Path) – Path to analysis NetCDF with segmentation and projections.

  • output_path (Path | None) – Output PNG path. Auto-generated if None.

Returns:

Path to saved PNG file.

Return type:

str

plot_reflectivity_with_cells(ds, frame_offset=0, output_path=None)#

Generate publication-quality two-panel radar visualization.

Creates side-by-side plots: (left) reflectivity with optical flow vectors, (right) segmented cells with motion projections. Useful for understanding cell behavior, motion patterns, and validation of segmentation.

Left Panel: - Background: Reflectivity field (dBZ scale, ChaseSpectral colormap) - Overlay: Optical flow vectors (motion estimation between frames) - Optional: OpenStreetMap basemap for geographic reference - Vectors scaled by flow_scale config, subsampled for clarity

Right Panel: - Background: Reflectivity (masked to segmented cells only) - Overlay (black contours): Current segmentation (frame N) - Overlay (gray contours): Projections (frame N+1 through N+5) - Projection contours fade with distance (recent more opaque)

Data Requirements:

Input dataset must contain: - reflectivity: 2D array - cell_labels: 2D integer array (0 = background, 1+ = cell IDs) - heading_x, heading_y: 2D flow vectors (optional, frame 1 has no flow) - cell_projections: 3D array [frame_offset, y, x] (optional, frame 1 lacks)

Parameters:
  • ds (Dataset) – Analysis dataset from RadarProcessor output. Must have reflectivity, cell_labels. Optionally has heading_x/heading_y and cell_projections.

  • frame_offset (int) – Frame offset for multi-frame plots (reserved for future enhancement). Currently unused (default: 0).

  • output_path (Path | None) – Output PNG path. If None, auto-generates in /tmp with timestamp.

Returns:

Path to saved PNG file (ready for web display or reports).

Return type:

str

Notes

Processing time: 1-3 seconds per frame on typical hardware. File size: typically 200-500 KB per PNG at default DPI.