Files
2026-10-21 09:24:12 +02:00

104 lines
3.2 KiB
Python

"""Create entirely synthetic offline demo inputs; no real map or flight observations."""
import json
import sys
from pathlib import Path
import numpy as np
import rasterio
from rasterio.transform import from_bounds
from flight_map.geo import DEFAULT_BOUNDS
from flight_map.storage import (
Observation,
checkpoint,
create_session,
database,
initialize,
save_observations,
)
def main() -> None:
if len(sys.argv) != 2:
raise SystemExit("Usage: python examples/make_demo.py OUTPUT_DIRECTORY")
folder = Path(sys.argv[1])
folder.mkdir(parents=True, exist_ok=True)
db = folder / "demo.sqlite"
if db.exists():
raise SystemExit(f"Refusing to replace {db}")
started = 1_792_497_600.0
with database(db) as connection:
initialize(connection)
session = create_session(connection, DEFAULT_BOUNDS, 2000, 30, started)
items = []
northings = [52.235, 52.237, 52.244, 52.247, 52.246]
for index in range(5):
items.append(
Observation(
"abc123",
"DEMO123",
started + index * 30,
4.77 + index * 0.027,
northings[index],
900 + index * 30,
1043 + index * 30,
)
)
items.append(
Observation(
"def456",
"DEMO456",
started + index * 30,
4.85 - index * 0.013,
52.26 - index * 0.008,
700,
843,
)
)
save_observations(connection, session, items, started + 150)
checkpoint(connection, session.id, started + 150, "stopped")
ways = [
[(4.77, 52.235), (4.81, 52.24), (4.87, 52.25)],
[(4.80, 52.23), (4.82, 52.245), (4.81, 52.26)],
[(4.835, 52.23), (4.84, 52.26)],
[(4.82, 52.242), (4.823, 52.242), (4.823, 52.244), (4.82, 52.244), (4.82, 52.242)],
]
(folder / "map.json").write_text(
json.dumps(
{
"elements": [
{
"type": "way",
"id": index,
"geometry": [{"lon": lon, "lat": lat} for lon, lat in points],
}
for index, points in enumerate(ways)
]
}
)
)
for name, value in (("terrain.tif", -2),):
with rasterio.open(
folder / name,
"w",
driver="GTiff",
height=64,
width=64,
count=1,
dtype="float32",
crs="EPSG:4326",
transform=from_bounds(*session.collection_bounds.values, 64, 64),
) as dataset:
dataset.write(np.full((1, 64, 64), value, dtype="float32"))
print(f"Synthetic demo session: {session.id}")
print(
f"flight-map plot --db '{db}' --session {session.id} "
f"--map-data '{folder / 'map.json'}' --terrain '{folder / 'terrain.tif'}' "
f"--terrain-reference orthometric --output '{folder / 'demo.svg'}'"
)
if __name__ == "__main__":
main()