Skip to content

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

Fix Copernicus terrain selection at shifted tile seams

Cinna Davis21544bd8c642
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 8912688..b74ac21 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -43,6 +43,8 @@ jobs:
run: python -m pytest -q tests/test_real_prepared_geometry_compatibility.py::test_pinned_legacy_geometry_and_data_source_preserve_real_tracks
- name: Check country profiles against the actual BKG land boundary
run: python scripts/check_country_profiles.py --online --cache-root "$RUNNER_TEMP/dopplergeist-geography"
+ - name: Check terrain seams against observed Copernicus raster footprints
+ run: python -m pytest -q tests/test_real_terrain_tile_seams.py
- name: Check progress reporting against recorded empty-tile checkpoints
run: |
python - <<'PY'
diff --git a/src/dopplergeist/data_access.py b/src/dopplergeist/data_access.py
index 4c34f95..2e2530d 100644
--- a/src/dopplergeist/data_access.py
+++ b/src/dopplergeist/data_access.py
@@ -27,6 +27,7 @@ import pandas as pd
import requests
from .geometry import Track
+from .terrain import _glo90_tile_degrees
from .tracks import _segment_velocity, adsblol_frame
try:
@@ -1103,9 +1104,7 @@ class CachedTerrain:
lat, lon = np.broadcast_arrays(lat, lon)
shape = lat.shape
lat, lon = lat.ravel(), lon.ravel()
- # Published COG tiles omit the original bottom/right overlap pixels.
- # Their outer edges are shifted north/west by half a GLO90 pixel.
- degrees = np.column_stack((np.floor(lat - 1 / 2400).astype(int), np.floor(lon + 1 / 2400).astype(int)))
+ degrees = _glo90_tile_degrees(lat, lon)
self.last_sample_files = {"tileList.txt", self.geoid_path.name}
self.last_sample_ocean_tiles = set()
tiles, inverse = np.unique(degrees, axis=0, return_inverse=True)
diff --git a/src/dopplergeist/index_compatibility.py b/src/dopplergeist/index_compatibility.py
index e07b2fd..637087d 100644
--- a/src/dopplergeist/index_compatibility.py
+++ b/src/dopplergeist/index_compatibility.py
@@ -3,6 +3,18 @@
# The cache-size-only change and this exact compatibility check do not change
# decoded observations or normalization. Any source edit disables this mapping.
PREPARED_DATA_ACCESS_EQUIVALENCE = {
+ # Only GLO-90 terrain tile selection changed; prepared aircraft
+ # observation decoding and normalization remain byte-for-byte unchanged.
+ "690caf2155bcc17905a5d71ea3b3d4111485451cc734b827c9c4ac5f2997d22b": (
+ "23aa4ac1781cb5be921f5243f421886d2f2e549a4ded6dcc1986ade651883f7e",
+ "d88c4be6668b92c9a1a31b5cd0b4dbdcb3d7cf73c5891ae414f44deca6088644",
+ "77da0d39e1e95476fdf02e29e9a345914545af7e62227a93b4cb6786edb37a71",
+ "ddd77e9734fff6a70cc9195bd1305002f9f78e39ea601f27e0f596dcb336033a",
+ "275e38a37f82993b609b6b78c113d35c4da269083ceb3afcb1d94ada48bdc0d4",
+ "dad02d09d89ad9d267cd8d0424b8e018d0399a28d6b43903b5a55867290b3957",
+ "d664caf4b496599d29a81360c4a9d9736a3248c157e71d885463b349aad6dd36",
+ "ce78ad66f2d478e1f7ea158ea04c0d3b25021339e34f090652740fe55e46e5ec",
+ ),
# Country selection changes only acquisition bounds and optional row warming;
# prepared observation decoding and normalization are unchanged.
"23aa4ac1781cb5be921f5243f421886d2f2e549a4ded6dcc1986ade651883f7e": (
diff --git a/src/dopplergeist/terrain.py b/src/dopplergeist/terrain.py
index 682d38b..3070778 100644
--- a/src/dopplergeist/terrain.py
+++ b/src/dopplergeist/terrain.py
@@ -12,6 +12,20 @@ from pyproj import Transformer
_PIXEL_CACHE_MAX_ENTRIES = 1024
+def _glo90_tile_degrees(lat, lon):
+ """Select the published COG footprint, including latitude-dependent widths."""
+ # GLO-90 removes its southern/eastern overlap pixels. Latitude footprints
+ # are south-exclusive/north-inclusive, shifted north by half a 3" pixel.
+ north = np.ceil(np.asarray(lat) - 1 / 2400).astype(int) - 1
+ # Use the selected tile's latitude band, not the point latitude: the N49
+ # footprint extends slightly north of 50 degrees; S50 has 1200 columns.
+ # https://copernicus-dem-90m.s3.amazonaws.com/readme.html
+ band = np.searchsorted([50, 60, 70, 80, 85], np.abs(north + .5))
+ width = np.asarray([1200, 800, 600, 400, 240, 120])[band]
+ east = np.floor(np.asarray(lon) + .5 / width).astype(int)
+ return np.column_stack((north, east))
+
+
@lru_cache(maxsize=32)
def _raster_transformer(crs):
"""Reuse a raster's unchanged coordinate operation across refinement calls."""
@@ -168,7 +182,7 @@ class CopernicusTerrain:
lat,lon=np.broadcast_arrays(lat,lon)
shape=lat.shape
lat,lon=lat.ravel(),lon.ravel()
- degrees=np.column_stack((np.floor(lat).astype(int),np.floor(lon).astype(int)))
+ degrees=_glo90_tile_degrees(lat,lon)
tiles,inverse=np.unique(degrees,axis=0,return_inverse=True)
height=np.zeros(len(lat))
for index,(north,east) in enumerate(tiles):
diff --git a/tests/data/real-glo90-tile-headers.json b/tests/data/real-glo90-tile-headers.json
new file mode 100644
index 0000000..f753ddb
--- /dev/null
+++ b/tests/data/real-glo90-tile-headers.json
@@ -0,0 +1,249 @@
+{
+ "observed_at_utc": "2026-11-04T04:56:29.325184+00:00",
+ "source": "Copernicus GLO-90 public COG headers; no audio or aircraft observations generated",
+ "provider_documentation": "https://copernicus-dem-90m.s3.amazonaws.com/readme.html",
+ "rasters": [
+ {
+ "tile": "Copernicus_DSM_COG_30_N49_00_E013_00_DEM",
+ "north": 49,
+ "east": 13,
+ "url": "https://copernicus-dem-90m.s3.amazonaws.com/Copernicus_DSM_COG_30_N49_00_E013_00_DEM/Copernicus_DSM_COG_30_N49_00_E013_00_DEM.tif",
+ "prefix_bytes": 65536,
+ "prefix_sha256": "5c5790813af1bd3c54003e0faa38a38ba9386e25a26102b11ff36dc543fd169c",
+ "etag": "\"ee52cdebadd4624381873c2865459da8\"",
+ "content_range": "bytes 0-65535/5153362",
+ "width": 1200,
+ "height": 1200,
+ "pixel_width_degrees": 0.0008333333333333334,
+ "pixel_height_degrees": 0.0008333333333333334,
+ "raster_type": 2,
+ "geographic_crs": 4326,
+ "bounds_wsen": [
+ 12.999583333333334,
+ 49.000416666666666,
+ 13.999583333333334,
+ 50.000416666666666
+ ]
+ },
+ {
+ "tile": "Copernicus_DSM_COG_30_N50_00_E013_00_DEM",
+ "north": 50,
+ "east": 13,
+ "url": "https://copernicus-dem-90m.s3.amazonaws.com/Copernicus_DSM_COG_30_N50_00_E013_00_DEM/Copernicus_DSM_COG_30_N50_00_E013_00_DEM.tif",
+ "prefix_bytes": 65536,
+ "prefix_sha256": "83636050be93cc898245dcbd7b3d5cfa7c7dc06cddfa38d35949f15220949ad9",
+ "etag": "\"dd9167e306f6531f04cf5a77f0f8c629\"",
+ "content_range": "bytes 0-65535/3595889",
+ "width": 800,
+ "height": 1200,
+ "pixel_width_degrees": 0.00125,
+ "pixel_height_degrees": 0.0008333333333333334,
+ "raster_type": 2,
+ "geographic_crs": 4326,
+ "bounds_wsen": [
+ 12.999375,
+ 50.000416666666666,
+ 13.999375,
+ 51.000416666666666
+ ]
+ },
+ {
+ "tile": "Copernicus_DSM_COG_30_N50_00_E014_00_DEM",
+ "north": 50,
+ "east": 14,
+ "url": "https://copernicus-dem-90m.s3.amazonaws.com/Copernicus_DSM_COG_30_N50_00_E014_00_DEM/Copernicus_DSM_COG_30_N50_00_E014_00_DEM.tif",
+ "prefix_bytes": 65536,
+ "prefix_sha256": "9a7ff28f5c3a14860ca8ef89c3c0d0a5c31d889a02e3b125a93d4d296f567173",
+ "etag": "\"e50eea055605ed38d0cda9cb5e1d8fe4\"",
+ "content_range": "bytes 0-65535/3611521",
+ "width": 800,
+ "height": 1200,
+ "pixel_width_degrees": 0.00125,
+ "pixel_height_degrees": 0.0008333333333333334,
+ "raster_type": 2,
+ "geographic_crs": 4326,
+ "bounds_wsen": [
+ 13.999375,
+ 50.000416666666666,
+ 14.999375,
+ 51.000416666666666
+ ]
+ },
+ {
+ "tile": "Copernicus_DSM_COG_30_N52_00_E013_00_DEM",
+ "north": 52,
+ "east": 13,
+ "url": "https://copernicus-dem-90m.s3.amazonaws.com/Copernicus_DSM_COG_30_N52_00_E013_00_DEM/Copernicus_DSM_COG_30_N52_00_E013_00_DEM.tif",
+ "prefix_bytes": 65536,
+ "prefix_sha256": "681ef4a864309c7f0834a9a346c7c6708278bab74e2a9b81f96c79989468a3dc",
+ "etag": "\"bea950b0ffeca9d513a48e3218a0fdc0\"",
+ "content_range": "bytes 0-65535/3765647",
+ "width": 800,
+ "height": 1200,
+ "pixel_width_degrees": 0.00125,
+ "pixel_height_degrees": 0.0008333333333333334,
+ "raster_type": 2,
+ "geographic_crs": 4326,
+ "bounds_wsen": [
+ 12.999375,
+ 52.000416666666666,
+ 13.999375,
+ 53.000416666666666
+ ]
+ },
+ {
+ "tile": "Copernicus_DSM_COG_30_N52_00_E014_00_DEM",
+ "north": 52,
+ "east": 14,
+ "url": "https://copernicus-dem-90m.s3.amazonaws.com/Copernicus_DSM_COG_30_N52_00_E014_00_DEM/Copernicus_DSM_COG_30_N52_00_E014_00_DEM.tif",
+ "prefix_bytes": 65536,
+ "prefix_sha256": "b779b77855312618deca3a66a7726b4571f1f1897a0d02289696c12a818d5cf3",
+ "etag": "\"a8f72a6f5fc92f5f8623873df4eed2e4\"",
+ "content_range": "bytes 0-65535/3836633",
+ "width": 800,
+ "height": 1200,
+ "pixel_width_degrees": 0.00125,
+ "pixel_height_degrees": 0.0008333333333333334,
+ "raster_type": 2,
+ "geographic_crs": 4326,
+ "bounds_wsen": [
+ 13.999375,
+ 52.000416666666666,
+ 14.999375,
+ 53.000416666666666
+ ]
+ },
+ {
+ "tile": "Copernicus_DSM_COG_30_S50_00_W074_00_DEM",
+ "north": -50,
+ "east": -74,
+ "url": "https://copernicus-dem-90m.s3.amazonaws.com/Copernicus_DSM_COG_30_S50_00_W074_00_DEM/Copernicus_DSM_COG_30_S50_00_W074_00_DEM.tif",
+ "prefix_bytes": 65536,
+ "prefix_sha256": "e1896286b65f4e76d83f32f18d330b61fd936c7dc4607fe6fdcd7cbd3e352e04",
+ "etag": "\"5166e3b85e123c49a66f8cf4865941ac\"",
+ "content_range": "bytes 0-65535/4916223",
+ "width": 1200,
+ "height": 1200,
+ "pixel_width_degrees": 0.0008333333333333334,
+ "pixel_height_degrees": 0.0008333333333333334,
+ "raster_type": 2,
+ "geographic_crs": 4326,
+ "bounds_wsen": [
+ -74.00041666666667,
+ -49.999583333333334,
+ -73.00041666666667,
+ -48.999583333333334
+ ]
+ },
+ {
+ "tile": "Copernicus_DSM_COG_30_S51_00_W074_00_DEM",
+ "north": -51,
+ "east": -74,
+ "url": "https://copernicus-dem-90m.s3.amazonaws.com/Copernicus_DSM_COG_30_S51_00_W074_00_DEM/Copernicus_DSM_COG_30_S51_00_W074_00_DEM.tif",
+ "prefix_bytes": 65536,
+ "prefix_sha256": "c90c4d0404cdd6cc8c6fe63d11c166d3bac83cbeb699dda60c0cccd60bd568ea",
+ "etag": "\"b1176f92575ce727e8159abbababc698\"",
+ "content_range": "bytes 0-65535/3419738",
+ "width": 800,
+ "height": 1200,
+ "pixel_width_degrees": 0.00125,
+ "pixel_height_degrees": 0.0008333333333333334,
+ "raster_type": 2,
+ "geographic_crs": 4326,
+ "bounds_wsen": [
+ -74.000625,
+ -50.999583333333334,
+ -73.000625,
+ -49.999583333333334
+ ]
+ },
+ {
+ "tile": "Copernicus_DSM_COG_30_N60_00_E010_00_DEM",
+ "north": 60,
+ "east": 10,
+ "url": "https://copernicus-dem-90m.s3.amazonaws.com/Copernicus_DSM_COG_30_N60_00_E010_00_DEM/Copernicus_DSM_COG_30_N60_00_E010_00_DEM.tif",
+ "prefix_bytes": 65536,
+ "prefix_sha256": "8c47e384e21eb39ba8e5fee0d602c9c5d41562730ef5639249e630f10efbc19d",
+ "etag": "\"914cad0f21f0b548ccf62559c069a66a\"",
+ "content_range": "bytes 0-65535/2700509",
+ "width": 600,
+ "height": 1200,
+ "pixel_width_degrees": 0.0016666666666666668,
+ "pixel_height_degrees": 0.0008333333333333334,
+ "raster_type": 2,
+ "geographic_crs": 4326,
+ "bounds_wsen": [
+ 9.999166666666667,
+ 60.000416666666666,
+ 10.999166666666667,
+ 61.000416666666666
+ ]
+ },
+ {
+ "tile": "Copernicus_DSM_COG_30_N70_00_E025_00_DEM",
+ "north": 70,
+ "east": 25,
+ "url": "https://copernicus-dem-90m.s3.amazonaws.com/Copernicus_DSM_COG_30_N70_00_E025_00_DEM/Copernicus_DSM_COG_30_N70_00_E025_00_DEM.tif",
+ "prefix_bytes": 65536,
+ "prefix_sha256": "dd1e6ce1cc0779de3eb8a4f604855717f8188ec7a63f628d3c31c53f9d18e3e7",
+ "etag": "\"14e6b658aa0cd2b9107cdd3610716073\"",
+ "content_range": "bytes 0-65535/1364487",
+ "width": 400,
+ "height": 1200,
+ "pixel_width_degrees": 0.0025,
+ "pixel_height_degrees": 0.0008333333333333334,
+ "raster_type": 2,
+ "geographic_crs": 4326,
+ "bounds_wsen": [
+ 24.99875,
+ 70.00041666666667,
+ 25.99875,
+ 71.00041666666667
+ ]
+ },
+ {
+ "tile": "Copernicus_DSM_COG_30_S81_00_E000_00_DEM",
+ "north": -81,
+ "east": 0,
+ "url": "https://copernicus-dem-90m.s3.amazonaws.com/Copernicus_DSM_COG_30_S81_00_E000_00_DEM/Copernicus_DSM_COG_30_S81_00_E000_00_DEM.tif",
+ "prefix_bytes": 65536,
+ "prefix_sha256": "372ba3af6746f959c76981515cceb3c4bda01eca922cfadf460d351267a763c0",
+ "etag": "\"599c4c4b981f8d07deb56fde790bb3c0\"",
+ "content_range": "bytes 0-65535/824047",
+ "width": 240,
+ "height": 1200,
+ "pixel_width_degrees": 0.004166666666666667,
+ "pixel_height_degrees": 0.0008333333333333334,
+ "raster_type": 2,
+ "geographic_crs": 4326,
+ "bounds_wsen": [
+ -0.0020833333333333333,
+ -80.99958333333333,
+ 0.9979166666666667,
+ -79.99958333333333
+ ]
+ },
+ {
+ "tile": "Copernicus_DSM_COG_30_S86_00_E000_00_DEM",
+ "north": -86,
+ "east": 0,
+ "url": "https://copernicus-dem-90m.s3.amazonaws.com/Copernicus_DSM_COG_30_S86_00_E000_00_DEM/Copernicus_DSM_COG_30_S86_00_E000_00_DEM.tif",
+ "prefix_bytes": 65536,
+ "prefix_sha256": "80d7dc487d24b2ef362b83fca1cc3982ebfed76bc8b12e23ca205c9711d8cf35",
+ "etag": "\"045cfbc6115d9888a99344c79d2a4e50\"",
+ "content_range": "bytes 0-65535/457390",
+ "width": 120,
+ "height": 1200,
+ "pixel_width_degrees": 0.008333333333333333,
+ "pixel_height_degrees": 0.0008333333333333334,
+ "raster_type": 2,
+ "geographic_crs": 4326,
+ "bounds_wsen": [
+ -0.004166666666666667,
+ -85.99958333333333,
+ 0.9958333333333333,
+ -84.99958333333333
+ ]
+ }
+ ]
+}
diff --git a/tests/test_real_terrain_tile_seams.py b/tests/test_real_terrain_tile_seams.py
new file mode 100644
index 0000000..501b376
--- /dev/null
+++ b/tests/test_real_terrain_tile_seams.py
@@ -0,0 +1,53 @@
+"""Tile ownership checked against actual public Copernicus raster headers."""
+import json
+from pathlib import Path
+
+import numpy as np
+import pytest
+
+from dopplergeist.terrain import _glo90_tile_degrees
+
+
+OBSERVED = json.loads((Path(__file__).parent / "data" / "real-glo90-tile-headers.json").read_text())
+RASTERS = {(r["north"], r["east"]): r for r in OBSERVED["rasters"]}
+
+
[email protected]("raster", OBSERVED["rasters"], ids=lambda r: r["tile"])
+def test_actual_raster_western_strip_belongs_to_its_tile(raster):
+ west, south, east, north = raster["bounds_wsen"]
+ # This is a real strip inside the observed first column. The old fixed
+ # half-pixel selects the previous longitude tile at wider latitude bands.
+ lat = (south + north) / 2
+ lon = west + raster["pixel_width_degrees"] / 10
+ assert west <= lon < east and south < lat <= north
+ assert _glo90_tile_degrees([lat], [lon]).tolist() == [[raster["north"], raster["east"]]]
+
+
+def test_actual_brandenburg_seam_and_berlin_centre():
+ points = [(52.52, 13.9995), (52.52, 13.405)]
+ selected = _glo90_tile_degrees(*np.asarray(points).T)
+ assert selected.tolist() == [[52, 14], [52, 13]]
+ for (lat, lon), pair in zip(points, selected):
+ raster = RASTERS[tuple(pair)]
+ west, south, east, north = raster["bounds_wsen"]
+ assert west <= lon < east and south < lat <= north
+
+
+def test_actual_n49_n50_shared_latitude_edge_and_different_widths():
+ edge = RASTERS[49, 13]["bounds_wsen"][3]
+ assert edge == RASTERS[50, 14]["bounds_wsen"][1]
+ # The shifted shared edge belongs to N49. Above it, the same longitude
+ # belongs to N50E014 because N50's longitude columns are wider.
+ lat = np.array([edge - 1e-7, edge, edge + 1e-7])
+ lon = np.full(3, 13.9995)
+ assert _glo90_tile_degrees(lat, lon).tolist() == [[49, 13], [49, 13], [50, 14]]
+
+
+def test_actual_s50_s51_have_different_longitude_widths():
+ lower_latitude = RASTERS[-50, -74]
+ higher_latitude = RASTERS[-51, -74]
+ assert lower_latitude["width"] == 1200
+ assert higher_latitude["width"] == 800
+ # Absolute tile origin would incorrectly classify S50 as the wider band.
+ lon = lower_latitude["bounds_wsen"][0] + lower_latitude["pixel_width_degrees"] / 10
+ assert _glo90_tile_degrees([-49.5], [lon]).tolist() == [[-50, -74]]