[349] | 1 | ####################### |
---|
| 2 | ##### PLANETOPLOT ##### |
---|
| 3 | ####################### |
---|
[345] | 4 | |
---|
[349] | 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 |
---|
[392] | 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 |
---|
[345] | 9 | |
---|
| 10 | def planetoplot (namefiles,\ |
---|
[351] | 11 | level=0,\ |
---|
[350] | 12 | vertmode=0,\ |
---|
[345] | 13 | proj=None,\ |
---|
| 14 | back=None,\ |
---|
| 15 | target=None, |
---|
| 16 | stride=3,\ |
---|
[350] | 17 | numplot=None,\ |
---|
[345] | 18 | var=None,\ |
---|
| 19 | colorb="def",\ |
---|
[399] | 20 | winds=False,\ |
---|
[345] | 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,\ |
---|
[359] | 40 | stime=None,\ |
---|
| 41 | outputname=None,\ |
---|
| 42 | resolution=200,\ |
---|
| 43 | ope=None,\ |
---|
| 44 | fileref=None,\ |
---|
| 45 | minop=0.,\ |
---|
| 46 | maxop=0.,\ |
---|
[363] | 47 | titleref="fill",\ |
---|
[369] | 48 | invert_y=False,\ |
---|
| 49 | xaxis=[None,None],\ |
---|
[372] | 50 | yaxis=[None,None],\ |
---|
[382] | 51 | ylog=False,\ |
---|
[385] | 52 | yintegral=False,\ |
---|
[388] | 53 | blat=None,\ |
---|
[418] | 54 | tsat=False,\ |
---|
[419] | 55 | flagnolow=False): |
---|
[345] | 56 | |
---|
[359] | 57 | |
---|
[345] | 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,\ |
---|
[418] | 67 | getname,localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar,hole_bounds |
---|
[402] | 68 | from mymath import deg,max,min,mean,get_tsat,writeascii |
---|
[363] | 69 | import matplotlib as mpl |
---|
[392] | 70 | from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title |
---|
[345] | 71 | from matplotlib.cm import get_cmap |
---|
| 72 | import numpy as np |
---|
| 73 | from numpy.core.defchararray import find |
---|
[359] | 74 | |
---|
[349] | 75 | ################################ |
---|
[392] | 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 | ################################ |
---|
[349] | 86 | ### Which plot needs to be done? |
---|
[392] | 87 | ################################ |
---|
[349] | 88 | nlon, nlat, nvert, ntime, mapmode, nslices = determineplot(slon, slat, svert, stime) |
---|
[399] | 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] |
---|
[392] | 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 |
---|
[406] | 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 |
---|
[392] | 101 | |
---|
| 102 | ################################################################################################# |
---|
| 103 | ### Loop over the files + vars initially separated by commas to be plotted on the same figure ### |
---|
| 104 | ################################################################################################# |
---|
[399] | 105 | k = 0 ; firstfile = True |
---|
[392] | 106 | for nnn in range(len(namefiles)): |
---|
| 107 | for vvv in range(len(var)): |
---|
| 108 | |
---|
| 109 | print "********** LOOP..... THIS IS SUBPLOT NUMBER.....",k |
---|
| 110 | |
---|
[345] | 111 | ###################### |
---|
| 112 | ### Load NETCDF object |
---|
[392] | 113 | namefile = namefiles[nnn] ; print "********** THE NAMEFILE IS....", namefile |
---|
[345] | 114 | nc = Dataset(namefile) |
---|
[351] | 115 | |
---|
[345] | 116 | ################################## |
---|
| 117 | ### Initial checks and definitions |
---|
[349] | 118 | ### ... TYPEFILE |
---|
| 119 | typefile = whatkindfile(nc) |
---|
[392] | 120 | if firstfile: typefile0 = typefile |
---|
| 121 | elif typefile != typefile0: errormess("Not the same kind of files !", [typefile0, typefile]) |
---|
[349] | 122 | ### ... VAR |
---|
[392] | 123 | varname=var[vvv] |
---|
| 124 | print "********** THE VAR IS....",varname, var2 |
---|
| 125 | if varname not in nc.variables: varname = False |
---|
[349] | 126 | ### ... WINDS |
---|
| 127 | if winds: |
---|
[345] | 128 | [uchar,vchar,metwind] = getwinddef(nc) |
---|
| 129 | if uchar == 'not found': winds = False |
---|
[392] | 130 | if not varname and not winds: errormess("please set at least winds or var",printvar=nc.variables) |
---|
[349] | 131 | ### ... COORDINATES, could be moved below |
---|
[399] | 132 | [lon2d,lat2d] = getcoorddef(nc) |
---|
[349] | 133 | ### ... PROJECTION |
---|
[392] | 134 | if proj == None: proj = getproj(nc) |
---|
[345] | 135 | |
---|
[349] | 136 | ########################################################## |
---|
| 137 | if typefile == "gcm": |
---|
[402] | 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.") |
---|
[349] | 142 | vert = nc.variables["altitude"][:] |
---|
[350] | 143 | elif typefile in ['meso','mesoapi']: |
---|
[399] | 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] |
---|
[393] | 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' |
---|
[402] | 153 | lon = np.arange(0,getattr(nc,londim),1) ; lat = np.arange(0,getattr(nc,latdim),1) |
---|
[393] | 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) |
---|
[350] | 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!! |
---|
[349] | 165 | ########################################################## |
---|
[345] | 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) |
---|
[380] | 175 | |
---|
[402] | 176 | all_varname[k] = varname |
---|
| 177 | all_namefile[k] = namefile |
---|
[406] | 178 | all_time[k] = time |
---|
[402] | 179 | if var2: all_var2[k] = getfield(nc,var2) |
---|
[392] | 180 | ##### SPECIFIC |
---|
[398] | 181 | if varname in ["temp","t","T_nadir_nit","T_nadir_day","temp_day","temp_night"] and tsat: |
---|
[392] | 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 |
---|
[391] | 185 | all_var[k]=get_tsat(vert,tinput,zlon=lon,zlat=lat,zalt=vert,ztime=time) |
---|
[388] | 186 | else: |
---|
[392] | 187 | ##### GENERAL STUFF HERE |
---|
| 188 | all_var[k] = getfield(nc,varname) |
---|
| 189 | print "********** all_var[k].shape", all_var[k].shape |
---|
[345] | 190 | k += 1 |
---|
| 191 | firstfile = False |
---|
| 192 | #### End of for namefile in namefiles |
---|
| 193 | |
---|
[359] | 194 | ################################## |
---|
[380] | 195 | ### Operation on files |
---|
[392] | 196 | ### ... for the moment only OK when 1 var only |
---|
[380] | 197 | if ope is not None: |
---|
| 198 | print ope |
---|
| 199 | if ope in ["-","+"]: |
---|
[392] | 200 | if fileref is not None: all_var[k] = getfield(Dataset(fileref),all_varname[k-1]) ; all_varname[k] = all_varname[k-1] |
---|
[380] | 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] |
---|
[402] | 204 | all_varname[k+1] = all_varname[k] ; numplot = numplot+2 |
---|
[380] | 205 | elif ope in ["cat"]: |
---|
[399] | 206 | tab = all_var[0];k = 1 |
---|
[380] | 207 | while k != len(namefiles)-1: |
---|
[402] | 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 |
---|
[359] | 211 | elif ope is not None: |
---|
[380] | 212 | errormess(ope+" : non-implemented operation. Available op. are + and -.") |
---|
[345] | 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 |
---|
[380] | 221 | found_lct = False;nplot = 1;itime = first;error = False |
---|
[345] | 222 | if itstep is None and numplot > 0: itstep = int(24./numplot) |
---|
| 223 | elif numplot <= 0: itstep = 1 |
---|
[392] | 224 | print "********************************************" |
---|
[345] | 225 | while error is False: |
---|
[392] | 226 | print "********** nplot", nplot, "itime",itime,"error",error |
---|
[345] | 227 | |
---|
[407] | 228 | # time = all_time[index_f] |
---|
[406] | 229 | |
---|
[345] | 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 | |
---|
[349] | 249 | ### Map projection |
---|
| 250 | if mapmode == 1: |
---|
[385] | 251 | m = define_proj(proj,wlon,wlat,back=back,blat=blat) |
---|
[349] | 252 | x, y = m(lon2d, lat2d) |
---|
| 253 | #################################################################### |
---|
[392] | 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) |
---|
[407] | 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 | |
---|
[392] | 264 | if mapmode == 1 and stime is None: |
---|
| 265 | indextime = itime |
---|
| 266 | if len(var) != 1 or len(namefiles) != 1: indextime = first |
---|
[350] | 267 | else: |
---|
[405] | 268 | indextime = getsindex(stime,((nplot-1)//(nlon*nlat*nvert))%ntime,time) |
---|
[406] | 269 | if typefile in ['mesoapi','meso'] and indextime is not None: ltst = localtime ( interv[0]+indextime*interv[1], 0.5*(wlon[0]+wlon[1]) ) |
---|
[359] | 270 | |
---|
[349] | 271 | #################################################################### |
---|
| 272 | |
---|
[392] | 273 | ticks = ndiv + 1 |
---|
| 274 | |
---|
[345] | 275 | #### Contour plot |
---|
| 276 | if var2: |
---|
[382] | 277 | what_I_plot, error = reducefield(all_var2[index_f], d4=indextime, d1=indexlon, d2=indexlat , d3=indexvert, yint=yintegral, alt=vert) |
---|
[349] | 278 | #what_I_plot = what_I_plot*mult |
---|
[345] | 279 | if not error: |
---|
[350] | 280 | if mapmode == 1: |
---|
| 281 | if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(what_I_plot,6) |
---|
[345] | 282 | zevmin, zevmax = calculate_bounds(what_I_plot) |
---|
[392] | 283 | zelevels = np.linspace(zevmin,zevmax,ticks) #20) |
---|
[349] | 284 | if var2 == 'HGT': zelevels = np.arange(-10000.,30000.,2000.) |
---|
[345] | 285 | if mapmode == 0: |
---|
| 286 | x, y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\ |
---|
[350] | 287 | indextime,what_I_plot.shape, len(all_var2[index_f].shape),vertmode) |
---|
[345] | 288 | ### If we plot a 2-D field |
---|
| 289 | if len(what_I_plot.shape) is 2: |
---|
[349] | 290 | cs = contour(x,y,what_I_plot, zelevels, colors='k', linewidths = 1 ) #0.33 colors='w' )# , alpha=0.5) |
---|
[392] | 291 | #if typefile in ['gcm']: clabel(cs,fmt = '%1.2e') |
---|
[345] | 292 | ### If we plot a 1-D field |
---|
| 293 | elif len(what_I_plot.shape) is 1: |
---|
[350] | 294 | plot(what_I_plot,x) |
---|
[345] | 295 | else: |
---|
| 296 | errormess("There is an error in reducing field !") |
---|
| 297 | |
---|
| 298 | #### Shaded plot |
---|
[392] | 299 | varname = all_varname[index_f] |
---|
| 300 | if varname: |
---|
[405] | 301 | what_I_plot, error = reducefield(all_var[index_f], d4=indextime, d1=indexlon, d2=indexlat , d3=indexvert , yint=yintegral, alt=vert, anomaly=anomaly) |
---|
[345] | 302 | what_I_plot = what_I_plot*mult |
---|
| 303 | if not error: |
---|
[405] | 304 | fvar = varname |
---|
| 305 | if anomaly: fvar = 'anomaly' |
---|
| 306 | ##### MAPMODE-SPECIFIC SETTINGS ##### |
---|
[350] | 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) |
---|
[405] | 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) |
---|
[345] | 321 | if colorb in ["def","nobar"]: palette = get_cmap(name=defcolorb(fvar.upper())) |
---|
[398] | 322 | elif (fileref is not None) and (index_f is numplot-1): palette = get_cmap(name="RdBu_r") |
---|
[345] | 323 | else: palette = get_cmap(name=colorb) |
---|
[350] | 324 | ##### 2D field |
---|
[345] | 325 | if len(what_I_plot.shape) is 2: |
---|
[418] | 326 | if hole: what_I_plot = hole_bounds(what_I_plot,zevmin,zevmax) |
---|
| 327 | else: what_I_plot = bounds(what_I_plot,zevmin,zevmax) |
---|
[419] | 328 | if flagnolow: what_I_plot = nolow(what_I_plot) |
---|
[345] | 329 | if not tile: |
---|
| 330 | #zelevels = np.linspace(zevmin*(1. + 1.e-7),zevmax*(1. - 1.e-7)) #,num=20) |
---|
[392] | 331 | zelevels = np.linspace(zevmin,zevmax,num=ticks) |
---|
[402] | 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) |
---|
[345] | 334 | else: |
---|
[405] | 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 ) |
---|
[392] | 337 | if colorb != 'nobar' and varname != 'HGT' : |
---|
[359] | 338 | if (fileref is not None) and (index_f is numplot-1): |
---|
[398] | 339 | colorbar(fraction=0.05,pad=0.03,format="%.3f",\ |
---|
[392] | 340 | ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,20])),\ |
---|
[345] | 341 | extend='neither',spacing='proportional') |
---|
[359] | 342 | else: |
---|
| 343 | colorbar(fraction=0.05,pad=0.03,format=fmtvar(fvar.upper()),\ |
---|
[392] | 344 | ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,20])),\ |
---|
[359] | 345 | extend='neither',spacing='proportional') |
---|
[345] | 346 | # both min max neither |
---|
[350] | 347 | ##### 1D field |
---|
[345] | 348 | elif len(what_I_plot.shape) is 1: |
---|
| 349 | plot(x,what_I_plot) |
---|
[402] | 350 | if save == 'txt': writeascii(np.transpose(what_I_plot),'profile'+str(nplot)+'.txt') |
---|
| 351 | |
---|
[350] | 352 | #### Other cases: (maybe plot 3-D field one day or movie ??) |
---|
[345] | 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 !") |
---|
[349] | 360 | |
---|
| 361 | ### Vector plot --- a adapter |
---|
| 362 | if winds: |
---|
[382] | 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) |
---|
[349] | 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) |
---|
[392] | 373 | if varname == False: colorvec = definecolorvec(back) |
---|
[349] | 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 |
---|
[345] | 380 | |
---|
| 381 | ### Next subplot |
---|
[392] | 382 | basename = getname(var=varname,winds=winds,anomaly=anomaly) |
---|
[399] | 383 | basename = basename + getstralt(nc,level) |
---|
[345] | 384 | if typefile in ['mesoapi','meso']: |
---|
[399] | 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]])) |
---|
[349] | 387 | plottitle = basename |
---|
[399] | 388 | if addchar: |
---|
| 389 | [addchar,gogol,gogol2] = getlschar ( all_namefile[index_f] ) |
---|
| 390 | plottitle = plottitle + addchar + "_LT"+str(ltst) |
---|
[345] | 391 | else: plottitle = plottitle + "_LT"+str(ltst) |
---|
[349] | 392 | else: |
---|
[359] | 393 | if fileref is not None: |
---|
[402] | 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": |
---|
[359] | 400 | plottitle = zetitle |
---|
[402] | 401 | if titleref is "fill": titleref=zetitle |
---|
[359] | 402 | if fileref is not None: |
---|
[402] | 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])) |
---|
[392] | 409 | title( plottitle ) |
---|
[345] | 410 | itime += itstep |
---|
[402] | 411 | if nplot >= numplot: error = True |
---|
[345] | 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 |
---|
[359] | 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 = '' |
---|
[345] | 427 | ### |
---|
[359] | 428 | zeplot = prefix + basename |
---|
| 429 | if addchar: zeplot = zeplot + addchar |
---|
| 430 | if numplot <= 0: zeplot = zeplot + "_LT"+str(abs(numplot)) |
---|
[345] | 431 | ### |
---|
[359] | 432 | if not target: zeplot = namefile[0:find(namefile,'wrfout')] + zeplot |
---|
| 433 | else: zeplot = target + "/" + zeplot |
---|
[345] | 434 | ### |
---|
[359] | 435 | else: |
---|
| 436 | zeplot=outputname |
---|
| 437 | |
---|
[345] | 438 | if found_lct: |
---|
| 439 | pad_inches_value = 0.35 |
---|
[392] | 440 | print "********** SAVE ", save |
---|
[345] | 441 | if save == 'png': |
---|
| 442 | if display: makeplotres(zeplot,res=100.,pad_inches_value=pad_inches_value) #,erase=True) ## a miniature |
---|
[359] | 443 | makeplotres(zeplot,res=resolution,pad_inches_value=pad_inches_value,disp=False) |
---|
[402] | 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." |
---|
[345] | 447 | else: |
---|
[392] | 448 | print "INFO: save mode not supported. using gui instead." |
---|
[345] | 449 | show() |
---|
[392] | 450 | else: print "!!! Local time not found" |
---|
[345] | 451 | |
---|
| 452 | ############### |
---|
| 453 | ### Now the end |
---|
| 454 | return zeplot |
---|