import netCDF4 as nc
# 读取数据###############################################################
data_nc = nc.Dataset(r"./data/WRF/wrfout_d03_2023-01-15_12%3A00%3A00")
# print(data_nc.variables['XLAT'])
# print(len(data_nc.variables)) # 获取字典variables的长度
# print(data_nc.variables.get('XLAT')) # 获取键(XLAT)的值
# print(data_nc.variables.items()) # 以列表返回可遍历的(键, 值) 元组数组
# print(data_nc.variables.keys()) # 以列表返回字典所有的键
# print(data_nc.variables.values()) # 以列表返回字典中的所有值
f = open("test.html", "w")
f.write("""
WRF 输出变量
""")
i = 1
# 遍历key的值
for key in data_nc.variables:
print(key)
# print(data_nc.variables[key]['description'])
str_d = str(data_nc.variables[key]).find('description')+13
str_u = str(data_nc.variables[key]).find('units')
str_s = str(data_nc.variables[key]).find('stagger')
desc = str(data_nc.variables[key])[str_d:str_u]
units = str(data_nc.variables[key])[str_u+7:str_s]
f.write(''+str(i)+' | '+key+' | '+desc+' | '+units+' |
')
i = i + 1
# print(data_nc.variables['SST_INPUT'])
print(str(data_nc.variables['QFX']))
f.write("""
""")
f.close()
# # 遍历value的值
# for value in data_nc.variables.values():
# print(value)
#
# # 遍历字典键值对
# for key in data_nc.variables:
# print(key + ":" + str(data_nc.variables[key])) # 返回字符串
#
# for i in data_nc.variables.items():
# print(i) # 返回元组
#
# for key, value in data_nc.variables.items():
# print(key + ':' + str(value))
# all_vars_info = data_nc.variables.items()
# print(all_vars_info)
# slp = getvar(data_nc, "slp") # 读取海表面气压
# smooth_slp = smooth2d(slp, 3, cenweight=4)
# lats, lons = latlon_coords(slp)
# u, v = g_uvmet.get_uvmet(data_nc)