python 读取netCDF 文件方法

1. 安装netCDF库

首先下载netCDF包,网址:https://pypi.org/project/netCDF4/

 选择符合自己要求的whl文件

 使用 pip 命令进行安装

pip install netCDF4-1.5.3-cp38-cp38-win_amd64.whl

2. 相关代码如下所示:

 1 from netCDF4 import Dataset
 2 
 3 # 查看nc数据基本信息
 4 # nc_obj = Dataset(r'E:\文档\My RSM-VAT Files\Data\Example\PRD_SD_JAN_41_41\CMAQ\ACONC.1',mode='r', format="NETCDF4")
 5 path = r"E:\PaperData\PRD_SD_JAN_41_41\CMAQ\ACONC.1"
 6 nc_obj = Dataset(path, mode='r', format="NETCDF4")
 7 print(nc_obj)
 8 # 查看nc数据各个变量的信息
 9 print(nc_obj.variables.keys())
10 for i in nc_obj.variables.keys():
11     print('___________________________________________')
12     print(i)
13     print(nc_obj.variables[i])
14 
15 NOx = (nc_obj.variables['NOx'][:])
16 SO2 = (nc_obj.variables['SO2'][:])
17 NH3 = (nc_obj.variables['NH3'][:])
18 VOC = (nc_obj.variables['VOC'][:])

计算结果如图所示

 

 

注意:路径中若出现中文字符则需要转码,但是目前本人尚未实现该技术。 

 

参考资料:

https://blog.csdn.net/wildand/article/details/88899718

 https://www.cnblogs.com/oikoumene/p/11137789.html

https://www.csdn.net/gather_2e/Mtjagg2sMzM2LWJsb2cO0O0O.html

posted @ 2020-06-23 13:43  CollinsLi  阅读(2157)  评论(0编辑  收藏  举报