- 积分
- 853
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2021-4-27
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
先把要读取的nc文件放在同一文件夹中,再用python循环读取,读取文件为从NCEP下载的向下地表平均日长波辐射通量,并计算其月平均值,存放至一个文本文件中
NCEP日平均地表向下长波辐射通量下载网址:https://psl.noaa.gov/cgi-bin/db_search/DBListFiles.pl?did=195&tid=98666&vid=1234
- import netCDF4 as nc
- import numpy as np
- from os import listdir
- from os.path import join
-
- data = np.zeros((5,12,94,192)) #建立年份*月份*纬向格点数*经向格点数的数列
- path = r'E:' #nc文件存放文件夹
- a = 0
- for filename in listdir(path):
- #读取nc文件
- file = join(path,filename)
- nc_obj = nc.Dataset(file)
- x = nc_obj.variables['dlwrf'][:] #dlwrf为nc文件中的变量名
- nc_obj.close()
- #计算月平均值
- num = 0
- for m in range(12):
- if m in[1,3,5,7,8,10,12]:
- mnum = 31
- elif m == 2:
- if (a+1979) % 4 == 0 and (a+1979) % 100 != 0:
- mnum = 29
- else:
- mnum = 28
- else:
- mnum = 30
- for i in range(94):
- for j in range(192):
- data[a,m,i,j] = sum(x[num:num+mnum,i,j]) / mnum
- num = num + mnum
- a = a + 1
- #将月平均值按年份、月份、纬度、经度的顺序存放至dat文件中
- with open(r'ulwrf.dat','w') as fp:
- for n in range(39):
- for m in range(12):
- for i in range(94):
- for j in range(192):
- fp.write(str(data[n,m,i,j])+' ')
复制代码 详情也可查看https://blog.csdn.net/qq_47672397/article/details/124534856?spm=1001.2014.3001.5501
|
|