适配 KNMI netCDF 新数据布局:(station,time) 替代 (time,station)

This commit is contained in:
2569718930@qq.com
2026-05-18 18:28:18 +08:00
parent 8a5e8957c5
commit 8c640b8616
+23 -15
View File
@@ -146,23 +146,31 @@ class KnmiSourceMixin:
return None return None
data = ta[:] data = ta[:]
latest_temp = float(data[-1, idx]) if data.ndim == 2 else float(data[-1]) # Handle both old (time,station) and new (station,time) layouts
dim_names = [str(d.name).lower() for d in ta.dimensions]
if data.ndim == 2:
if dim_names and dim_names[0] == "station":
latest_temp = float(data[idx, -1])
else:
latest_temp = float(data[-1, idx])
else:
latest_temp = float(data[-1])
# Wind speed def _read_2d(var, idx: int) -> Optional[float]:
ff = nc.variables.get("ff", None) if var is None:
wind_ms = None return None
if ff is not None: vdata = var[:]
wind_data = ff[:] if vdata.ndim == 2:
wind_ms = float(wind_data[-1, idx] if wind_data.ndim == 2 else wind_data[-1]) vdim_names = [str(d.name).lower() for d in var.dimensions]
if vdim_names and vdim_names[0] == "station":
return float(vdata[idx, -1])
return float(vdata[-1, idx])
return float(vdata[-1])
# Pressure wind_ms = _read_2d(nc.variables.get("ff"), idx)
p0 = nc.variables.get("p0", None) pressure_hpa = _read_2d(nc.variables.get("p0"), idx)
pressure_hpa = None if pressure_hpa is not None and pressure_hpa > 5000:
if p0 is not None: pressure_hpa = pressure_hpa / 100.0
p_data = p0[:]
pressure_hpa = float(p_data[-1, idx] if p_data.ndim == 2 else p_data[-1])
if pressure_hpa > 5000:
pressure_hpa = pressure_hpa / 100.0
nc.close() nc.close()