40 lines
1.8 KiB
Python
40 lines
1.8 KiB
Python
"""Plot construction and color tables shared by radar views."""
|
|
|
|
import numpy as np
|
|
import pyqtgraph as pg
|
|
|
|
from python_app.models.run_config_schema import GprModel
|
|
from python_app.models.run_config_validation import parse_position_csv
|
|
from python_app.gui.theme import PLOT_BACKGROUND
|
|
|
|
|
|
def create_plot(title: str = "") -> pg.PlotWidget:
|
|
plot = pg.PlotWidget(background=PLOT_BACKGROUND, 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
|
|
|
|
|
|
# Same Tx/Rx markers on ground BP and the three planar SAR views.
|
|
ANTENNA_STYLES = (("t", "#ff595e", "#ffca3a"), ("t1", "#4cc9f0", "#e0fbfc"))
|
|
|
|
|
|
def selected_antenna_coordinates(geometry: GprModel, inputs: str, outputs: str) -> tuple[np.ndarray, np.ndarray]:
|
|
selected_inputs, selected_outputs = parse_position_csv(inputs), parse_position_csv(outputs)
|
|
tx = [[row.x_m, row.y_m, row.z_m] for row in geometry.tx_geometry
|
|
if not selected_outputs or row.output_pos in selected_outputs]
|
|
rx = [[row.x_m, row.y_m, row.z_m] for row in geometry.rx_geometry
|
|
if not selected_inputs or row.input_pos in selected_inputs]
|
|
return np.asarray(tx, dtype=float).reshape(-1, 3), np.asarray(rx, dtype=float).reshape(-1, 3)
|