1 | #! /usr/bin/env python |
---|
2 | from netCDF4 import Dataset |
---|
3 | from numpy import * |
---|
4 | import numpy as np |
---|
5 | import matplotlib.pyplot as mpl |
---|
6 | from matplotlib.cm import get_cmap |
---|
7 | import pylab |
---|
8 | from matplotlib import ticker |
---|
9 | import matplotlib.colors as colors |
---|
10 | import datetime |
---|
11 | from mpl_toolkits.basemap import Basemap, shiftgrid |
---|
12 | from FV3_utils import * |
---|
13 | |
---|
14 | ############################ |
---|
15 | fa='sans-serif' |
---|
16 | hfont = {'fontname':'Arial'} |
---|
17 | mpl.rc('font',family=fa) |
---|
18 | mpl.rc('pdf',fonttype=42) |
---|
19 | font=30 |
---|
20 | cc=['k'] |
---|
21 | pal=get_cmap(name="rainbow") |
---|
22 | norm=colors.LogNorm() |
---|
23 | #lvls=np.logspace(-6,-4,21) |
---|
24 | norm=None #colors.LogNorm() |
---|
25 | lvls=np.linspace(37,57,21) |
---|
26 | |
---|
27 | ### Data |
---|
28 | name2=name+'.nc' |
---|
29 | # name=name+'_A.nc' |
---|
30 | name=name+'.nc' |
---|
31 | print("Plot "+name) |
---|
32 | nc1=Dataset(name) |
---|
33 | nc2=Dataset(name2) |
---|
34 | ts=nc2.variables["temperature"][:,0,:,:] |
---|
35 | # ts=nc2.variables["tsurf"][:,:,:] |
---|
36 | u=nc1.variables["u"][:,:,:,:] |
---|
37 | v=nc1.variables["v"][:,:,:,:] |
---|
38 | lat=nc1.variables["lat"][:] |
---|
39 | alt=nc1.variables["altitude"][:] |
---|
40 | lon=nc1.variables["lon"][:] |
---|
41 | ps=nc2.variables["ps"][:,:] |
---|
42 | # ps=nc2.variables["phisinit"][:,:]/0.6169/1000. # altitude km |
---|
43 | |
---|
44 | numalt=getind(1,alt) |
---|
45 | # numalt=getind(1000,alt) |
---|
46 | print('numalt =',numalt,'altitude=',alt[numalt]) |
---|
47 | u=u[:,numalt,:,:] |
---|
48 | v=v[:,numalt,:,:] |
---|
49 | u=np.mean(u,axis=0) |
---|
50 | v=np.mean(v,axis=0) |
---|
51 | ts=np.mean(ts,axis=0) |
---|
52 | ps=np.mean(ps,axis=0) |
---|
53 | |
---|
54 | ts=switchlon(ts) |
---|
55 | u=switchlon(u) |
---|
56 | v=switchlon(v) |
---|
57 | # ps=switchlon(ps) |
---|
58 | # topo=switchlon(topo) |
---|
59 | # lon=lon+180. |
---|
60 | |
---|
61 | ### Figure |
---|
62 | fig=mpl.figure(figsize=(20, 10)) |
---|
63 | # CF=mpl.contourf(lon, lat, ts,lvls,cmap=pal,norm=norm,extend='both') |
---|
64 | # cbar=mpl.colorbar(CF, shrink=1, ticks=lvls[::2]) #,format="%1.0f") |
---|
65 | # cbar.ax.set_title("[K]",y=1.04,fontsize=font) |
---|
66 | # for t in cbar.ax.get_yticklabels(): |
---|
67 | # t.set_fontsize(font) |
---|
68 | # mpl.title('Surface temperatures and winds',fontsize=font) |
---|
69 | |
---|
70 | #vect=lvls |
---|
71 | # CS=mpl.contour(lon,lat,topo,np.linspace(-6,6,21),colors='k',linewidths=0.5) |
---|
72 | #lab=mpl.clabel(CS, inline=1, fontsize=20, fmt='%1.2e',inline_spacing=1) |
---|
73 | #for l in lab: |
---|
74 | # l.set_rotation(0) |
---|
75 | |
---|
76 | CF=mpl.contourf(lon, lat, ps,cmap=pal,norm=norm,extend='both') |
---|
77 | cbar=mpl.colorbar(CF, label="Pa") |
---|
78 | cbar.set_label("Pa", size=font) |
---|
79 | for t in cbar.ax.get_yticklabels(): |
---|
80 | t.set_fontsize(font) |
---|
81 | mpl.title('Surface pressures and winds',fontsize=font) |
---|
82 | |
---|
83 | getwinds(lon,lat,u,v,1,1,100,0.002,5) |
---|
84 | |
---|
85 | mpl.grid() |
---|
86 | mpl.ylabel(r'Latitude',labelpad=10,fontsize=font) |
---|
87 | mpl.xlabel('Longitude',labelpad=10, fontsize=font) |
---|
88 | pylab.ylim([-90,90]) |
---|
89 | yticks=np.linspace(-90,90,13) |
---|
90 | pylab.xlim([0,360]) |
---|
91 | xticks=np.linspace(0,360,7) |
---|
92 | mpl.yticks(yticks,fontsize=font) |
---|
93 | mpl.xticks(xticks,fontsize=font) |
---|
94 | mpl.tight_layout() |
---|
95 | mpl.savefig('mapwinds1km.png',bbox_inches='tight',dpi=70) |
---|
96 | mpl.show() |
---|
97 | |
---|
98 | ####################### |
---|
99 | |
---|