source: trunk/LMDZ.PLUTO/util/script_figures/mapch4cloud.py @ 3831

Last change on this file since 3831 was 3823, checked in by afalco, 5 days ago

Pluto: added some python scripts for visualization.
AF

  • Property svn:executable set to *
File size: 6.1 KB
Line 
1#! /usr/bin/env python
2from ppclass import pp
3from    netCDF4               import    Dataset
4from    numpy                 import    *
5import  numpy                 as        np
6import  matplotlib.pyplot     as        mpl
7from matplotlib.cm import get_cmap
8import pylab
9from matplotlib import ticker
10import matplotlib.colors as mcolors
11import datetime
12from mpl_toolkits.basemap import Basemap, shiftgrid
13
14############################
15filename1="diagfi2015.nc"
16filename2="diagfi2015_S.nc"
17var="tsurf" #variable
18var1="ch4_ice_col"
19var2="phisinit"
20tint=["30.625","30.875","31.125","30.375"] #Time must be as written in the input file
21tintstr=["03:00","09:00","15:00","21:00"] #Time must be as written in the input file
22
23font=15
24
25nc1=Dataset(filename1)
26nc2=Dataset(filename2)
27
28lat=nc1.variables["lat"][:]
29lon=nc1.variables["lon"][:]
30
31# altitdue file 2
32alt=nc2.variables["altitude"][:]
33############################
34
35def getvar(filename,var,tint):
36    myvar = pp(file=filename,var=var,t=tint,compute="nothing").getf()  # get data to be changed according to selected variable
37    print((shape(myvar)))
38    return myvar
39
40def swinglon(myvar):
41   # changer les longitudes pour mettre TR au centre
42   vec=shape(myvar)
43   myvarbis=np.zeros(vec,dtype='f')
44# i lat : pas de changement
45# j lon :
46   for i in range(vec[0]):
47       for j in range(vec[1]):
48           if j < int(vec[1]/2.) :
49             myvarbis[i,j]=myvar[i,j+int(vec[1]/2.)]
50             # myvar2bis[i,j]=myvar2[i,j+int(vec[1]/2)]
51           else:
52             myvarbis[i,j]=myvar[i,j-int(vec[1]/2.)]
53             # myvar2bis[i,j]=myvar2[i,j-int(vec[1]/2)]
54   return myvarbis
55
56def getwinds(lon,lat,vecx,vecy):
57          svx='None'   # arrow every svx box
58          svy='None'
59          svx=1
60          svy=1
61          angle='uv'       # 'xy'
62          color='black'    # arrow color
63          pivot='mid'      # arrow around middle of box. Alternative : tip
64          scale=2*33     # scale arrow
65          width=0.002      # width arrow
66          linewidths=0.5   # epaisseur contour arrow
67          edgecolors='k'   # couleur contour arrow
68
69    #  *scale*: [ *None* | float ]
70    #  Data units per arrow length unit, e.g., m/s per plot width; a smaller
71    #  scale parameter makes the arrow longer.  If *None*, a simple
72    #  autoscaling algorithm is used, based on the average vector length
73    #  and the number of vectors.  The arrow length unit is given by
74    #  the *scale_units* parameter
75   
76    #  *scale_units*: *None*, or any of the *units* options.
77    #  For example, if *scale_units* is 'inches', *scale* is 2.0, and
78    #  ``(u,v) = (1,0)``, then the vector will be 0.5 inches long.
79    #  If *scale_units* is 'width', then the vector will be half the width
80    #  of the axes.
81   
82    #  If *scale_units* is 'x' then the vector will be 0.5 x-axis
83    #  units.  To plot vectors in the x-y plane, with u and v having
84    #  the same units as x and y, use
85    #  "angles='xy', scale_units='xy', scale=1".
86   
87          x, y = np.meshgrid(lon,lat)
88          q = mpl.quiver( x[::svy,::svx],y[::svy,::svx],\
89           vecx[::svy,::svx],vecy[::svy,::svx],\
90          angles=angle,color=color,pivot=pivot,\
91          scale=scale,width=width,linewidths=linewidths,edgecolors=edgecolors)
92
93          # make vector key.
94          #keyh = 1.025 ; keyv = 1.05 # upper right corner over colorbar
95          keyh = 0.97 ; keyv = 1.06
96          keyh = 0.03 ; keyv = 1.07
97          #keyh = -0.03 ; keyv = 1.08 # upper left corner
98          labelpos='E'    # position label compared to arrow : N S E W
99          p = mpl.quiverkey(q,keyh,keyv,\
100          5.0,r'$5 m/s$',\
101          fontproperties={'size': font,'weight': 'bold'},\
102          color='black',labelpos=labelpos,labelsep = 0.07)
103
104def getfigvar(nbfig,nbrow,nbcol,i):
105    mpl.subplot(nbrow,nbcol,i+1)
106    pal=get_cmap(name="PuBu")
107    newlon=lon+180
108
109    mymin=0.1
110    mymax=50
111
112    # log
113    norm=mcolors.LogNorm()
114    lvls=np.logspace(np.log10(mymin),np.log10(mymax),15)
115    #titi=[1.e-14,1.e-13,1.e-12,1.e-11]
116    CF=mpl.contourf(newlon, lat, cloud,levels=lvls,norm=norm,cmap=pal)
117    '''
118    # lin
119    lev=np.linspace(mymin,mymax,6)
120    CF=mpl.contourf(newlon, lat, cloud,lev,cmap=pal,extend='both')
121    '''
122    yticks=[-90,-60,-30,0,30,60,90]
123    xticks=[0,60,120,180,240,300,360]
124    cbar=mpl.colorbar(CF,shrink=1, format="%1.1f")
125    cbar.ax.set_title("1E-6 kg/m2",y=1.04,fontsize=font)
126
127    for t in cbar.ax.get_yticklabels():
128        t.set_fontsize(font)
129
130    vect=[47]
131    print(('shape=',shape(newlon),shape(lat),shape(tmp)))
132    CS=mpl.contour(newlon,lat,tmp,colors='k',linewidths=0.5)
133    #### inline=1 : values over the line
134    mpl.clabel(CS, inline=1, fontsize=20, fmt='%1.1f',inline_spacing=1)
135
136    mpl.title('Local Time (180E) ='+str(tintstr[i]),fontsize=font)
137    mpl.ylabel('Latitude (deg)',labelpad=10,fontsize=font)
138    mpl.xlabel('Longitude (deg)',labelpad=10, fontsize=font)
139    mpl.xticks(xticks,fontsize=font)
140    mpl.yticks(yticks,fontsize=font)
141    #getwinds(newlon,lat,u,v)
142
143def getnumalt(choicealt,alt):
144    numalt=np.where(abs(alt-choicealt)==min(abs(alt-choicealt)))
145    numalt=numalt[0][0]
146    return numalt
147
148#######################
149
150nbfig=size(tint)
151nbrow=2
152nbcol=2
153mpl.figure(figsize=(30, 15))
154choicealt=30 #m
155
156
157for i in range(nbfig): 
158   numalt=getnumalt(choicealt,alt)
159   print((numalt,'alt=',alt[numalt],'m'))
160   mycloud=getvar(filename1,var1,tint[i])[0,0,:,:]
161   mytmp=getvar(filename1,var2,tint[i])[0,0,:,:]
162   #myvar=getvar(filename2,var,tint[i])[0,0,:,:]
163
164   cloud=swinglon(mycloud)
165   cloud=cloud*1.e6
166   tmp=swinglon(mytmp)
167   #myvarbis=swinglon(myvar)
168
169   getfigvar(nbfig,nbrow,nbcol,i)
170
171left  = None  # the left side of the subplots of the figure
172right = None   # the right side of the subplots of the figure
173bottom = None  # the bottom of the subplots of the figure
174top = None     # the top of the subplots of the figure
175wspace = None  # the amount of width reserved for blank space between subplots
176hspace = None  # the amount of height reserved for white space between subplots
177#mpl.subplots_adjust(left, bottom, right, top, wspace, hspace)
178#mpl.subplots_adjust(hspace = .1)
179
180mpl.savefig('mapch4cloud.eps',dpi=200)
181mpl.savefig('mapch4cloud.png',dpi=200)
182
183#mpl.show()
184
185
186
187
Note: See TracBrowser for help on using the repository browser.