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