1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | from netCDF4 import Dataset |
---|
4 | import matplotlib.pyplot as mpl |
---|
5 | import numpy as np |
---|
6 | from myplot import reducefield,getfield,getcoorddef,calculate_bounds,bounds,fmtvar,ptitle,makeplotres |
---|
7 | from matplotlib.pyplot import contourf,colorbar,show,xlabel,ylabel |
---|
8 | from matplotlib.cm import get_cmap |
---|
9 | |
---|
10 | name = "wrfout_d01_9999-09-09_09:00:00_z" |
---|
11 | itime = 12 |
---|
12 | #itime = 1 |
---|
13 | ndiv = 10 |
---|
14 | zey = 0 |
---|
15 | var = "W" |
---|
16 | vmin = -1. |
---|
17 | vmax = 1. |
---|
18 | title = "Vertical velocity" |
---|
19 | var = "Um" |
---|
20 | vmin = -2. |
---|
21 | vmax = 18. |
---|
22 | title = "Horizontal velocity" |
---|
23 | #var = "tk" |
---|
24 | #vmin = 150. |
---|
25 | #vmax = 170. |
---|
26 | #title = "Atmospheric temperature" |
---|
27 | |
---|
28 | name = "wrfout_d01_2024-03-22_01:00:00_z" |
---|
29 | itime = 12 |
---|
30 | ndiv = 10 |
---|
31 | zey = 120 |
---|
32 | var = "VMR_ICE" |
---|
33 | title = "Volume mixing ratio of water ice [ppm]" |
---|
34 | vmin = -0.5 |
---|
35 | vmax = 400. |
---|
36 | |
---|
37 | nc = Dataset(name) |
---|
38 | |
---|
39 | what_I_plot, error = reducefield( getfield(nc,var), d4=itime, d2=zey ) |
---|
40 | |
---|
41 | |
---|
42 | y = nc.variables["vert"][:] |
---|
43 | |
---|
44 | horinp = len(what_I_plot[0,:]) |
---|
45 | x = np.linspace(0.,horinp*500.,horinp) / 1000. |
---|
46 | xlabel("Horizontal coordinate (km)") |
---|
47 | |
---|
48 | horinp = len(what_I_plot[0,:]) |
---|
49 | x = np.linspace(0.,horinp,horinp) |
---|
50 | xlabel("x grid points") |
---|
51 | |
---|
52 | |
---|
53 | zevmin, zevmax = calculate_bounds(what_I_plot,vmin=vmin,vmax=vmax) |
---|
54 | #if colorb in ["def","nobar"]: palette = get_cmap(name=defcolorb(fvar)) |
---|
55 | #else: palette = get_cmap(name=colorb) |
---|
56 | palette = get_cmap(name="jet") |
---|
57 | what_I_plot = bounds(what_I_plot,zevmin,zevmax) |
---|
58 | zelevels = np.linspace(zevmin,zevmax) |
---|
59 | contourf( x, y, what_I_plot, zelevels, cmap = palette ) |
---|
60 | colorbar(fraction=0.05,pad=0.03,format=fmtvar(var),\ |
---|
61 | ticks=np.linspace(zevmin,zevmax,ndiv+1),\ |
---|
62 | extend='neither',spacing='proportional') |
---|
63 | ptitle(title) |
---|
64 | ylabel("Altitude (m)") |
---|
65 | makeplotres(var+str(itime),res=200.,disp=False) |
---|
66 | #show() |
---|