1 | #! /usr/bin/env python |
---|
2 | import os, sys |
---|
3 | from netCDF4 import Dataset |
---|
4 | from numpy import * |
---|
5 | import numpy as np |
---|
6 | import matplotlib.pyplot as mpl |
---|
7 | from matplotlib.cm import get_cmap |
---|
8 | import pylab |
---|
9 | from matplotlib import ticker |
---|
10 | import matplotlib.colors as colors |
---|
11 | import datetime |
---|
12 | from mpl_toolkits.basemap import Basemap, shiftgrid |
---|
13 | from FV3_utils import * |
---|
14 | |
---|
15 | ############################ |
---|
16 | filename1=name+"_A.nc" |
---|
17 | filename2=name+".nc" |
---|
18 | filename3=name+".nc" |
---|
19 | # filename3="../../phisinit.nc" |
---|
20 | var="tsurf" #variable |
---|
21 | phisinit="phisinit" #variable |
---|
22 | vari="u" |
---|
23 | varj="v" |
---|
24 | tint=[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 | |
---|
28 | altitude = 10 # default value, in km ! WARNING: only integers accepted for animation script yet |
---|
29 | if len(sys.argv)>1: |
---|
30 | altitude=float(sys.argv[1]) |
---|
31 | print("Setting altitude to ",altitude, "km") |
---|
32 | |
---|
33 | font=26 |
---|
34 | |
---|
35 | nc1=Dataset(filename1) |
---|
36 | nc2=Dataset(filename2) |
---|
37 | nc3=Dataset(filename3) |
---|
38 | |
---|
39 | lat=getvar(nc1,"latitude") |
---|
40 | lon=getvar(nc1,"longitude") |
---|
41 | alt=getvar(nc1,"altitude") |
---|
42 | tim=getvar(nc1,"Time") |
---|
43 | ############################ |
---|
44 | |
---|
45 | def 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 | |
---|
93 | def 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 | |
---|
116 | def getnumalt(choicealt,alt): |
---|
117 | numalt=np.where(abs(alt-choicealt)==min(abs(alt-choicealt))) |
---|
118 | numalt=numalt[0][0] |
---|
119 | return numalt |
---|
120 | |
---|
121 | ####################### |
---|
122 | numalt=getnumalt(altitude,alt) |
---|
123 | print(('numalt =',numalt,'altitude=',alt[numalt])) |
---|
124 | uini=getvar(nc1,vari,times=tint)[:,numalt] |
---|
125 | vini=getvar(nc1,varj,times=tint)[:,numalt] |
---|
126 | myvar=getvar(nc2,var,times=tint) |
---|
127 | myvar2=getvar(nc3,phisinit) # phisinitmyvar2=myvar2/0.6169/1000. # altitude km |
---|
128 | nbfig=uini.shape[0] |
---|
129 | print(("nbfig=",nbfig)) |
---|
130 | myvar2bis=switchlon(myvar2, lon) |
---|
131 | |
---|
132 | os.makedirs("movie_winds", exist_ok=True) |
---|
133 | |
---|
134 | for 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 | |
---|
148 | left = None # the left side of the subplots of the figure |
---|
149 | right = None # the right side of the subplots of the figure |
---|
150 | bottom = None # the bottom of the subplots of the figure |
---|
151 | top = None # the top of the subplots of the figure |
---|
152 | wspace = None # the amount of width reserved for blank space between subplots |
---|
153 | hspace = 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 | |
---|