1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
| from matplotlib import cm,colors
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
import netCDF4 as nc
from wrfpost import sharexy
fip = "/run/media/storm/Flash/WRF/623/"
fin1 = "wrfout_d02_2016-06-23_06_00_00"
shpfn = '/home/storm/MATLAB/shp/bou2_4p'
ti = [0,6,12,18]
xs = 0; xe = -1
ys = 0; ye = -1
zs = 0; ze = -1
data = nc.Dataset(fip + fin1, "r")
truelat = data.TRUELAT1
truelat = data.TRUELAT2
stalon = data.CEN_LON
stalat = data.CEN_LAT
# 国内雷达图配色
collev = ["#FFFFFF","#98F5FF","#87CEEB","#00FF00",\
"#008B00","#FFFF00","#FFA500","#FF8C00",\
"#FF0000","#AF0000","#8B0000","#FF00FF",\
"#8A2BE2","#360CF9"]
# 文献中雷达反射率配色
# ["#9808F0", "#51A5CE", "#3455A9", "#7FC500", "#54BE09", "#39932C",\
# "#F7E731","#E6BC25", "#F78C29", "#E12C2D", "#A22429", "#4A1910",\
# "#B85BC1", "#935CB6"]
cmaps = colors.ListedColormap(collev,'indexed')
cm.register_cmap(name = 'dbzcmap',data = collev,lut = 128)
fn = "Arial"
fs = 10
ld = 0.
nrows = 2
ncols = 2
fig,axes = plt.subplots(nrows = nrows, ncols = ncols,
subplot_kw= dict(aspect = 'auto'))
for i, ax in zip(np.arange(0, nrows*ncols), axes.flat):
dbz = data.variables["COMPOSITE_REFL_10CM"][ti[i],xs:xe,ys:ye]
lat = data.variables["XLAT"][ti[i], xs:xe, ys:ye]
lon = data.variables["XLONG"][ti[i], xs:xe, ys:ye]
map = Basemap(ax= ax, projection="lcc", llcrnrlon = lon[-1,0], llcrnrlat = lat[0,0],\
urcrnrlon = lon[0,-1], urcrnrlat=lat[-1,-1], lat_0 = stalat,\
lon_0 = stalon, resolution ="h")
x, y = map(lon, lat)
# 添加经度,纬度坐标,海岸线,国界线
labelsx, labelsy = sharexy(ax, nrows, ncols, i)
map.readshapefile(shpfn, 'bou2_4p', linewidth = 1, color = 'k', ax = ax)
map.drawmeridians(np.arange(int(lon[-1,0]), int(lon[0,-1])+1, 2), labels= labelsx, \
fontname = fn, fontsize= fs, linewidth = ld, ax = ax)
map.drawparallels(np.arange(int(lat[0,0]), int(lat[-1,-1])+1), labels= labelsy, \
fontname = fn, fontsize= fs, linewidth = ld, ax = ax)
con = map.contourf(x, y, dbz, np.arange(0,71,5), cmap= cmaps)
ax.set_adjustable('box-forced') # 防止绘图和坐标区域不一致
fig.subplots_adjust(top = 0.9, bottom = 0.1, left = 0.12, right = 0.77,
hspace = 0.05, wspace = 0.05)
fig.colorbar(con, ax=axes.ravel().tolist(), pad = 0.01)
#plt.savefig("panel.eps")
plt.show()
|