【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)
乘风的头像乘风管理团队
上一篇 2023年11月14日
下一篇 2023年11月14日

相关推荐