我必须从我拥有的一堆WRFout文件中绘制空间图。目前,我正在使用以下代码行打印每个空间图的相应时间
#..Load packages
import os
import netCDF4
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap,addcyclic,cm,shiftgrid
from wrf import getvar,get_basemap,to_np,latlon_coords
#..Read the files
fpath = sorted(glob.glob("/path/wrfout_d01_2017-03-02_00:00:00"))
with netCDF4.Dataset(fpath, 'r') as fin:
#..Read variables
p = getvar(fin,'pressure')
times = getvar(fin,'times',meta=False)
#..Make the pressure plot
fig = plt.figure()
mp = get_basemap(p)
x,y = mp(to_np(lons),to_np(lats))
cntrs = mp.contourf(x,y,p,cmap='jet')
plt.title(str(to_np(times))[0:-10])
plt.show()
times
变量以2017-03-02T00:00:00.000000000
格式给出时间
代码行plt.title(str(to_np(times))[0:-10])
将时间打印为2017-03-02T00:00:00
,这是UTC时间。但是,我希望它被打印为2017-03-01 17:00:00
,这是当地时间(UTC- 7 hours)
提前感谢,如有任何建议,我们将不胜感激
您可以使用熊猫进行转换。您可以选择适合您的时区。 刚刚添加了有用的代码片段
这可能会有帮助
输出:
现在我的时区是UTC+5:30(印度)。所以,展示这一点。你的应该给你的
相关问题 更多 >
编程相关推荐