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