适配 KNMI station ID 格式变更:3位码→5位WMO码,修复前导零丢失

This commit is contained in:
2569718930@qq.com
2026-05-18 18:23:57 +08:00
parent 06ac6bab32
commit 8a5e8957c5
+13 -11
View File
@@ -20,7 +20,7 @@ KNMI_VERSION = "1.0"
KNMI_API_BASE = "https://api.dataplatform.knmi.nl/open-data/v1" KNMI_API_BASE = "https://api.dataplatform.knmi.nl/open-data/v1"
KNMI_STATION = { KNMI_STATION = {
"amsterdam": { "amsterdam": {
"station": "240", "station": "06240",
"icao": "EHAM", "icao": "EHAM",
"label": "Schiphol 10min (KNMI)", "label": "Schiphol 10min (KNMI)",
}, },
@@ -117,20 +117,22 @@ class KnmiSourceMixin:
try: try:
stn = meta["station"] stn = meta["station"]
# Find station index # Find station index
station_ids = list(nc.variables.get("station_id", [])[:]) station_var = nc.variables.get("station_id") or nc.variables.get("station")
if not station_ids: station_ids = []
station_codes = [] for s in (station_var[:] if station_var is not None else []):
for s in nc.variables.get("station", []): try:
try: val = str(int(s))
station_codes.append(str(int(s))) except Exception:
except Exception: val = str(s).strip()
station_codes.append("") station_ids.append(val)
station_ids = station_codes
try: try:
idx = station_ids.index(stn) idx = station_ids.index(stn)
except ValueError: except ValueError:
idx = station_ids.index(int(stn)) if stn.isdigit() else -1 try:
idx = station_ids.index(str(int(stn)))
except (ValueError, TypeError):
idx = -1
if idx < 0 or idx >= len(station_ids): if idx < 0 or idx >= len(station_ids):
logger.warning("KNMI station {} not found in file", stn) logger.warning("KNMI station {} not found in file", stn)