68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
"""Helpers for extracting GPR objects from result collections.
|
|
|
|
Locator TCP delivery now lives in the C++ data_processor. This module retains
|
|
only the inspection helpers that the GUI uses for plotting.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
|
|
from python_app.models.dataset_model import ResultCollection, ResultPayload
|
|
|
|
|
|
def collection_payload_by_name(
|
|
collection: ResultCollection,
|
|
name: str,
|
|
kind: int | None = None,
|
|
) -> ResultPayload | None:
|
|
"""Return the first collection payload matching name and optional kind."""
|
|
for payload in collection.collection_payloads:
|
|
if payload.processing_name != name:
|
|
continue
|
|
if kind is not None and int(payload.kind) != int(kind):
|
|
continue
|
|
return payload
|
|
return None
|
|
|
|
|
|
def collection_payloads_by_prefix(
|
|
collection: ResultCollection,
|
|
prefix: str,
|
|
kind: int | None = None,
|
|
) -> list[ResultPayload]:
|
|
"""Return collection payloads matching a processing-name prefix."""
|
|
payloads: list[ResultPayload] = []
|
|
for payload in collection.collection_payloads:
|
|
if not str(payload.processing_name).startswith(prefix):
|
|
continue
|
|
if kind is not None and int(payload.kind) != int(kind):
|
|
continue
|
|
payloads.append(payload)
|
|
return payloads
|
|
|
|
|
|
def collection_has_gpr_payloads(collection: ResultCollection) -> bool:
|
|
"""Return whether collection carries GPR-specific collection payloads."""
|
|
return any(
|
|
str(payload.processing_name).startswith("gpr_")
|
|
for payload in collection.collection_payloads
|
|
)
|
|
|
|
|
|
def gpr_object_rows(collection: ResultCollection) -> np.ndarray:
|
|
"""Return object rows as `[x_m, z_m, score]` from a GPR collection."""
|
|
points_payload = collection_payload_by_name(collection, "gpr_points", kind=4)
|
|
if points_payload is not None:
|
|
points = np.asarray(points_payload.table, dtype=np.float32)
|
|
if points.ndim == 2 and points.shape[1] >= 3:
|
|
return points[:, :3]
|
|
|
|
centers_payload = collection_payload_by_name(collection, "gpr_region_centers", kind=4)
|
|
if centers_payload is not None:
|
|
centers = np.asarray(centers_payload.table, dtype=np.float32)
|
|
if centers.ndim == 2 and centers.shape[1] >= 3:
|
|
return centers[:, :3]
|
|
|
|
return np.zeros((0, 3), dtype=np.float32)
|