from netCDF4 import Dataset
from datetime import timedelta, datetime
import os
import pandas as pd
from wrf import getvar
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
def get_para_data(para_name, time_range, file):
para_data = []
for i in time_range:
z = getvar(file, para_name, timeidx=i, meta=False) # meta默认true : cat,false :join
z = z[:, row, col]
para_data.extend(z)
return para_data
def plot_uv(p, u, v, save_path):
time_ids = [0, 3, 6, 9, 12, 15, 18, 21]
plt.figure(figsize=(14, 8))
for k in range(8):
ax = plt.subplot(2, 4, k + 1)
pp = p[time_ids[k] * 30:(time_ids[k] + 1) * 30]
xx = pp * 0
uu = u[time_ids[k] * 30:(time_ids[k] + 1) * 30]
vv = v[time_ids[k] * 30:(time_ids[k] + 1) * 30]
plt.sca(ax)
Q = plt.quiver(xx, pp, uu, vv, units='x', scale=3.5)
plt.quiverkey(Q, 0.25, 1.03, 5, '5 m/s', labelpos='W')
plt.ylim(0, 1500)
plt.xlim(-10, 10)
plt.xticks([0], [""])
plt.text(-8, 150, str(time_ids[k]) + " BJT")
if k in [0, 4]:
plt.ylabel("Height (m)")
plt.tight_layout()
plt.savefig(save_path)
plt.close()
def plot_temp(p, t, save_path):
time_ids = [0, 3, 6, 9, 12, 15, 18, 21]
plt.figure(figsize=(14, 8))
for k in range(8):
ax = plt.subplot(2, 4, k + 1)
pp = p[time_ids[k] * 30:(time_ids[k] + 1) * 30]
tt = t[time_ids[k] * 30:(time_ids[k] + 1) * 30]
plt.sca(ax)
plt.plot(tt, pp, '-ok')
plt.ylim(0, 1500)
plt.xlim(-10, 10)
plt.text(-8, 150, str(time_ids[k]) + " BJT")
if k in [0, 4]:
plt.ylabel("Height (m)")
if k > 3:
plt.xlabel("Temp ($^o$C)")
plt.tight_layout()
plt.savefig(save_path)
plt.close()
if __name__ == '__main__':
# ------------------------------------------显示目录-----------------------------------------------------