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

Last change on this file was 3868, checked in by afalco, 8 days ago

Pluto: update figure scripts.
AF

  • Property svn:executable set to *
File size: 5.6 KB
Line 
1#! /usr/bin/env python
2import os, sys
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 colors
11import datetime
12from mpl_toolkits.basemap import Basemap, shiftgrid
13from FV3_utils import *
14
15############################
16filename1=name+"_A.nc"
17filename2=name+".nc"
18filename3=name+".nc"
19# filename3="../../phisinit.nc"
20var="tsurf" #variable
21phisinit="phisinit" #variable
22vari="u"
23varj="v"
24tint=[30,32] #Time must be as written in the input file
25# tint=None
26#tintstr=["03:00","09:00","15:00","21:00"] #Time must be as written in the input file
27
28altitude = 10 # default value, in km ! WARNING: only integers accepted for animation script yet
29if len(sys.argv)>1:
30    altitude=float(sys.argv[1])
31    print("Setting altitude to ",altitude, "km")
32
33font=26
34
35nc1=Dataset(filename1)
36nc2=Dataset(filename2)
37nc3=Dataset(filename3)
38
39lat=getvar(nc1,"latitude")
40lon=getvar(nc1,"longitude")
41alt=getvar(nc1,"altitude")
42tim=getvar(nc1,"Time")
43############################
44
45def getwinds(lon,lat,vecx,vecy):
46          svx='None'   # arrow every svx box
47          svy='None'
48          svx=1
49          svy=1
50          angle='uv'       # 'xy'
51          color='black'    # arrow color
52          pivot='mid'      # arrow around middle of box. Alternative : tip
53          scale=100     # scale arrow : plus grand = fleche plus petite
54          width=0.002      # width arrow
55          linewidths=0.5   # epaisseur contour arrow
56          edgecolors='k'   # couleur contour arrow
57
58    #  *scale*: [ *None* | float ]
59    #  Data units per arrow length unit, e.g., m/s per plot width; a smaller
60    #  scale parameter makes the arrow longer.  If *None*, a simple
61    #  autoscaling algorithm is used, based on the average vector length
62    #  and the number of vectors.  The arrow length unit is given by
63    #  the *scale_units* parameter
64
65    #  *scale_units*: *None*, or any of the *units* options.
66    #  For example, if *scale_units* is 'inches', *scale* is 2.0, and
67    #  ``(u,v) = (1,0)``, then the vector will be 0.5 inches long.
68    #  If *scale_units* is 'width', then the vector will be half the width
69    #  of the axes.
70
71    #  If *scale_units* is 'x' then the vector will be 0.5 x-axis
72    #  units.  To plot vectors in the x-y plane, with u and v having
73    #  the same units as x and y, use
74    #  "angles='xy', scale_units='xy', scale=1".
75
76          x, y = np.meshgrid(lon,lat)
77          q = mpl.quiver( x[::svy,::svx],y[::svy,::svx],\
78           vecx[::svy,::svx],vecy[::svy,::svx],\
79          angles=angle,color=color,pivot=pivot,\
80          scale=scale,width=width,linewidths=linewidths,edgecolors=edgecolors)
81
82          # make vector key.
83          #keyh = 1.025 ; keyv = 1.05 # upper right corner over colorbar
84          keyh = 0.97 ; keyv = 1.06
85          keyh = 0.03 ; keyv = 1.07
86          #keyh = -0.03 ; keyv = 1.08 # upper left corner
87          labelpos='E'    # position label compared to arrow : N S E W
88          p = mpl.quiverkey(q,keyh,keyv,\
89          5.0,r'$5 m/s$',\
90          fontproperties={'size': font,'weight': 'bold'},\
91          color='black',labelpos=labelpos,labelsep = 0.07)
92
93def getfigvar(i):
94    pal=get_cmap(name="OrRd")
95    lev=np.linspace(37,51,15)
96    newlon=lon+180
97    CF=mpl.contourf(newlon, lat, myvarbis,lev,cmap=pal,extend='both',alpha=0.7)
98    yticks=[-90,-60,-30,0,30,60,90]
99    xticks=[0,60,120,180,240,300,360]
100    cbar=mpl.colorbar(CF,shrink=1, format="%1.0f")
101    cbar.ax.set_title("Tsurf [K]",y=1.04,fontsize=font, pad=20)
102
103    for t in cbar.ax.get_yticklabels():
104        t.set_fontsize(font)
105
106    c=mpl.contour(newlon, lat, myvar2bis, 10,levels=np.linspace(-4,4,8), colors = 'k', linewidths = 3.5)
107    mpl.clabel(c, fmt='%2.1f',inline=1, colors='k', fontsize=23,inline_spacing=1)
108    mpl.title('Winds & Surface Temperature',fontsize=font, pad=20)
109    # mpl.title('Local Time at Sputnik Planum='+str(i*3)+'H00',fontsize=font)
110    mpl.ylabel('Latitude (deg)',labelpad=10,fontsize=font)
111    mpl.xlabel('West Longitude (deg)',labelpad=10, fontsize=font)
112    mpl.xticks(xticks,fontsize=font)
113    mpl.yticks(yticks,fontsize=font)
114    getwinds(newlon,lat,u,v)
115
116def getnumalt(choicealt,alt):
117    numalt=np.where(abs(alt-choicealt)==min(abs(alt-choicealt)))
118    numalt=numalt[0][0]
119    return numalt
120
121#######################
122numalt=getnumalt(altitude,alt)
123print(('numalt =',numalt,'altitude=',alt[numalt]))
124uini=getvar(nc1,vari,times=tint)[:,numalt]
125vini=getvar(nc1,varj,times=tint)[:,numalt]
126myvar=getvar(nc2,var,times=tint)
127myvar2=getvar(nc3,phisinit) # phisinitmyvar2=myvar2/0.6169/1000.  # altitude km
128nbfig=uini.shape[0]
129print(("nbfig=",nbfig))
130myvar2bis=switchlon(myvar2, lon)
131
132os.makedirs("movie_winds", exist_ok=True)
133
134for i in range(nbfig):
135   mpl.figure(figsize=(30, 15))
136   u2=uini[i,:,:]
137   v2=vini[i,:,:]
138   myv=myvar[i,:,:]
139   u=switchlon(u2, lon)
140   v=switchlon(v2, lon)
141   myvarbis=switchlon(myv, lon)
142   print(i,"/",nbfig)
143   getfigvar(i)
144#    mpl.tight_layout()
145   mpl.savefig(f"movie_winds/mapwinds_{altitude:.0f}km_{i:03}.eps",dpi=200)
146   mpl.savefig(f"movie_winds/mapwinds_{altitude:.0f}km_{i:03}.png",dpi=200)
147
148left  = None  # the left side of the subplots of the figure
149right = None   # the right side of the subplots of the figure
150bottom = None  # the bottom of the subplots of the figure
151top = None     # the top of the subplots of the figure
152wspace = None  # the amount of width reserved for blank space between subplots
153hspace = None  # the amount of height reserved for white space between subplots
154#mpl.subplots_adjust(left, bottom, right, top, wspace, hspace)
155#mpl.subplots_adjust(hspace = .1)
156
157#mpl.show()
158
159
160
Note: See TracBrowser for help on using the repository browser.