feat(perception): map vegetation provider labels
This commit is contained in:
@@ -9,6 +9,7 @@ from pathlib import Path
|
||||
from typing import Any, Final
|
||||
|
||||
SCHEMA: Final = "missioncore.vegetation-mission-policy/v1"
|
||||
PROVIDER_MAP_SCHEMA: Final = "missioncore.vegetation-provider-label-map/v1"
|
||||
VEHICLE_SCHEMA: Final = "missioncore.m49-physical-safety-shadow-profile/v1"
|
||||
_MAX_JSON_BYTES: Final = 1024 * 1024
|
||||
|
||||
@@ -163,6 +164,64 @@ def load_vegetation_mission_policy(
|
||||
return policy
|
||||
|
||||
|
||||
def load_vegetation_provider_label_map(
|
||||
path: Path,
|
||||
*,
|
||||
policy: dict[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
"""Load the provider-label adapter without inventing material claims."""
|
||||
|
||||
label_map = _json(path, "vegetation provider label map")
|
||||
providers = label_map.get("providers")
|
||||
invariants = label_map.get("invariants")
|
||||
if (
|
||||
label_map.get("schema_version") != PROVIDER_MAP_SCHEMA
|
||||
or label_map.get("policy_profile_id") != policy.get("profile_id")
|
||||
or not isinstance(providers, dict)
|
||||
or not providers
|
||||
or not isinstance(invariants, dict)
|
||||
or any(value is not False for value in invariants.values())
|
||||
):
|
||||
raise VegetationMissionPolicyError("provider label map identity changed")
|
||||
|
||||
materials = set(policy["material_classes"])
|
||||
for provider_id, provider in providers.items():
|
||||
if not isinstance(provider_id, str) or not isinstance(provider, dict):
|
||||
raise VegetationMissionPolicyError("provider label map is invalid")
|
||||
labels = provider.get("labels")
|
||||
if (
|
||||
provider.get("unmapped_policy") != "no-material-claim"
|
||||
or not isinstance(provider.get("class_granularity"), str)
|
||||
or not isinstance(provider.get("can_distinguish_low_and_high_grass"), bool)
|
||||
or not isinstance(provider.get("can_distinguish_tree_trunk"), bool)
|
||||
or not isinstance(labels, dict)
|
||||
or any(
|
||||
not isinstance(label, str)
|
||||
or not label
|
||||
or not isinstance(material, str)
|
||||
or material not in materials
|
||||
for label, material in labels.items()
|
||||
)
|
||||
):
|
||||
raise VegetationMissionPolicyError(f"provider label map is invalid: {provider_id}")
|
||||
return label_map
|
||||
|
||||
|
||||
def map_provider_material(
|
||||
label_map: dict[str, Any],
|
||||
*,
|
||||
provider_id: str,
|
||||
provider_label: str,
|
||||
) -> str | None:
|
||||
"""Return an exact material claim, or none when the provider did not make one."""
|
||||
|
||||
provider = label_map["providers"].get(provider_id)
|
||||
if not isinstance(provider, dict):
|
||||
raise VegetationMissionPolicyError(f"unknown vegetation provider: {provider_id}")
|
||||
material = provider["labels"].get(provider_label)
|
||||
return material if isinstance(material, str) else None
|
||||
|
||||
|
||||
def resolve_terrain_policy(
|
||||
policy: dict[str, Any],
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user