Skip to content

Python tool for aircraft Doppler audio geolocation using historical ADS-B flight data (Source-available)

Add Spain search profile (#368)

Cinna Davis675c9295c960
diff --git a/docs/COUNTRIES.md b/docs/COUNTRIES.md
index ca94a1d..d721d35 100644
--- a/docs/COUNTRIES.md
+++ b/docs/COUNTRIES.md
@@ -1,17 +1,22 @@
# Country profiles
-The automatic request, CLI and upload interface support two receiver regions:
+The automatic request and upload interface support three receiver regions:
| Country | Coverage | Envelope: west, south, east, north | Search CRS | Receiver region |
| --- | --- | --- | --- | --- |
| `US` | `conus` | `-125, 24, -66, 50` | `EPSG:5070` | Existing CONUS rectangle |
| `DE` | `germany` | `5.5, 47, 15.5, 55.2` | `EPSG:32632` | BKG VG250 Germany land polygon inside the envelope |
+| `ES` | `spain` | `-18.2, 27.5, 4.5, 43.9` | `EPSG:6933` | Spain and territories bounding envelope; no country polygon |
The envelope limits optional rectangular subsets. Germany's envelope includes
foreign territory; the land polygon removes those receiver locations before
terrain sampling or scoring. Islands, exclaves and polygon holes are preserved.
The boundary is generalized geographic data, not a survey of a microphone site.
-Country support does not establish German localization accuracy.
+Spain uses an outer envelope covering mainland Spain and its island territories.
+It does not apply a Spanish land mask, so a search must provide explicit bounds
+that describe the intended receiver area. Aircraft outside the receiver bounds
+remain eligible when they are within the acoustic search margin. Country support
+does not establish localization accuracy.
## Requests and commands
@@ -21,8 +26,9 @@ dopplergeist analyze recording.mp3 --country DE --jobs jobs --online \
--time-source 'Evidence establishing the recording-start interval'
```
-The upload API accepts `"search":{"country":"DE"}`. It also accepts
-`"search":{"coverage":"germany"}`. A normalized request records the coverage;
+The upload API accepts `"search":{"country":"DE"}` or
+`"search":{"country":"ES"}`. It also accepts the matching coverage names
+`germany` and `spain`. A normalized request records the coverage;
an explicitly supplied country is normalized to uppercase. If both are supplied,
they must agree. `bounds_wsen` and `--bounds` narrow the selected profile. They
must be an independently justified prior, not the evaluation location.
diff --git a/docs/INTERFACES.md b/docs/INTERFACES.md
index bd12498..7ed92ca 100644
--- a/docs/INTERFACES.md
+++ b/docs/INTERFACES.md
@@ -33,14 +33,17 @@ returns `needs_input` with `required_fields: ["time_window"]` if a defensible wi
is still unavailable. Do not fabricate a timestamp. A derived best recording start
is a result field and must not be mislabeled independent timestamp evidence.
-`search.country` accepts `US` (CONUS) or `DE` (Germany); lowercase ISO codes are
-normalized. The corresponding `search.coverage` values are `conus` and `germany`.
+`search.country` accepts `US` (CONUS), `DE` (Germany) or `ES` (Spain); lowercase
+ISO codes are normalized. The corresponding `search.coverage` values are
+`conus`, `germany` and `spain`.
Either country or coverage is sufficient, and contradictory values are rejected.
Legacy `{"coverage":"conus"}` objects keep their serialized shape; the validator
does not insert a country into old requests. Optional `bounds_wsen` further restrict
the selected profile to `[west, south, east, north]` in longitude/latitude degrees.
Bounds must lie inside its declared envelope. Germany's land mask further limits
-receiver points, while neighboring aircraft remain eligible. The capability
+receiver points. Spain uses a bounding envelope without a country polygon and
+requires explicit bounds for a suitably regional search. Neighboring aircraft
+remain eligible outside the receiver area when they fall within acoustic range. The capability
response publishes the supported catalog; see [country profiles](COUNTRIES.md).
Actual data availability may be smaller and must be reported in provenance and
the decision. Bounds must increase; antimeridian crossing is not supported here.
diff --git a/scripts/check_country_profiles.py b/scripts/check_country_profiles.py
index 563e4e3..e81dbd0 100644
--- a/scripts/check_country_profiles.py
+++ b/scripts/check_country_profiles.py
@@ -36,6 +36,7 @@ def check_contracts():
request_base = {"schema_version": 1, "audio_path": str(Path(__file__).resolve())}
conus_subset = [-90.0, 40.0, -87.0, 43.0]
buesingen_subset = [8.66, 47.68, 8.72, 47.72]
+ madrid_subset = [-4.16, 40.05, -2.97, 40.95]
cases = (
("omitted search", None, {"coverage": "conus"}, "US"),
("legacy CONUS", {"coverage": "conus"}, {"coverage": "conus"}, "US"),
@@ -48,6 +49,10 @@ def check_contracts():
{"country": "DE", "coverage": "germany"}, "DE"),
("Germany subset", {"country": "DE", "bounds_wsen": buesingen_subset},
{"country": "DE", "coverage": "germany", "bounds_wsen": buesingen_subset}, "DE"),
+ ("Spain country", {"country": "es"}, {"country": "ES", "coverage": "spain"}, "ES"),
+ ("Spain coverage", {"coverage": "spain"}, {"coverage": "spain"}, "ES"),
+ ("Spain region", {"country": "ES", "bounds_wsen": madrid_subset},
+ {"country": "ES", "coverage": "spain", "bounds_wsen": madrid_subset}, "ES"),
)
validated = {}
for name, search, expected, country in cases:
@@ -68,6 +73,7 @@ def check_contracts():
rejected = (
{"country": "DE", "coverage": "conus"},
{"country": "US", "coverage": "germany"},
+ {"country": "DE", "coverage": "spain"},
{"country": "FR"},
{"coverage": "custom"},
{"country": None},
@@ -88,8 +94,8 @@ def check_contracts():
raise CheckFailure(f"Invalid search was accepted: {search!r}")
catalog = public_profiles()
- require(len(catalog) == 2 and {p["country"] for p in catalog} == {"US", "DE"},
- "Capabilities must describe exactly the supported US and DE profiles")
+ require(len(catalog) == 3 and {p["country"] for p in catalog} == {"US", "DE", "ES"},
+ "Capabilities must describe exactly the supported US, DE and ES profiles")
for item in catalog:
profile = profile_for_search({"country": item["country"]})
require(item["coverage"] == profile.coverage and item["crs"] == profile.crs
@@ -98,6 +104,8 @@ def check_contracts():
require(profile_for_search().crs == "EPSG:5070", "Legacy CONUS CRS changed")
require(profile_for_search({"country": "DE"}).crs == "EPSG:32632",
"Germany must use its declared UTM 32N search CRS")
+ require(profile_for_search({"country": "ES"}).crs == "EPSG:6933",
+ "Spain must use its declared global equal-area search CRS")
print(f"PASS requests: {len(cases)} normalization/JSON round-trip cases; "
f"{len(rejected)} invalid declarations rejected; profile catalog agrees")
return validated
@@ -130,6 +138,9 @@ def check_mask(cache_root, online, validated):
require(receiver_mask_for_search(validated["legacy CONUS"]["search"],
cache_root=cache_root, offline=True) is None,
"The legacy CONUS profile unexpectedly acquired a country polygon")
+ require(receiver_mask_for_search(validated["Spain region"]["search"],
+ cache_root=cache_root, offline=True) is None,
+ "The Spain envelope must not load or apply the Germany polygon")
search = validated["DE country"]["search"]
mask = receiver_mask_for_search(search, cache_root=cache_root, offline=not online)
require(mask is not None, "Germany must not fall back to a rectangular mask")
@@ -175,6 +186,31 @@ def check_mask(cache_root, online, validated):
return mask
+def check_spain_grid(validated):
+ import numpy as np
+ from pyproj import Transformer
+ from dopplergeist.geography import profile_for_search
+ from dopplergeist.tiled_search import _grid_extent, _tile_coordinates
+
+ search = validated["Spain region"]["search"]
+ profile = profile_for_search(search)
+ bounds = search["bounds_wsen"]
+ forward = Transformer.from_crs("EPSG:4326", profile.crs, always_xy=True)
+ xmin, ymin, xmax, ymax = _grid_extent(bounds, 2000.0, profile.crs)
+ receivers = _tile_coordinates((xmin, ymin, xmax + 1, ymax + 1), 2000.0,
+ bounds, profile.crs)
+ require(len(receivers) > 0, "The published Madrid search rectangle contains no coarse receivers")
+ projected_x, projected_y = forward.transform(receivers.lon.to_numpy(), receivers.lat.to_numpy())
+ require(np.isfinite(projected_x).all() and np.isfinite(projected_y).all(),
+ "Spain receiver grid contains invalid projected coordinates")
+ west, south, east, north = bounds
+ require(bool(np.all((receivers.lon >= west) & (receivers.lon <= east)
+ & (receivers.lat >= south) & (receivers.lat <= north))),
+ "Spain receiver grid escaped the explicit Madrid bounds")
+ print(f"PASS Spain grid: {len(receivers)} coarse receivers in the real Madrid regional bounds; "
+ "no country polygon applied")
+
+
def check_border_grid(mask, validated):
import numpy as np
from pyproj import Transformer
@@ -269,6 +305,7 @@ def main(argv=None):
try:
validated = check_contracts()
mask = check_mask(args.cache_root, args.online, validated)
+ check_spain_grid(validated)
check_border_grid(mask, validated)
check_empty_areas(mask, validated)
except (CheckFailure, ImportError, OSError, ValueError, RuntimeError) as error:
diff --git a/src/dopplergeist/contracts.py b/src/dopplergeist/contracts.py
index 364f506..749ed30 100644
--- a/src/dopplergeist/contracts.py
+++ b/src/dopplergeist/contracts.py
@@ -21,8 +21,8 @@ class RecordingTimeWindow(TypedDict):
class SearchArea(TypedDict):
- country: NotRequired[Literal["US", "DE"]]
- coverage: NotRequired[Literal["conus", "germany"]]
+ country: NotRequired[Literal["US", "DE", "ES"]]
+ coverage: NotRequired[Literal["conus", "germany", "spain"]]
bounds_wsen: NotRequired[list[float]]
diff --git a/src/dopplergeist/geography.py b/src/dopplergeist/geography.py
index cb86b9f..57ed490 100644
--- a/src/dopplergeist/geography.py
+++ b/src/dopplergeist/geography.py
@@ -2,7 +2,9 @@
Country masks restrict receiver locations, never aircraft trajectories. The US
profile deliberately retains the historical CONUS rectangle and CRS. Germany
-uses BKG VG250 land geometry in its native ETRS89 / UTM 32N coordinates.
+uses BKG VG250 land geometry in its native ETRS89 / UTM 32N coordinates. Spain
+uses an outer geographic envelope and global equal-area projection; the caller's
+declared bounds select the actual receiver search region.
"""
from copy import deepcopy
from dataclasses import dataclass
@@ -30,6 +32,8 @@ _PROFILES = {
(-125.0, 24.0, -66.0, 50.0), "EPSG:5070"),
"DE": SearchProfile("DE", "germany", "Germany",
(5.5, 47.0, 15.5, 55.2), "EPSG:32632"),
+ "ES": SearchProfile("ES", "spain", "Spain (all territories; bounding envelope)",
+ (-18.2, 27.5, 4.5, 43.9), "EPSG:6933"),
}
_COVERAGE_COUNTRIES = {p.coverage: code for code, p in _PROFILES.items()}
@@ -66,10 +70,10 @@ def profile_for_search(search=None):
coverage = search.get("coverage")
if "country" in search:
if not isinstance(country, str) or country.upper() not in _PROFILES:
- raise ValueError("Supported countries are US (CONUS) and DE (Germany)")
+ raise ValueError("Supported countries are US (CONUS), DE (Germany) and ES (Spain)")
country = country.upper()
if "coverage" in search and (not isinstance(coverage, str) or coverage not in _COVERAGE_COUNTRIES):
- raise ValueError("Supported coverage values are conus (US/CONUS) and germany (DE)")
+ raise ValueError("Supported coverage values are conus (US/CONUS), germany (DE) and spain (ES)")
if country is None:
country = _COVERAGE_COUNTRIES.get(coverage, "US")
profile = _PROFILES[country]
@@ -241,7 +245,7 @@ def receiver_mask_for_search(search, *, cache_root, offline=True):
Existing cache bytes are checked each time; missing or changed data produce
an explicit data-unavailable outcome through the acquisition adapter.
"""
- if profile_for_search(search).country == "US":
+ if profile_for_search(search).country != "DE":
return None
from .data_access import DataUnavailable
path = Path(cache_root) / "geography" / f"de-vg250-{BKG_BOUNDARY_SHA256[:16]}.json"
diff --git a/tests/test_contracts.py b/tests/test_contracts.py
index 0867be2..b0c7706 100644
--- a/tests/test_contracts.py
+++ b/tests/test_contracts.py
@@ -53,6 +53,25 @@ def test_invalid_request_and_truth_fields_rejected(change):
validate_request(request)
+def test_spain_request_accepts_real_madrid_region_and_requires_country_consistency():
+ request = {"schema_version": 1, "audio_path": "recording.mp3",
+ "search": {"country": "ES", "coverage": "spain",
+ "bounds_wsen": [-4.16, 40.05, -2.97, 40.95]}}
+ clean = validate_request(request)
+ assert clean["search"] == request["search"]
+
+ request["search"]["coverage"] = "germany"
+ with pytest.raises(ValueError, match="requires coverage spain"):
+ validate_request(request)
+
+
+def test_spain_request_rejects_bounds_outside_profile_envelope():
+ request = {"schema_version": 1, "audio_path": "recording.mp3",
+ "search": {"country": "ES", "bounds_wsen": [-20.0, 40.0, -3.0, 41.0]}}
+ with pytest.raises(ValueError, match="must stay within Spain"):
+ validate_request(request)
+
+
def test_untrusted_time_source_and_reversed_window_rejected():
request = example("analysis-request")
request["time_window"]["source"] = "file_mtime"
diff --git a/tests/test_geography_profiles.py b/tests/test_geography_profiles.py
new file mode 100644
index 0000000..ab3ce50
--- /dev/null
+++ b/tests/test_geography_profiles.py
@@ -0,0 +1,21 @@
+from dopplergeist.geography import profile_for_search, public_profiles, receiver_mask_for_search
+
+
+def test_spain_profile_supports_bounded_madrid_uploads_without_germany_mask(tmp_path):
+ search = {"country": "ES", "coverage": "spain",
+ "bounds_wsen": [-4.16, 40.05, -2.97, 40.95]}
+ profile = profile_for_search(search)
+
+ assert profile.country == "ES"
+ assert profile.coverage == "spain"
+ assert profile.crs == "EPSG:6933"
+ assert profile.bounds_wsen == (-18.2, 27.5, 4.5, 43.9)
+ assert receiver_mask_for_search(search, cache_root=tmp_path, offline=True) is None
+
+
+def test_spain_profile_is_available_to_upload_capabilities():
+ profile = next(item for item in public_profiles() if item["country"] == "ES")
+
+ assert profile["coverage"] == "spain"
+ assert profile["name"] == "Spain (all territories; bounding envelope)"
+ assert profile["bounds_wsen"] == [-18.2, 27.5, 4.5, 43.9]