1 | ####################### |
---|
2 | ##### PLANETOPLOT ##### |
---|
3 | ####################### |
---|
4 | |
---|
5 | ### A. Spiga -- LMD -- 06~09/2011 -- General building and mapping capabilities |
---|
6 | ### T. Navarro -- LMD -- 10~11/2011 -- Improved use for GCM and added sections + 1Dplot capabilities |
---|
7 | ### A. Colaitis -- LMD -- 11/2011 -- Mostly minor improvements and inter-plot operation capabilities + zrecast interpolation for gcm |
---|
8 | ### A. Spiga -- LMD -- 11/2011 -- Extended multivar subplot capabilities + cosmetic changes + general cleaning and tests |
---|
9 | |
---|
10 | def planetoplot (namefiles,\ |
---|
11 | level=0,\ |
---|
12 | vertmode=0,\ |
---|
13 | proj=None,\ |
---|
14 | back=None,\ |
---|
15 | target=None, |
---|
16 | stride=3,\ |
---|
17 | var=None,\ |
---|
18 | colorb="def",\ |
---|
19 | winds=False,\ |
---|
20 | addchar=None,\ |
---|
21 | interv=[0,1],\ |
---|
22 | vmin=None,\ |
---|
23 | vmax=None,\ |
---|
24 | tile=False,\ |
---|
25 | zoom=None,\ |
---|
26 | display=True,\ |
---|
27 | hole=False,\ |
---|
28 | save="gui",\ |
---|
29 | anomaly=False,\ |
---|
30 | var2=None,\ |
---|
31 | ndiv=10,\ |
---|
32 | mult=1.,\ |
---|
33 | zetitle="fill",\ |
---|
34 | slon=None,\ |
---|
35 | slat=None,\ |
---|
36 | svert=None,\ |
---|
37 | stime=None,\ |
---|
38 | outputname=None,\ |
---|
39 | resolution=200,\ |
---|
40 | ope=None,\ |
---|
41 | fileref=None,\ |
---|
42 | minop=0.,\ |
---|
43 | maxop=0.,\ |
---|
44 | titleref="fill",\ |
---|
45 | invert_y=False,\ |
---|
46 | xaxis=[None,None],\ |
---|
47 | yaxis=[None,None],\ |
---|
48 | ylog=False,\ |
---|
49 | yintegral=False,\ |
---|
50 | blat=None,\ |
---|
51 | tsat=False,\ |
---|
52 | flagnolow=False): |
---|
53 | |
---|
54 | |
---|
55 | #################################################################################################################### |
---|
56 | ### Colorbars http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps?action=AttachFile&do=get&target=colormaps3.png |
---|
57 | |
---|
58 | ################################# |
---|
59 | ### Load librairies and functions |
---|
60 | from netCDF4 import Dataset |
---|
61 | from myplot import getcoord2d,define_proj,makeplotres,simplinterv,vectorfield,ptitle,latinterv,getproj,wrfinterv,dumpbdy,\ |
---|
62 | fmtvar,definecolorvec,defcolorb,getprefix,putpoints,calculate_bounds,errormess,definesubplot,\ |
---|
63 | zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow,\ |
---|
64 | getname,localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar,hole_bounds |
---|
65 | from mymath import deg,max,min,mean,get_tsat,writeascii |
---|
66 | import matplotlib as mpl |
---|
67 | from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title |
---|
68 | from matplotlib.cm import get_cmap |
---|
69 | import numpy as np |
---|
70 | from numpy.core.defchararray import find |
---|
71 | |
---|
72 | ################################ |
---|
73 | ### Preliminary stuff |
---|
74 | ################################ |
---|
75 | print "********************************************" |
---|
76 | print "********** WELCOME TO PLANETOPLOT **********" |
---|
77 | print "********************************************" |
---|
78 | if not isinstance(namefiles, np.ndarray): namefiles = [namefiles] |
---|
79 | if not isinstance(var, np.ndarray): var = [var] |
---|
80 | |
---|
81 | ################################ |
---|
82 | ### Which plot needs to be done? |
---|
83 | ################################ |
---|
84 | nlon, nlat, nvert, ntime, mapmode, nslices = determineplot(slon, slat, svert, stime) |
---|
85 | vlon = None ; vlat = None |
---|
86 | if slon is not None: vlon = slon[0][0] |
---|
87 | if slat is not None: vlat = slat[0][0] |
---|
88 | if mapmode == 0: winds=False |
---|
89 | elif mapmode == 1: |
---|
90 | if svert is None: svert = readslices(str(level)) ; nvert=1 |
---|
91 | zelen = len(namefiles)*len(var) |
---|
92 | numplot = zelen*nslices |
---|
93 | print "********** FILES, SLICES, VARS, TOTAL PLOTS: ", len(namefiles), nslices, len(var), numplot |
---|
94 | if ope is not None: |
---|
95 | if fileref is not None: zelen = zelen + 2 |
---|
96 | elif "var" in ope: zelen = zelen + 1 |
---|
97 | all_var = [[]]*zelen ; all_var2 = [[]]*zelen ; all_title = [[]]*zelen ; all_varname = [[]]*zelen ; all_namefile = [[]]*zelen ; all_time = [[]]*zelen |
---|
98 | |
---|
99 | ################################################################################################# |
---|
100 | ### Loop over the files + vars initially separated by commas to be plotted on the same figure ### |
---|
101 | ################################################################################################# |
---|
102 | k = 0 ; firstfile = True |
---|
103 | for nnn in range(len(namefiles)): |
---|
104 | for vvv in range(len(var)): |
---|
105 | |
---|
106 | print "********** LOOP..... THIS IS SUBPLOT NUMBER.....",k |
---|
107 | |
---|
108 | ###################### |
---|
109 | ### Load NETCDF object |
---|
110 | namefile = namefiles[nnn] ; print "********** THE NAMEFILE IS....", namefile |
---|
111 | nc = Dataset(namefile) |
---|
112 | |
---|
113 | ################################## |
---|
114 | ### Initial checks and definitions |
---|
115 | ### ... TYPEFILE |
---|
116 | typefile = whatkindfile(nc) |
---|
117 | if typefile in ['mesoideal']: mapmode=0;winds=False |
---|
118 | if firstfile: print "********** MAPMODE: ", mapmode |
---|
119 | if firstfile: typefile0 = typefile |
---|
120 | elif typefile != typefile0: errormess("Not the same kind of files !", [typefile0, typefile]) |
---|
121 | ### ... VAR |
---|
122 | varname=var[vvv] |
---|
123 | print "********** THE VAR IS....",varname, var2 |
---|
124 | if varname not in nc.variables: varname = False |
---|
125 | ### ... WINDS |
---|
126 | if winds: |
---|
127 | [uchar,vchar,metwind] = getwinddef(nc) |
---|
128 | if uchar == 'not found': winds = False |
---|
129 | if not varname and not winds: errormess("please set at least winds or var",printvar=nc.variables) |
---|
130 | ### ... COORDINATES, could be moved below |
---|
131 | [lon2d,lat2d] = getcoorddef(nc) |
---|
132 | ### ... PROJECTION |
---|
133 | if ((proj == None) and (typefile not in ['mesoideal'])): proj = getproj(nc) |
---|
134 | |
---|
135 | ########################################################## |
---|
136 | if typefile == "gcm": |
---|
137 | lat = nc.variables["latitude"][:] ; lon = nc.variables["longitude"][:] |
---|
138 | if "Time" in nc.variables: time = nc.variables["Time"][:] |
---|
139 | elif "time" in nc.variables: time = nc.variables["time"][:] |
---|
140 | else: errormess("no time axis found.") |
---|
141 | vert = nc.variables["altitude"][:] |
---|
142 | elif typefile in ['meso','mesoapi','geo','mesoideal']: |
---|
143 | if vlon is not None or vlat is not None: indices = bidimfind(lon2d,lat2d,vlon,vlat) ; print '********** INDICES: ', indices |
---|
144 | if slon is not None: slon[0][0] = indices[0] ; slon[0][1] = indices[0] |
---|
145 | if slat is not None: slat[0][0] = indices[1] ; slat[0][1] = indices[1] |
---|
146 | if varname in ['PHTOT','W']: vertdim='BOTTOM-TOP_PATCH_END_STAG' |
---|
147 | else: vertdim='BOTTOM-TOP_PATCH_END_UNSTAG' |
---|
148 | if varname in ['V']: latdim='SOUTH-NORTH_PATCH_END_STAG' |
---|
149 | else: latdim='SOUTH-NORTH_PATCH_END_UNSTAG' |
---|
150 | if varname in ['U']: londim='WEST-EAST_PATCH_END_STAG' |
---|
151 | else: londim='WEST-EAST_PATCH_END_UNSTAG' |
---|
152 | lon = np.arange(0,getattr(nc,londim),1) ; lat = np.arange(0,getattr(nc,latdim),1) |
---|
153 | time = np.arange(0,len(nc.variables["Times"]),1) |
---|
154 | if typefile in ['geo']: vert = [0.] ; stime = readslices(str(0)) |
---|
155 | else: |
---|
156 | if vertmode is None: vertmode=0 |
---|
157 | if vertmode == 0: vert = np.arange(0,getattr(nc,vertdim),1) |
---|
158 | else: vert = nc.variables["vert"][:] |
---|
159 | #if firstfile: |
---|
160 | # lat0 = lat |
---|
161 | #elif len(lat0) != len(lat): |
---|
162 | # errormess("Not the same latitude lengths !", [len(lat0), len(lat)]) |
---|
163 | #elif sum((lat == lat0) == False) != 0: |
---|
164 | # errormess("Not the same latitudes !", [lat,lat0]) |
---|
165 | ## Faire d'autre checks sur les compatibilites entre fichiers!! |
---|
166 | ########################################################## |
---|
167 | |
---|
168 | if firstfile: |
---|
169 | ########################## |
---|
170 | ### Define plot boundaries |
---|
171 | ### todo: possible areas in latinterv in argument (ex: "Far_South_Pole") |
---|
172 | if proj in ["npstere","spstere"]: [wlon,wlat] = polarinterv(lon2d,lat2d) |
---|
173 | elif proj in ["lcc","laea"]: [wlon,wlat] = wrfinterv(lon2d,lat2d) |
---|
174 | else: [wlon,wlat] = simplinterv(lon2d,lat2d) |
---|
175 | if zoom: [wlon,wlat] = zoomset(wlon,wlat,zoom) |
---|
176 | |
---|
177 | all_varname[k] = varname |
---|
178 | all_namefile[k] = namefile |
---|
179 | all_time[k] = time |
---|
180 | if var2: all_var2[k] = getfield(nc,var2) |
---|
181 | ##### SPECIFIC |
---|
182 | if varname in ["temp","t","T_nadir_nit","T_nadir_day","temp_day","temp_night"] and tsat: |
---|
183 | tt=getfield(nc,varname) ; print "computing Tsat-T, I ASSUME Z-AXIS IS PRESSURE" |
---|
184 | if type(tt).__name__=='MaskedArray': tt.set_fill_value([np.NaN]) ; tinput=tt.filled() |
---|
185 | else: tinput=tt |
---|
186 | all_var[k]=get_tsat(vert,tinput,zlon=lon,zlat=lat,zalt=vert,ztime=time) |
---|
187 | else: |
---|
188 | ##### GENERAL STUFF HERE |
---|
189 | all_var[k] = getfield(nc,varname) |
---|
190 | print "********** all_var[k].shape", all_var[k].shape |
---|
191 | k += 1 |
---|
192 | firstfile = False |
---|
193 | #### End of for namefile in namefiles |
---|
194 | |
---|
195 | ################################## |
---|
196 | ### Operation on files |
---|
197 | if ope is not None: |
---|
198 | print ope |
---|
199 | if "var" not in ope: |
---|
200 | if len(var) > 1: errormess("for this operation... please set only one var !") |
---|
201 | if ope in ["-","+"]: |
---|
202 | if fileref is not None: all_var[k] = getfield(Dataset(fileref),all_varname[k-1]) ; all_varname[k] = all_varname[k-1] ; all_time[k] = all_time[k-1] ; all_namefile[k] = all_namefile[k-1] |
---|
203 | else: errormess("fileref is missing!") |
---|
204 | if ope == "-": all_var[k+1]= all_var[k-1] - all_var[k] |
---|
205 | elif ope == "+": all_var[k+1]= all_var[k-1] + all_var[k] |
---|
206 | all_varname[k+1] = all_varname[k] ; all_time[k+1] = all_time[k] ; all_namefile[k+1] = all_namefile[k] ; numplot = numplot+2 |
---|
207 | elif ope in ["cat"]: |
---|
208 | tab = all_var[0];k = 1 |
---|
209 | while k != len(namefiles)-1: |
---|
210 | tab = np.append(tab,all_var[k],axis=0) ; k += 1 |
---|
211 | all_time[0] = np.arange(0,len(tab),1) ### AS: time reference is too simplistic, should be better |
---|
212 | all_var[0] = np.array(tab) ; numplot = 1 |
---|
213 | else: errormess(ope+" : non-implemented operation. Check pp.py --help") |
---|
214 | else: |
---|
215 | if len(namefiles) > 1: errormess("for this operation... please set only one file !") |
---|
216 | if len(var) > 2: errormess("not sure this works for more than 2 vars... please check.") |
---|
217 | if ope in ["div_var"]: all_var[k] = all_var[k-2] / all_var[k-1] ; insert = '_div_' |
---|
218 | elif ope in ["mul_var"]: all_var[k] = all_var[k-2] * all_var[k-1] ; insert = '_mul_' |
---|
219 | elif ope in ["add_var"]: all_var[k] = all_var[k-2] + all_var[k-1] ; insert = '_add_' |
---|
220 | elif ope in ["sub_var"]: all_var[k] = all_var[k-2] - all_var[k-1] ; insert = '_sub_' |
---|
221 | else: errormess(ope+" : non-implemented operation. Check pp.py --help") |
---|
222 | numplot = numplot + 1 ; all_time[k] = all_time[k-1] ; all_namefile[k] = all_namefile[k-1] |
---|
223 | all_varname[k] = all_varname[k-2] + insert + all_varname[k-1] |
---|
224 | |
---|
225 | ################################## |
---|
226 | ### Open a figure and set subplots |
---|
227 | fig = figure() |
---|
228 | subv,subh = definesubplot( numplot, fig ) |
---|
229 | |
---|
230 | ################################# |
---|
231 | ### Time loop for plotting device |
---|
232 | nplot = 1;error = False |
---|
233 | print "********************************************" |
---|
234 | while error is False: |
---|
235 | print "********** NPLOT", nplot |
---|
236 | |
---|
237 | ### General plot settings |
---|
238 | if nplot > numplot: break |
---|
239 | if numplot > 1: subplot(subv,subh,nplot) |
---|
240 | |
---|
241 | ### Map projection |
---|
242 | if mapmode == 1: |
---|
243 | m = define_proj(proj,wlon,wlat,back=back,blat=blat) |
---|
244 | x, y = m(lon2d, lat2d) |
---|
245 | |
---|
246 | #################################################################### |
---|
247 | ## get all indexes to be taken into account for this subplot and then reduce field |
---|
248 | ## We plot 1) all lon slices 2) all lat slices 3) all vert slices 4) all time slices and then go to the next slice |
---|
249 | indexlon = getsindex(slon,(nplot-1)%nlon,lon) |
---|
250 | indexlat = getsindex(slat,((nplot-1)//nlon)%nlat,lat) |
---|
251 | indexvert = getsindex(svert,((nplot-1)//(nlon*nlat))%nvert,vert) |
---|
252 | if ope is not None: |
---|
253 | if fileref is not None: index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(len(namefiles)+2) ## OK only 1 var, see test in the beginning |
---|
254 | elif "var" in ope: index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(len(var)+1) ## OK only 1 file, see test in the beginning |
---|
255 | else: yeah = len(namefiles)*len(var) ; index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%yeah |
---|
256 | time = all_time[index_f] |
---|
257 | if stime is not None: |
---|
258 | if stime[0][0] < 0: |
---|
259 | if typefile in ['mesoapi','meso']: |
---|
260 | for i in range(len(time)): time[i] = localtime ( interv[0]+time[i]*interv[1], 0.5*(wlon[0]+wlon[1]) ) |
---|
261 | print "OK... WORKING WITH LOCAL TIMES" |
---|
262 | else: errormess("local times not supported for GCM files. not too hard to modify the code though.") |
---|
263 | if mapmode == 1 and stime is None: indextime = 1 |
---|
264 | else: indextime = getsindex(stime,((nplot-1)//(nlon*nlat*nvert))%ntime,time) |
---|
265 | ltst = None |
---|
266 | if typefile in ['mesoapi','meso'] and indextime is not None: ltst = localtime ( interv[0]+indextime*interv[1], 0.5*(wlon[0]+wlon[1]) ) |
---|
267 | print "********** index lon, lat, vert, time ",indexlon,indexlat,indexvert,indextime |
---|
268 | #################################################################### |
---|
269 | |
---|
270 | ticks = ndiv + 1 |
---|
271 | |
---|
272 | #### Contour plot |
---|
273 | if var2: |
---|
274 | what_I_plot, error = reducefield(all_var2[index_f], d4=indextime, d1=indexlon, d2=indexlat , d3=indexvert, yint=yintegral, alt=vert) |
---|
275 | #what_I_plot = what_I_plot*mult |
---|
276 | if not error: |
---|
277 | if mapmode == 1: |
---|
278 | if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(what_I_plot,6) |
---|
279 | zevmin, zevmax = calculate_bounds(what_I_plot) |
---|
280 | zelevels = np.linspace(zevmin,zevmax,ticks) #20) |
---|
281 | if var2 == 'HGT': zelevels = np.arange(-10000.,30000.,2000.) |
---|
282 | if mapmode == 0: |
---|
283 | what_I_plot, x, y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\ |
---|
284 | indextime,what_I_plot, len(all_var2[index_f].shape),vertmode) |
---|
285 | ### If we plot a 2-D field |
---|
286 | if len(what_I_plot.shape) is 2: |
---|
287 | cs = contour(x,y,what_I_plot, zelevels, colors='k', linewidths = 1 ) #0.33 colors='w' )# , alpha=0.5) |
---|
288 | # clabel(cs,#zelevels[::2], |
---|
289 | # inline=3, |
---|
290 | # fmt='%1.1e', |
---|
291 | # fontsize=7) |
---|
292 | ### If we plot a 1-D field |
---|
293 | elif len(what_I_plot.shape) is 1: |
---|
294 | plot(what_I_plot,x) |
---|
295 | else: |
---|
296 | errormess("There is an error in reducing field !") |
---|
297 | |
---|
298 | #### Shaded plot |
---|
299 | varname = all_varname[index_f] |
---|
300 | if varname: |
---|
301 | what_I_plot, error = reducefield(all_var[index_f], d4=indextime, d1=indexlon, d2=indexlat , d3=indexvert , yint=yintegral, alt=vert, anomaly=anomaly) |
---|
302 | what_I_plot = what_I_plot*mult |
---|
303 | if not error: |
---|
304 | fvar = varname |
---|
305 | if anomaly: fvar = 'anomaly' |
---|
306 | ##### MAPMODE-SPECIFIC SETTINGS ##### |
---|
307 | if mapmode == 1: |
---|
308 | if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(what_I_plot,6) |
---|
309 | elif mapmode == 0: |
---|
310 | what_I_plot, x, y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\ |
---|
311 | indextime,what_I_plot, len(all_var[index_f].shape),vertmode) |
---|
312 | zxmin, zxmax = xaxis ; zymin, zymax = yaxis |
---|
313 | if zxmin is not None: mpl.pyplot.xlim(xmin=zxmin) |
---|
314 | if zxmax is not None: mpl.pyplot.xlim(xmax=zxmax) |
---|
315 | if zymin is not None: mpl.pyplot.ylim(ymin=zymin) |
---|
316 | if zymax is not None: mpl.pyplot.ylim(ymax=zymax) |
---|
317 | if invert_y: lima,limb = mpl.pyplot.ylim() ; mpl.pyplot.ylim(limb,lima) |
---|
318 | if ylog: mpl.pyplot.semilogy() |
---|
319 | if (fileref is not None) and (index_f is numplot-1): zevmin, zevmax = calculate_bounds(what_I_plot,vmin=minop,vmax=maxop) |
---|
320 | else: zevmin, zevmax = calculate_bounds(what_I_plot,vmin=vmin,vmax=vmax) |
---|
321 | if colorb in ["def","nobar"]: palette = get_cmap(name=defcolorb(fvar.upper())) |
---|
322 | elif (fileref is not None) and (index_f is numplot-1): palette = get_cmap(name="RdBu_r") |
---|
323 | else: palette = get_cmap(name=colorb) |
---|
324 | ##### 2D field |
---|
325 | if len(what_I_plot.shape) is 2: |
---|
326 | if hole: what_I_plot = hole_bounds(what_I_plot,zevmin,zevmax) |
---|
327 | else: what_I_plot = bounds(what_I_plot,zevmin,zevmax) |
---|
328 | if flagnolow: what_I_plot = nolow(what_I_plot) |
---|
329 | if not tile: |
---|
330 | #zelevels = np.linspace(zevmin*(1. + 1.e-7),zevmax*(1. - 1.e-7)) #,num=20) |
---|
331 | zelevels = np.linspace(zevmin,zevmax,num=ticks) |
---|
332 | print np.array(x).shape |
---|
333 | print np.array(y).shape |
---|
334 | print np.array(what_I_plot).shape |
---|
335 | |
---|
336 | if mapmode == 1: m.contourf( x, y, what_I_plot, zelevels, cmap = palette) |
---|
337 | elif mapmode == 0: contourf( x, y, what_I_plot, zelevels, cmap = palette) |
---|
338 | else: |
---|
339 | if mapmode == 1: m.pcolor( x, y, what_I_plot, cmap = palette, vmin=zevmin, vmax=zevmax ) |
---|
340 | elif mapmode == 0: pcolor( x, y, what_I_plot, cmap = palette, vmin=zevmin, vmax=zevmax ) |
---|
341 | if colorb != 'nobar': |
---|
342 | if (fileref is not None) and (index_f is numplot-1): daformat = "%.3f" |
---|
343 | else: daformat = fmtvar(fvar.upper()) |
---|
344 | colorbar( fraction=0.05,pad=0.03,format=daformat,\ |
---|
345 | ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,20])),extend='neither',spacing='proportional' ) |
---|
346 | ##### 1D field |
---|
347 | elif len(what_I_plot.shape) is 1: |
---|
348 | plot(x,what_I_plot) |
---|
349 | if save == 'txt': writeascii(np.transpose(what_I_plot),'profile'+str(nplot)+'.txt') |
---|
350 | |
---|
351 | #### Other cases: (maybe plot 3-D field one day or movie ??) |
---|
352 | else: |
---|
353 | print "WARNING!!! ",len(what_I_plot.shape),"-D PLOT NOT SUPPORTED !!! dimensions: ",what_I_plot.shape |
---|
354 | errormess("Are you sure you did not forget to prescribe a dimension ?") |
---|
355 | else: |
---|
356 | errormess("There is an error in reducing field !") |
---|
357 | |
---|
358 | ### Vector plot --- a adapter |
---|
359 | if winds: |
---|
360 | vecx, error = reducefield( getfield(nc,uchar), d4=indextime, d3=indexvert , yint=yintegral , alt=vert) |
---|
361 | vecy, error = reducefield( getfield(nc,vchar), d4=indextime, d3=indexvert , yint=yintegral , alt=vert) |
---|
362 | #what_I_plot, error = reducefield(all_var[index_f], d4=indextime, d1=indexlon, d2=indexlat , d3=indexvert ) |
---|
363 | if not error: |
---|
364 | if typefile in ['mesoapi','meso']: |
---|
365 | [vecx,vecy] = [dumpbdy(vecx,6,stag=uchar), dumpbdy(vecy,6,stag=vchar)] |
---|
366 | key = True |
---|
367 | elif typefile in ['gcm']: |
---|
368 | key = False |
---|
369 | if metwind: [vecx,vecy] = m.rotate_vector(vecx, vecy, lon2d, lat2d) |
---|
370 | if varname == False: colorvec = definecolorvec(back) |
---|
371 | else: colorvec = definecolorvec(colorb) |
---|
372 | vectorfield(vecx, vecy,\ |
---|
373 | x, y, stride=stride, csmooth=2,\ |
---|
374 | #scale=15., factor=300., color=colorvec, key=key) |
---|
375 | scale=20., factor=250., color=colorvec, key=key) |
---|
376 | #200. ## or csmooth=stride |
---|
377 | |
---|
378 | ### Next subplot |
---|
379 | basename = getname(var=varname,winds=winds,anomaly=anomaly) |
---|
380 | basename = basename + getstralt(nc,level) |
---|
381 | if typefile in ['mesoapi','meso']: |
---|
382 | if slon is not None: basename = basename + "_lon_" + str(int(lon2d[indices[1],indices[0]])) |
---|
383 | if slat is not None: basename = basename + "_lat_" + str(int(lat2d[indices[1],indices[0]])) |
---|
384 | plottitle = basename |
---|
385 | if addchar: |
---|
386 | [addchar,gogol,gogol2] = getlschar ( all_namefile[index_f] ) |
---|
387 | plottitle = plottitle + addchar + "_LT" |
---|
388 | else: plottitle = plottitle + "_LT" |
---|
389 | if ltst is not None: plottitle = plottitle + str(ltst) |
---|
390 | else: |
---|
391 | if fileref is not None: |
---|
392 | if index_f is numplot-1: plottitle = basename+' '+"fig(1) "+ope+" fig(2)" |
---|
393 | elif index_f is numplot-2: plottitle = basename+' '+fileref |
---|
394 | else: plottitle = basename+' '+namefiles[0]#index_f] |
---|
395 | else: plottitle = basename+' '+namefiles[0]#index_f] |
---|
396 | if mult != 1: plottitle = str(mult) + "*" + plottitle |
---|
397 | if zetitle != "fill": |
---|
398 | plottitle = zetitle |
---|
399 | if titleref is "fill": titleref=zetitle |
---|
400 | if fileref is not None: |
---|
401 | if index_f is numplot-2: plottitle = titleref |
---|
402 | if index_f is numplot-1: plottitle = "fig(1) "+ope+" fig(2)" |
---|
403 | # if indexlon is not None: plottitle = plottitle + " lon: " + str(min(lon[indexlon])) +" "+ str(max(lon[indexlon])) |
---|
404 | # if indexlat is not None: plottitle = plottitle + " lat: " + str(min(lat[indexlat])) +" "+ str(max(lat[indexlat])) |
---|
405 | # if indexvert is not None: plottitle = plottitle + " vert: " + str(min(vert[indexvert])) +" "+ str(max(vert[indexvert])) |
---|
406 | # if indextime is not None: plottitle = plottitle + " time: " + str(min(time[indextime])) +" "+ str(max(time[indextime])) |
---|
407 | title( plottitle ) |
---|
408 | if nplot >= numplot: error = True |
---|
409 | nplot += 1 |
---|
410 | |
---|
411 | |
---|
412 | |
---|
413 | |
---|
414 | |
---|
415 | |
---|
416 | |
---|
417 | |
---|
418 | ########################################################################## |
---|
419 | ### Save the figure in a file in the data folder or an user-defined folder |
---|
420 | if outputname is None: |
---|
421 | if typefile in ['meso','mesoapi']: prefix = getprefix(nc) |
---|
422 | elif typefile in ['gcm']: prefix = 'LMD_GCM_' |
---|
423 | else: prefix = '' |
---|
424 | ### |
---|
425 | zeplot = prefix + basename |
---|
426 | if addchar: zeplot = zeplot + addchar |
---|
427 | if numplot <= 0: zeplot = zeplot + "_LT"+str(abs(numplot)) |
---|
428 | ### |
---|
429 | if not target: zeplot = namefile[0:find(namefile,'wrfout')] + zeplot |
---|
430 | else: zeplot = target + "/" + zeplot |
---|
431 | ### |
---|
432 | else: |
---|
433 | zeplot=outputname |
---|
434 | |
---|
435 | pad_inches_value = 0.35 |
---|
436 | print "********** SAVE ", save |
---|
437 | if save == 'png': |
---|
438 | if display: makeplotres(zeplot,res=100.,pad_inches_value=pad_inches_value) #,erase=True) ## a miniature |
---|
439 | makeplotres(zeplot,res=resolution,pad_inches_value=pad_inches_value,disp=False) |
---|
440 | elif save in ['eps','svg','pdf']: makeplotres(zeplot,pad_inches_value=pad_inches_value,disp=False,ext=save) |
---|
441 | elif save == 'gui': show() |
---|
442 | elif save == 'txt': print "Saved results in txt file." |
---|
443 | else: |
---|
444 | print "INFO: save mode not supported. using gui instead." |
---|
445 | show() |
---|
446 | |
---|
447 | ############### |
---|
448 | ### Now the end |
---|
449 | return zeplot |
---|