Xarray ValueError求助:combine='by_coords'时concat_dim参数无效
解决 ValueError: When combine='by_coords', passing a value for
concat_dim has no effect 的问题 问题根源
该错误源于新版本xarray的参数兼容性校验:当使用combine='by_coords'模式时,不能同时指定concat_dim参数(因为by_coords会自动根据坐标维度合并文件,无需显式指定合并维度)。而act-atmos库的read_netcdf函数可能默认传递了concat_dim,与combine='by_coords'冲突,触发报错。
解决方法
1. 显式传递兼容的合并参数
根据你的需求选择以下任一方式:
- 指定固定维度合并:若需沿特定维度(如时间
time)合并文件,使用combine='nested'并搭配concat_dim:obj = act.io.armfiles.read_netcdf('sgpmetE13.b1/*', combine='nested', concat_dim='time') - 自动按坐标合并:若希望xarray自动根据坐标合并,传递
combine='by_coords'并确保不设置concat_dim(可显式设为None):obj = act.io.armfiles.read_netcdf('sgpmetE13.b1/*', combine='by_coords', concat_dim=None)
2. 更新act-atmos库到最新版本
检查act-atmos是否发布了修复该兼容性问题的更新,执行升级命令:
pip install --upgrade act-atmos
3. 降级xarray到兼容版本
若升级act-atmos无效,可回退到未添加该参数校验的旧版xarray,例如:
pip install xarray==2023.6.0
内容的提问来源于stack exchange,提问作者Fan Mei
相关产品推荐
相关产品推荐

