【python读取nc文件】报错:ValueError: unrecognized engine netcdf4 must be one of: [‘store‘]

写在最前面

尝试2019华为杯E题,但是报错:
ValueError: unrecognized engine netcdf4 must be one of: [‘store’]
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings…

最终解决
请添加图片描述

报错1:ValueError: found the following matches with the input file in xarray’s IO backends: [‘netcdf4’, ‘h5netcdf’]. But their dependencies may not be installed, see:

https://docs.xarray.dev/en/stable/user-guide/io.html
https://docs.xarray.dev/en/stable/getting-started-guide/installing.html

参考:https://blog.csdn.net/linxi4165/article/details/118470843

conda install xarray

注意:Python最好3.9以上
在这里插入图片描述

下载链接:
https://pypi.tuna.tsinghua.edu.cn/simple/netcdf4/

下载与系统对应的netCAD4,一定要注意32位还是64位,以及操作系统的类型。

找到python对应版本的
Ctrl+F进行网页搜索
在这里插入图片描述
该文件放到开始conda环境的cmd目录下
在pip>后输入
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple netCDF4-1.5.4-cp39-cp39-win_amd64.whl
加粗部分自行替代成自己下载版本的名字,也就是下载的WHL文件的全名之后等待安装即可。

报错二:ValueError: unrecognized engine netcdf4 must be one of: [‘store’] Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings…

参考:https://blog.csdn.net/showpingzhang/article/details/83384780

代码修改为:

# -*- coding: utf-8 -*-


import netCDF4
from netCDF4 import Dataset
nc_obj=Dataset('e:\\P_CLDAS_RE01_EA16_PRE_HOUR_2015010101.nc')

#查看nc文件有些啥东东
print(nc_obj)
print('---------------------------------------')

#查看nc文件中的变量
print(nc_obj.variables.keys())
for i in nc_obj.variables.keys():
    print(i)
print('---------------------------------------')

#查看每个变量的信息
print(nc_obj.variables['LAT'])
print(nc_obj.variables['LON'])
print(nc_obj.variables['PRCP'])
print('---------------------------------------')

#查看每个变量的属性
print(nc_obj.variables['LAT'].ncattrs())
print(nc_obj.variables['LON'].ncattrs())
print(nc_obj.variables['PRCP'].ncattrs())
print(nc_obj.variables['LAT'].units)
print(nc_obj.variables['LON'].units)
print(nc_obj.variables['PRCP']._Fillvalue)
print('---------------------------------------')

#读取数据值
lat=(nc_obj.variables['LAT'][:])
lon=(nc_obj.variables['LON'][:])
prcp=(nc_obj.variables['PRCP'][:])
print(lat)
print(lon)
print('---------------******-------------------')
print(prcp)

请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是Yu欸

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值