| 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 | nc = Dataset(name) |
|---|
| 29 | |
|---|
| 30 | what_I_plot, error = reducefield( getfield(nc,var), d4=itime, d2=zey ) |
|---|
| 31 | |
|---|
| 32 | y = nc.variables["vert"][:] |
|---|
| 33 | |
|---|
| 34 | horinp = len(what_I_plot[0,:]) |
|---|
| 35 | x = np.linspace(0.,horinp*500.,horinp) / 1000. |
|---|
| 36 | |
|---|
| 37 | zevmin, zevmax = calculate_bounds(what_I_plot,vmin=vmin,vmax=vmax) |
|---|
| 38 | #if colorb in ["def","nobar"]: palette = get_cmap(name=defcolorb(fvar)) |
|---|
| 39 | #else: palette = get_cmap(name=colorb) |
|---|
| 40 | palette = get_cmap(name="jet") |
|---|
| 41 | what_I_plot = bounds(what_I_plot,zevmin,zevmax) |
|---|
| 42 | zelevels = np.linspace(zevmin,zevmax) |
|---|
| 43 | contourf( x, y, what_I_plot, zelevels, cmap = palette ) |
|---|
| 44 | colorbar(fraction=0.05,pad=0.03,format=fmtvar(var),\ |
|---|
| 45 | ticks=np.linspace(zevmin,zevmax,ndiv+1),\ |
|---|
| 46 | extend='neither',spacing='proportional') |
|---|
| 47 | ptitle(title) |
|---|
| 48 | xlabel("Horizontal coordinate (km)") |
|---|
| 49 | ylabel("Altitude (m)") |
|---|
| 50 | makeplotres(var+str(itime),res=200.,disp=False) |
|---|
| 51 | #show() |
|---|