You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Scipy解决5km网格升尺度至10km指定网格的插值报错问题

解决重复经纬度网格的双线性插值问题(升尺度降水数据)

scipy.interpolate.RegularGridInterpolator仅支持严格规则、无重复的一维坐标网格,你的原始5×5公里网格存在重复经纬度,属于散乱点数据集,因此无法直接调用该工具。以下是完整的解决方案,包含重复数据预处理和双线性插值实现:

1. 预处理:去重合并重复经纬度的降水数据

先对原始数据中相同经纬度的降水记录做合并(以均值为例,可根据数据特性调整为求和/保留首条):

import pandas as pd
import numpy as np
from scipy.interpolate import LinearNDInterpolator

# 加载原始5×5公里网格数据
raw_grid = pd.read_csv("5x5_grid_precip.csv")
# 按经纬度分组,对每日降水列取均值
clean_grid = raw_grid.groupby(["LON", "LAT"]).mean().reset_index()

# 提取插值所需的坐标与降水数据
raw_coords = np.column_stack((clean_grid["LON"], clean_grid["LAT"]))
precip_values = clean_grid.drop(["LON", "LAT"], axis=1).values

2. 双线性插值生成目标网格数据

使用LinearNDInterpolator处理散乱点的线性插值(等价于双线性插值),对10×10公里目标网格计算降水值:

# 加载目标10×10公里网格数据
target_grid = pd.read_csv("10x10_target_grid.csv")
target_coords = np.column_stack((target_grid["LON"], target_grid["LAT"]))

# 构建插值器
interpolator = LinearNDInterpolator(raw_coords, precip_values)
# 执行插值
target_precip = interpolator(target_coords)

# 将插值结果合并到目标网格并保存
result_grid = pd.concat([
    target_grid,
    pd.DataFrame(target_precip, columns=clean_grid.columns[2:])
], axis=1)
result_grid.to_csv("upscaled_precip.csv", index=False)

补充说明

  • 若重复经纬度是数据录入错误,可将groupby(...).mean()替换为groupby(...).first()保留首条记录;
  • 若目标点超出原始数据的覆盖范围,插值结果会返回NaN,可补充最近邻插值填充:
    from scipy.interpolate import NearestNDInterpolator
    nearest_interp = NearestNDInterpolator(raw_coords, precip_values)
    nan_mask = np.isnan(target_precip)
    target_precip[nan_mask] = nearest_interp(target_coords[nan_mask])
    

内容的提问来源于stack exchange,提问作者En510

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 20:57:32