修复 KNMI 维度名称为字符串类型的兼容性问题

This commit is contained in:
2569718930@qq.com
2026-05-18 18:30:12 +08:00
parent 8c640b8616
commit 1c4287380e
+7 -9
View File
@@ -147,12 +147,11 @@ class KnmiSourceMixin:
data = ta[:] data = ta[:]
# Handle both old (time,station) and new (station,time) layouts # Handle both old (time,station) and new (station,time) layouts
dim_names = [str(d.name).lower() for d in ta.dimensions] n_stations = len(station_ids)
if data.ndim == 2: if data.ndim == 2 and data.shape[0] == n_stations:
if dim_names and dim_names[0] == "station": latest_temp = float(data[idx, -1])
latest_temp = float(data[idx, -1]) elif data.ndim == 2:
else: latest_temp = float(data[-1, idx])
latest_temp = float(data[-1, idx])
else: else:
latest_temp = float(data[-1]) latest_temp = float(data[-1])
@@ -160,10 +159,9 @@ class KnmiSourceMixin:
if var is None: if var is None:
return None return None
vdata = var[:] vdata = var[:]
if vdata.ndim == 2 and vdata.shape[0] == n_stations:
return float(vdata[idx, -1])
if vdata.ndim == 2: if vdata.ndim == 2:
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, idx])
return float(vdata[-1]) return float(vdata[-1])