source: trunk/LMDZ.PLUTO/util/script_figures/mapmeanwinds.py

Last change on this file was 3823, checked in by afalco, 2 days ago

Pluto: added some python scripts for visualization.
AF

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1#! /usr/bin/env python
2from    netCDF4               import    Dataset
3from    numpy                 import    *
4import  numpy                 as        np
5import  matplotlib.pyplot     as        mpl
6from matplotlib.cm import get_cmap
7import pylab
8from matplotlib import ticker
9import matplotlib.colors as colors
10import datetime
11from mpl_toolkits.basemap import Basemap, shiftgrid
12from FV3_utils import *
13
14############################
15fa='sans-serif'
16hfont = {'fontname':'Arial'}
17mpl.rc('font',family=fa)
18mpl.rc('pdf',fonttype=42)
19font=30
20cc=['k']
21pal=get_cmap(name="rainbow")
22norm=colors.LogNorm()
23#lvls=np.logspace(-6,-4,21)
24norm=None #colors.LogNorm()
25lvls=np.linspace(37,57,21)
26
27### Data
28name2=name+'.nc'
29# name=name+'_A.nc'
30name=name+'.nc'
31print("Plot "+name)
32nc1=Dataset(name)
33nc2=Dataset(name2)
34ts=nc2.variables["temperature"][:,0,:,:]
35# ts=nc2.variables["tsurf"][:,:,:]
36u=nc1.variables["u"][:,:,:,:]
37v=nc1.variables["v"][:,:,:,:]
38lat=nc1.variables["lat"][:]
39alt=nc1.variables["altitude"][:]
40lon=nc1.variables["lon"][:]
41ps=nc2.variables["ps"][:,:]
42# ps=nc2.variables["phisinit"][:,:]/0.6169/1000.  # altitude km
43
44numalt=getind(1,alt)
45# numalt=getind(1000,alt)
46print('numalt =',numalt,'altitude=',alt[numalt])
47u=u[:,numalt,:,:]
48v=v[:,numalt,:,:]
49u=np.mean(u,axis=0)
50v=np.mean(v,axis=0)
51ts=np.mean(ts,axis=0)
52ps=np.mean(ps,axis=0)
53
54ts=switchlon(ts)
55u=switchlon(u)
56v=switchlon(v)
57# ps=switchlon(ps)
58# topo=switchlon(topo)
59# lon=lon+180.
60
61### Figure
62fig=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
76CF=mpl.contourf(lon, lat, ps,cmap=pal,norm=norm,extend='both')
77cbar=mpl.colorbar(CF, label="Pa")
78cbar.set_label("Pa", size=font)
79for t in cbar.ax.get_yticklabels():
80  t.set_fontsize(font)
81mpl.title('Surface pressures and winds',fontsize=font)
82
83getwinds(lon,lat,u,v,1,1,100,0.002,5)
84
85mpl.grid()
86mpl.ylabel(r'Latitude',labelpad=10,fontsize=font)
87mpl.xlabel('Longitude',labelpad=10, fontsize=font)
88pylab.ylim([-90,90])
89yticks=np.linspace(-90,90,13)
90pylab.xlim([0,360])
91xticks=np.linspace(0,360,7)
92mpl.yticks(yticks,fontsize=font)
93mpl.xticks(xticks,fontsize=font)
94mpl.tight_layout()
95mpl.savefig('mapwinds1km.png',bbox_inches='tight',dpi=70)
96mpl.show()
97
98#######################
99
Note: See TracBrowser for help on using the repository browser.