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

如何消除GPCC降水气候态图本初子午线的数据空白?

修复GPCC降水数据本初子午线空白(保留原分辨率)

我在绘制GPCC降水气候态分布图时,发现本初子午线存在数据空白(截断)问题,希望通过CDO、NCO或Python工具修复,且全程保留原数据分辨率。

问题示意图

问题示意图1
问题示意图2


CDO 解决方案

无需插值,通过调整经度范围+边界数据复制填补空白,完全保留原分辨率:

  1. 转换经度范围至[-180, 180],自动衔接跨0°的边界:
cdo sellonlatbox,-180,180,-90,90 input.nc temp.nc
  1. 基于原网格的 nearest neighbor 方法填补空白(不改变分辨率):
cdo remapcon,input.nc temp.nc fixed_gpcc.nc

注:remapcon以原数据网格为目标模板,仅填补缺失的边界格点,不会修改现有数据或分辨率。


NCO 解决方案

通过调整经度坐标+相邻格点复制填补空白:

  1. 将经度从[0,360]转换为[-180,180]:
ncpdq -O -a lon input.nc temp.nc
ncatted -O -a units,lon,o,c,"degrees_east" temp.nc
ncap2 -O -s 'where(lon>180) lon=lon-360' temp.nc temp.nc
  1. 排序经度并填补本初子午线缺失值(复制相邻有效格点数据):
ncks -O --msa -d lon,-180,180 temp.nc fixed_gpcc.nc

Python(xarray)解决方案

直接处理经度衔接,用邻域格点值填补空白,保留原分辨率:

import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs

# 读取GPCC数据
ds = xr.open_dataset('precip.nc')

# 转换经度范围:0-360 → -180-180,并排序
ds['lon'] = ((ds['lon'] + 180) % 360) - 180
ds = ds.sortby('lon')

# 定位本初子午线附近的空白,用相邻格点填充(仅补缺失的1-2个格点,不改变分辨率)
ds['precip'] = ds['precip'].interpolate_na(dim='lon', method='nearest', limit=1)

# 保存修复后的数据
ds.to_netcdf('fixed_gpcc.nc')

# 绘图验证
JJAS2 = ds['precip'].sel(time=ds['time.month'].isin([6,7,8,9])) \
                   .sel(time=ds['time.year']>1981) \
                   .groupby('time.year').mean('time') \
                   .mean(dim='year', keep_attrs=True)

fig, ax = plt.subplots(1, 1, figsize=(16,8), subplot_kw={'projection': ccrs.PlateCarree()})
cs = ax.contourf(JJAS2.lon, JJAS2.lat, JJAS2, 
                 levels=[0,50,100,150,200,250,300,350,400,450,500],
                 vmin=0, vmax=500, cmap='Blues', extend='both')
ax.gridlines(draw_labels=True, linewidth=1, color='gray', alpha=0.5, linestyle='--')
ax.coastlines(color='black')
ax.set_extent([-20,30,0,30], crs=ccrs.PlateCarree())
cbar = plt.colorbar(cs, fraction=0.05, pad=0.04, extend='both', orientation='horizontal')
plt.show()

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 03:35:00