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

使用Rasterio重采样NetCDF文件遇波段数超限错误求助

问题:NetCDF重采样时Rasterio报错(CDO也存在维度相关问题)

尝试用rasterio将NetCDF文件重采样至更高分辨率,工具无法解析数据;使用CDO操作时同样失败,CDO提示可能是维度命名问题,但rasterio未给出相关提示,无法确定问题根源。

代码示例

from rasterio.enums import Resampling
import xarray as xr

yt_fwi = xr.open_dataset("/file_path/yt_fwi_redo.nc")
upscale_factor = 10
new_width = yt_fwi.rio.width * upscale_factor
new_height = yt_fwi.rio.height * upscale_factor

resamp_fwi = yt_fwi.rio.reproject(yt_fwi.rio.crs, shape=(int(new_height), int(new_width)), resampling=Resampling.nearest)

报错信息

rasterio._err.CPLE_AppDefinedError: Invalid band count : 438700. Maximum allowed currently is 65536. Define GDAL_MAX_BAND_COUNT to a higher level if it is a legitimate number.

解决方案

错误根源

你的NetCDF文件包含438700个时间步,rasterio将time维度识别为波段,而GDAL默认最大波段数为65536,因此触发报错。

处理步骤

  • 单时间步重采样:若无需一次性处理所有时间数据,先选取单个时间切片再操作:

    from rasterio.enums import Resampling
    import xarray as xr
    
    yt_fwi = xr.open_dataset("/file_path/yt_fwi_redo.nc")
    # 选取第一个时间步数据
    single_time_slice = yt_fwi.isel(time=0)
    upscale_factor = 10
    new_width = single_time_slice.rio.width * upscale_factor
    new_height = single_time_slice.rio.height * upscale_factor
    
    resamp_fwi = single_time_slice.rio.reproject(
        single_time_slice.rio.crs, 
        shape=(int(new_height), int(new_width)), 
        resampling=Resampling.nearest
    )
    
  • 批量处理所有时间步:通过循环逐个处理时间切片,再合并结果:

    resampled_list = []
    upscale_factor = 10
    # 先获取单切片的目标尺寸
    single_slice = yt_fwi.isel(time=0)
    new_width = single_slice.rio.width * upscale_factor
    new_height = single_slice.rio.height * upscale_factor
    
    for i in range(len(yt_fwi.time)):
        slice_data = yt_fwi.isel(time=i)
        resampled_slice = slice_data.rio.reproject(
            slice_data.rio.crs,
            shape=(int(new_height), int(new_width)),
            resampling=Resampling.nearest
        )
        resampled_list.append(resampled_slice)
    # 合并所有重采样后的时间切片
    resamp_fwi = xr.concat(resampled_list, dim='time')
    
  • CDO维度问题处理:检查NetCDF的维度命名,确保经度、纬度、时间命名符合CDO识别规范(如lon/latitude、lat/longitude、time),若维度名不标准,可通过xarray重命名:

    # 示例:将x/y维度重命名为lon/lat
    yt_fwi = yt_fwi.rename({'x': 'lon', 'y': 'lat'})
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 13:25:05