Pumping: the weather of the stations with a position written into data/<SERIAL>/weather/ (extraction/weather.py, after pump.py); the mm (corr_x_mm, corr_y_mm by the sensor_id of each row) and targets.csv with the references (pattern_type, distance_mm, mm_per_px); --replace pumps a range again
pump.py --check passes; the mm and targets.csv parts are not yet run against the database (no VPN). stations.txt: NIEDERHORN and NORDEND without a position (outside Switzerland). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9adc38f9b9
commit
ea0228a73a
8 files changed
+205
-22
No files matched your search
+2
-2
@@ -8,9 +8,9 @@ python3 weather/meteoswiss.py "Genève" 2026-11-15 2026-11-16 --out gve.csv
|
||||
python3 weather/meteoswiss.py 46.52,6.63 2025-06-01T12:00 2025-06-01T18:00
|
||||
```
|
||||
|
||||
A caller (the Data page of aimsight-app) calls `hourly(place, start, end)` -> `(where, {time: {column: value or None}})`, `where` the place found and the station chosen; `LookupError` for a place not found, `OSError` when MeteoSwiss or swisstopo do not answer.
|
||||
The pumping writes it into `data/<SERIAL>/weather/<SERIAL>_weather_<YYYYMMDD>.csv` (`extraction/weather.py`): the columns below, `station` followed by `position` (the line of `stations.txt`), `place`, `station_name`, `distance_km`, `height_m`; the app and the agents read these files. A caller calls `hourly(place, start, end)` -> `(where, {time: {column: value or None}})`, `where` the place found and the station chosen; `LookupError` for a place not found, `OSError` when MeteoSwiss or swisstopo do not answer.
|
||||
|
||||
- `place`: a Swiss place name, resolved by the swisstopo search (`api3.geo.admin.ch`), or coordinates `lat,lon` (WGS84). The resolved place and the chosen station (name, distance, altitude) are written on stderr: check them, the search always returns its best match.
|
||||
- `place`: a Swiss place name, resolved by the swisstopo search (`api3.geo.admin.ch`), or coordinates `lat,lon` (WGS84). The resolved place and the chosen station (name, distance, altitude) are written on stderr: check them. A best match whose label does not start with the first word asked is refused (`Toronto` gave `Trient (VS)`): a place outside Switzerland has no weather here, MeteoSwiss measures in Switzerland only.
|
||||
- `start`, `end`: `YYYY-MM-DD` or `YYYY-MM-DDTHH:MM`, in UTC, `end` excluded. The range is in the past.
|
||||
- The output: a CSV, one row per hour, `time_utc` (start of the hour) and `station`, then `precipitation_mm`, `temperature_c`, `humidity_pct`, `wind_speed_kmh`, `wind_gust_kmh`, `wind_direction_deg`, `pressure_hpa` (at the station, QFE), `sunshine_min`, `global_radiation_wm2`, `snow_depth_cm`. An empty cell: not measured at this station or at this hour.
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import json
|
||||
import math
|
||||
import re
|
||||
import sys
|
||||
import unicodedata
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from datetime import datetime, timedelta, timezone
|
||||
@@ -75,9 +76,18 @@ def locate(place):
|
||||
raise LookupError(f"place not found: {place}")
|
||||
attrs = results[0]["attrs"]
|
||||
label = re.sub(r"<[^>]+>", "", attrs["label"]).split("\n")[0].strip()
|
||||
# the search always returns its best match ("Toronto" -> "Trient (VS)"): the label must start with the first word asked
|
||||
# ponytail: first word only; "lat,lon" for a place whose name differs from its label
|
||||
if not plain(label).startswith(plain(place.split()[0])):
|
||||
raise LookupError(f"place not found: {place} (best match: {label})")
|
||||
return attrs["lat"], attrs["lon"], label
|
||||
|
||||
|
||||
def plain(text):
|
||||
"""Lower case, without accents: "Genève" -> "geneve"."""
|
||||
return "".join(c for c in unicodedata.normalize("NFKD", text.lower()) if not unicodedata.combining(c))
|
||||
|
||||
|
||||
def distance_km(lat1, lon1, lat2, lon2):
|
||||
p1, p2 = math.radians(lat1), math.radians(lat2)
|
||||
a = (math.sin((p2 - p1) / 2) ** 2
|
||||
|
||||
Reference in new issue
Block a user