Source code for openworld_radio_twin.providers.base
from dataclasses import dataclass, field
from openworld_radio_twin.models import AntennaFeature, BuildingFeature, Channel, ChannelRange
SCENE_BOUNDARY_POLICY = "fully_contained_in_square_enu_domain"
ANTENNA_BOUNDARY_POLICY = "inside_square_enu_domain"
[docs]
class BuildingProviderError(RuntimeError):
"""A remote building provider could not return a valid query result."""
[docs]
class AntennaProviderError(RuntimeError):
"""An antenna source could not return a valid query result."""
[docs]
@dataclass(frozen=True)
class BuildingQueryResult:
"""Building records of one source; ``license``, ``license_url`` and ``attribution`` are
filled from the source that answered by ``MapDataProvider.buildings``.
``source_datasets`` lists the upstream datasets that the fetched records name, each with
the licence as given and the number of records naming it; it is empty for sources that
name none.
"""
buildings: list[BuildingFeature]
provider: str
release: str | None = None
warnings: list[str] = field(default_factory=list)
boundary_excluded_count: int = 0
source_selection: dict[str, object] = field(default_factory=dict)
license: str = ""
license_url: str = ""
attribution: str = ""
source_datasets: list[dict[str, object]] = field(default_factory=list)
@property
def source_count(self) -> int:
return len(self.buildings) + self.boundary_excluded_count
@property
def source_provenance(self) -> dict[str, str]:
"""Flat source identity for HTTP and per-radio-map provenance records."""
return {
f"building_source_{key}": str(value) for key, value in self.source_selection.items()
}
[docs]
@dataclass(frozen=True)
class AntennaQueryResult:
"""Antenna records of one source; ``attribution``, ``license`` and ``license_url`` travel
with the data.
``channels`` lists the downlink channels the antennas of the scene or area register,
before any selection; ``channel`` is the selected one, whose ``centre_hz`` and
``bandwidth_hz`` are the values of Sionna's ``scene.frequency`` and ``scene.bandwidth``.
"""
antennas: list[AntennaFeature]
provider: str
release: str | None = None
warnings: list[str] = field(default_factory=list)
boundary_excluded_count: int = 0
source_selection: dict[str, object] = field(default_factory=dict)
attribution: str = ""
license: str = ""
license_url: str = ""
channels: list[Channel] = field(default_factory=list)
channel: ChannelRange | None = None
@property
def source_provenance(self) -> dict[str, str]:
"""Flat source identity for HTTP and per-radio-map provenance records."""
return {f"antenna_source_{key}": str(value) for key, value in self.source_selection.items()}