24 lines
886 B
Python
24 lines
886 B
Python
"""Plot construction and color tables shared by radar views."""
|
|
|
|
import numpy as np
|
|
import pyqtgraph as pg
|
|
|
|
|
|
def create_plot(title: str = "") -> pg.PlotWidget:
|
|
plot = pg.PlotWidget(background="#0f141c", enableMenu=False, title=title)
|
|
plot.showGrid(x=True, y=True, alpha=0.2)
|
|
return plot
|
|
|
|
|
|
def build_lut(stops: list[str], *, size: int = 256) -> np.ndarray:
|
|
"""Interpolate hex color stops into 8-bit RGB LUT array."""
|
|
stop_positions = np.linspace(0.0, 1.0, num=len(stops), dtype=np.float32)
|
|
sample_positions = np.linspace(0.0, 1.0, num=size, dtype=np.float32)
|
|
stop_colors = np.asarray([pg.mkColor(value).getRgb()[:3] for value in stops], dtype=np.float32)
|
|
|
|
lut = np.empty((size, 3), dtype=np.uint8)
|
|
for channel in range(3):
|
|
lut[:, channel] = np.interp(sample_positions, stop_positions, stop_colors[:, channel]).astype(np.uint8)
|
|
return lut
|
|
|