Changeset 1204 in lmdz_wrf for trunk/tools
- Timestamp:
- Oct 19, 2016, 12:19:50 AM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r1198 r1204 9 9 10 10 ## e.g. # drawing.py -f /media/data2/etudes/WRF_LMDZ/WL_HyMeX/IIphase/medic950116/wlmdza/wrfout/wrfout_d01_1995-01-13_00:00:00 -o create_movie -S 'draw_2D_shad#Time@WRFTimes@10@95@191@1#tas:East_West|-1,North_South|-1,Time|2:longitude:latitude:Summer:270.,300.:tas|at|t=0:pdf:None:None' -v T2 11 ## e.g. # drawing.py -f wrfout_d01_1980-03-01_00\:00\:00_Time_B0-E48-I1.nc -o draw_2D_shad -S 'tas:East_West|-1,North_South|-1,Time|2:longitude:latitude:Summer:270.,300.:tas|at|t=0:pdf:None:cyl,i' -v T2 12 ## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'landmask,height:Time|0:Time|0:XLONG_M:XLAT_M:auto:rainbow,auto,auto:fixc,k:%.2f:0.,1.:0.,3000.,10:landmask & height:pdf:None:lcc,i:True' -v LANDMASK,HGT_M 11 ## e.g. # drawing.py -o draw_2D_shad -f wrfout_d01_2001-11-11_00:00:00 -S 'tas:west_east|-1,south_north|-1,Time|2:XLONG:XLAT:auto:rainbow,auto,auto:Srange,Srange:tas|at|2001-11-11|02|UTC:png:None:cyl,l:True' -v T2 12 ## e.g. # drawing.py -o draw_2D_shad_time -f wrfout_d01_2001-11-11_00:00:00 -S 'hurs~west_east|-1,south_north|27,Time|-1~XLONG~WRFtime~auto~Blues,auto,auto~Srange,Srange~tas|evolution|at|south_north=27~png~None~WRFtime|hours!since!1949-12-01|exct,1,h|$%d^{%H}$|date!($[DD]^{[HH]}$)~True' -v Q2 13 ## e.g. # drawing.py -o draw_2D_shad_cont -f wrfout_d01_2001-11-11_00:00:00 -S 'huss,tas:west_east|-1,south_north|-1,Time|2:Time|2:XLONG:XLAT:auto:Blues,auto,auto:fixc,r:%3g:Srange,Srange:260,300,9:huss|&|tas|at|2001-11-11|02|UTC:png:None:cyl,c:True' -v Q2,T2 14 ## e.g. # drawing.py -o draw_2D_shad_cont_time -f wrfout_d01_2001-11-11_00:00:00 -S 'hfls,tas;west_east|-1,south_north|27,Time|-1;south_north|27;XLONG;WRFtime;auto;BuPu,auto,auto;fixc,y;%3g;Srange,Srange;260,300,9;huss|&|tas|evolution|at|south_north=27;png;None;WRFtime|hours!since!1949-12-01|exct,1,h|$%d^{%H}$|date!($[DD]^{[HH]}$);True' -v LH,T2 13 15 ## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'height,landmask:Time|0:Time|0:XLONG_M:XLAT_M:terrain:fixc,k:None:0.,3000.:0,1,10:MEDCORDEX height & landmask:pdf:False:lcc,i' -v HGT_M,LANDMASK 14 16 ## e.g. # drawing.py -o draw_2D_shad_line -f 'mean_dtcon-pluc-pres_lat.nc,mean_dtcon-pluc-pres_lat.nc' -S 'dtcon,prc:bottom_top|-1,south_north|-1:latmean:presmean:seismic,k:-5.,5.:monthly|dtcon|&|prc:pdf:flip@y:None:True' -v 'dtconmean,prcmean' … … 35 37 ## e.g. # drawing.py -o draw_2lines_time -f /home/lluis/etudes/WRF_LMDZ/WaquaL_highres/tests/model_graphics/WRF/current/wss_wrfout_xvar_ymean.nc,/home/lluis/etudes/WRF_LMDZ/WaquaL_highres/tests/model_graphics/WRF/current/tas_wrfout_xvar_ymean.nc -v wssvarmean,tasvarmean -S 'time:0.,20.:0.,4.:exct,1,d;%d:x:wss,tas:red,blue:2.,2.:-:2.,2.:,:wss!tas!mean!longitudinal!xvar:time!($[DD]$):0:wss_tas_wrfout_xvar_ymean:pdf' 36 38 37 main = 'drawing.py'39 mainn = 'drawing.py' 38 40 39 41 errormsg = 'ERROR -- error -- ERROR -- error' … … 237 239 def draw_2D_shad_time(ncfile, values, varn): 238 240 """ plotting a fields with shading with time values 239 draw_2D_shad (ncfile, values, varn)241 draw_2D_shad_time(ncfile, values, varn) 240 242 ncfile= file to use 241 values=[vnamefs]~[dimvals]~[dimxvn]~[dimyvn]~[ colorbar]~[sminv],[smaxv]~[figt]~243 values=[vnamefs]~[dimvals]~[dimxvn]~[dimyvn]~[dimvfmt]~[colorbarvals]~[sminv],[smaxv]~[figt]~ 242 244 [kindfig]~[reverse]~[timevals]~[close] 243 245 [vnamefs]: Name in the figure of the variable to be shaded 244 246 [dimvals]: ',' list of [dimname]|[value] telling at which dimension of the 245 247 variable a given value is required (-1, all the length, [beg]@[end] for an interval) 246 [dimx/yvn]: name of the variables with the values of the final dimensions (x,y) 247 [colorbar]: name of the color bar 248 [dimx/yvn]: name of the variables with the values of the final dimensions (x,y) ('WRFtime' for WRF times) 249 [dimvfmt]=[dvs],[dvf],[Ndv],[ordv]: format of the values for the non-temporal axis (or 'auto') 250 [dvs]: style of non-temporal axis ('auto' for 'pretty') 251 'Nfix', values computed at even 'Ndx' 252 'Vfix', values computed at even 'Ndx' increments 253 'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10) 254 [dvf]: format of the labels at the x-axis ('auto' for '%5g') 255 [Ndv]: Number of ticks at the x-axis ('auto' for 5) 256 [ordv]: angle of orientation of ticks at the x-axis ('auto' for horizontal) 257 [colorbarvals]=[colbarn],[fmtcolorbar],[orientation] 258 [colorbarn]: name of the color bar 259 [fmtcolorbar]: format of the numbers in the color bar 'C'-like ('auto' for %6g) 260 [orientation]: orientation of the colorbar ('vertical' (default, by 'auto'), 'horizontal') 248 261 [smin/axv]: minimum and maximum value for the shading or: 249 262 'Srange': for full range … … 262 275 * 'flip'@[x/y]: flip the axis x or y 263 276 [timevals]: [timen]|[units]|[kind]|[tfmt]|[label]|[timeaxis] time labels characteristics 264 [timen]; name of the time variable 277 [timen]; name of the time variable ('WRFtime' for WRF times) 265 278 [units]; units string according to CF conventions ([tunits] since 266 279 [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces) … … 274 287 [label]; label at the graph ('!' for spaces) 275 288 [close]: should figure be closed (finished) 276 values='dtcon~Time|-1,bottom_top|-1~presmean~time~ seismic~-3.e-6,3.e-6~monthly|'289 values='dtcon~Time|-1,bottom_top|-1~presmean~time~auto~seismic,auto,auto~-3.e-6,3.e-6~monthly|' 277 290 'dtcon~pdf~transpose~time|hours!since!1949-12-01|exct,2,d|%d|date!([DD])~True 278 291 varn= [varsn] name of the variable to plot with shading … … 285 298 quit() 286 299 287 farguments = '[vnamefs]~[dimvals]~[dimxvn]~[dimyvn]~[ colorbar]~[sminv],[smaxv]~'+\288 '[ figt]~[kindfig]~[reverse]~[timevals]~[close]'300 farguments = '[vnamefs]~[dimvals]~[dimxvn]~[dimyvn]~[dimvfmt]~[colorbarvals]~' + \ 301 '[sminv],[smaxv]~[figt]~[kindfig]~[reverse]~[timevals]~[close]' 289 302 drw.check_arguments(fname,values,farguments,'~') 290 303 … … 293 306 vdimxn = values.split('~')[2] 294 307 vdimyn = values.split('~')[3] 295 colbarn = values.split('~')[4] 296 shadminmax = values.split('~')[5] 297 figtitle = values.split('~')[6].replace('|',' ') 298 figkind = values.split('~')[7] 299 revals = values.split('~')[8] 300 timevals = values.split('~')[9] 301 close = values.split('~')[10] 308 dimvfmt = values.split('~')[4] 309 colorbarvals = values.split('~')[5] 310 shadminmax = values.split('~')[6] 311 figtitle = values.split('~')[7].replace('|',' ') 312 figkind = values.split('~')[8] 313 revals = values.split('~')[9] 314 timevals = values.split('~')[10] 315 close = gen.Str_Bool(values.split('~')[11]) 302 316 303 317 ncfiles = ncfile … … 327 341 varunits = objvars.getncattr('units') 328 342 329 if not objsf.variables.has_key(vdimxn): 330 print errormsg 331 print ' ' + fname + ': shading file "' + ncfiles + \ 332 '" does not have dimension variable "' + vdimxn + '" !!' 333 quit(-1) 334 if not objsf.variables.has_key(vdimyn): 335 print errormsg 336 print ' ' + fname + ': shading file "' + ncfiles + \ 337 '" does not have dimension variable "' + vdimyn + '" !!' 338 quit(-1) 339 340 objdimx = objsf.variables[vdimxn] 341 objdimy = objsf.variables[vdimyn] 342 odimxu = objdimx.getncattr('units') 343 odimyu = objdimy.getncattr('units') 344 345 if len(objdimx.shape) <= 2: 346 odimxv0 = objdimx[:] 347 odimyv0 = objdimy[:] 348 349 elif len(objdimx.shape) == 3: 350 odimxv0 = objdimx[0,:] 351 odimyv0 = objdimy[0,:] 352 else: 353 print errormsg 354 print ' ' + fname + ': shape of dimension variable:', objdimx.shape, \ 355 ' not ready!!' 343 if vdimxn != 'WRFtime' and not objsf.variables.has_key(vdimxn): 344 print errormsg 345 print ' ' + fname + ": shading file '" + ncfiles + \ 346 "' does not have dimension variable '" + vdimxn + "' !!" 347 quit(-1) 348 if vdimyn != 'WRFtime' and not objsf.variables.has_key(vdimyn): 349 print errormsg 350 print ' ' + fname + ": shading file '" + ncfiles + \ 351 "' does not have dimension variable '" + vdimyn + " !!'" 356 352 quit(-1) 357 353 … … 362 358 timelabel = timevals.split('|')[4].replace('!',' ') 363 359 360 if vdimxn == 'WRFtime' or vdimyn == 'WRFtime': 361 tunitsec = timeunit.split(' ') 362 if len(tunitsec) == 4: 363 refdate = tunitsec[2][0:4]+tunitsec[2][5:7]+tunitsec[2][8:10] + \ 364 tunitsec[3][0:2] + tunitsec[3][3:5] + tunitsec[3][6:8] 365 else: 366 refdate = tunitsec[2][0:4]+tunitsec[2][5:7]+tunitsec[2][8:10]+ '000000' 367 tunitsval = tunitsec[0] 368 369 timewrfv = objsf.variables['Times'] 370 dt = timewrfv.shape[0] 371 cftimes = np.zeros((dt), dtype=np.float) 372 373 for it in range(dt): 374 wrfdates = gen.datetimeStr_conversion(timewrfv[it,:],'WRFdatetime', \ 375 'matYmdHMS') 376 cftimes[it] = gen.realdatetime1_CFcompilant(wrfdates, refdate, tunitsval) 377 378 if vdimxn != 'WRFtime': 379 objdimx = objsf.variables[vdimxn] 380 objdimxv = objdimx[:] 381 odimxu = objdimx.getncattr('units') 382 else: 383 objdimxv = cftimes 384 odimxu = timeunit 385 386 if vdimyn != 'WRFtime': 387 objdimy = objsf.variables[vdimyn] 388 objdimyv = objdimy[:] 389 odimyu = objdimy.getncattr('units') 390 else: 391 objdimyv = cftimes 392 odimyu = timeunit 393 394 if len(objdimxv.shape) <= 2: 395 odimxv0 = objdimxv[:] 396 elif len(objdimxv.shape) == 3: 397 odimxv0 = objdimxv[0,:] 398 else: 399 print errormsg 400 print ' ' + fname + ': shape of dimension variable:', objdimxv.shape, \ 401 ' not ready!!' 402 quit(-1) 403 if len(objdimyv.shape) <= 2: 404 odimyv0 = objdimyv[:] 405 elif len(objdimyv.shape) == 3: 406 odimyv0 = objdimyv[0,:] 407 else: 408 print errormsg 409 print ' ' + fname + ': shape of dimension variable:', objdimyv.shape, \ 410 ' not ready!!' 411 quit(-1) 412 364 413 # Dimensional values 365 odxv, dimsdxv = drw.slice_variable(objsf.variables[vdimxn], dimvals.replace(',','|')) 366 odyv, dimsdyv = drw.slice_variable(objsf.variables[vdimyn], dimvals.replace(',','|')) 414 if vdimxn != 'WRFtime': 415 odxv, dimsdxv = drw.slice_variable(objsf.variables[vdimxn], dimvals.replace(',','|')) 416 else: 417 odxv = cftimes 418 dimsdxv = ['Time'] 419 420 if vdimyn != 'WRFtime': 421 odyv, dimsdyv = drw.slice_variable(objsf.variables[vdimyn], dimvals.replace(',','|')) 422 else: 423 odyv = cftimes 424 dimsdyv = ['Time'] 367 425 368 426 if vdimxn == timename: 369 odimxv = o bjsf.variables[vdimxn][:]427 odimxv = odxv 370 428 odimxu = timelabel 371 429 timeaxis = 'x' 372 odimyv = o bjsf.variables[vdimyn]373 odimyu = o dimyv.getncattr('units')430 odimyv = odyv 431 odimyu = objdimy.getncattr('units') 374 432 timepos, timelabels = drw.CFtimes_plot(odxv, timeunit, timekind, timefmt) 375 433 elif vdimyn == timename: 376 odimyv = o bjsf.variables[vdimyn]434 odimyv = odyv 377 435 odimyu = timelabel 378 436 timeaxis = 'y' 379 odimxv = o bjsf.variables[vdimxn]380 odimxu = o dimxv.getncattr('units')437 odimxv = odxv 438 odimxu = objdimx.getncattr('units') 381 439 timepos, timelabels = drw.CFtimes_plot(odyv, timeunit, timekind, timefmt) 382 440 else: … … 396 454 shading_nx.append(shadminmax.split(',')[1]) 397 455 398 closeval = drw.Str_Bool(close) 456 colbarn, fmtcolbar, colbaror = drw.colorbar_vals(colorbarvals,',') 457 colormapv = [colbarn, fmtcolbar, colbaror] 458 459 if dimvfmt != 'auto': dimvfmt = dimvfmt + 'auto,auto,auto,auto' 460 xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimvfmt,',') 461 vaxis = [xstyl, xaxf, Nxax, xaxor] 462 463 if revals == 'None': 464 revals = None 399 465 400 466 drw.plot_2D_shadow_time(valshad, vnamesfig, odxv, odyv, odimxu, odimyu, \ 401 dimnamesv, colbarn, shading_nx, varunits, figtitle, figkind, revals, timeaxis,\402 time pos, timelabels, closeval)467 dimnamesv, vaxis, colormapv, shading_nx, varunits, figtitle, figkind, revals, \ 468 timeaxis, timepos, timelabels, close) 403 469 404 470 return … … 639 705 Nclevels = int(contlevels.split(',')[2]) 640 706 641 levels_cont = drw.pretty_int(clevmin, clevmax, Nclevels)707 levels_cont = gen.pretty_int(clevmin, clevmax, Nclevels) 642 708 643 709 if len(levels_cont) <= 1: … … 660 726 661 727 drw.plot_2D_shadow_contour(valshad, valcont, vnamesfig, odimxv, odimyv, odimxu, \ 662 odimyu, xaxis, yaxis, dimnamesv, colbarn, fmtcolbar, colbaror, countkind,\728 odimyu, xaxis, yaxis, dimnamesv, [colbarn, fmtcolbar, colbaror], countkind, \ 663 729 countlfmt, shading_nx, levels_cont, varunits, figtitle, figkind, revals, \ 664 730 mapvalue, close) … … 675 741 [dimvals/c]: list of [dimname]|[value] telling at which dimension of the 676 742 variable a given value is required (no dimension name, all the length) 677 [dimxvn]: name of the variables with the values of the dimension of the x-axis 678 [dimyvn]: name of the variables with the values of the dimension of the y-axis 743 [dimxvn]: name of the variables with the values of the dimension of the x-axis ('WRFtime' for WRF times) 744 [dimyvn]: name of the variables with the values of the dimension of the y-axis ('WRFtime' for WRF times) 679 745 [dimxyf]=[dxf],[Ndx],[dyf],[Ndy]: format of the values at each axis 680 746 [dxs]: style of x-axis ('auto' for 'pretty') … … 715 781 'flip',[x/y]: flip only the dimension [x] or [y] 716 782 [timevals]: [timen]|[units]|[kind]|[tfmt]|[label] time labels characteristics 717 [timen]; name of the time variable 783 [timen]; name of the time variable ('WRFtime' for WRF times) 718 784 [units]; units string according to CF conventions ([tunits] since 719 785 [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces) … … 825 891 varunits.append(objvarc.getncattr('units')) 826 892 827 if not objsf.variables.has_key(vdimxn):893 if vdimxn != 'WRFtime' and not objsf.variables.has_key(vdimxn): 828 894 print errormsg 829 895 print ' ' + fname + ': shading file "' + ncfiles + \ 830 896 '" does not have dimension variable "' + vdimxn + '" !!' 831 897 quit(-1) 832 if not objsf.variables.has_key(vdimyn):898 if vdimyn != 'WRFtime' and not objsf.variables.has_key(vdimyn): 833 899 print errormsg 834 900 print ' ' + fname + ': shading file "' + ncfiles + \ … … 842 908 timelabel = timevals.split('|')[4].replace('!',' ') 843 909 910 if vdimxn == 'WRFtime' or vdimyn == 'WRFtime': 911 tunitsec = timeunit.split(' ') 912 if len(tunitsec) == 4: 913 refdate = tunitsec[2][0:4]+tunitsec[2][5:7]+tunitsec[2][8:10] + \ 914 tunitsec[3][0:2] + tunitsec[3][3:5] + tunitsec[3][6:8] 915 else: 916 refdate = tunitsec[2][0:4]+tunitsec[2][5:7]+tunitsec[2][8:10]+ '000000' 917 tunitsval = tunitsec[0] 918 919 timewrfv = objsf.variables['Times'] 920 dt = timewrfv.shape[0] 921 cftimes = np.zeros((dt), dtype=np.float) 922 923 for it in range(dt): 924 wrfdates = gen.datetimeStr_conversion(timewrfv[it,:],'WRFdatetime', \ 925 'matYmdHMS') 926 cftimes[it] = gen.realdatetime1_CFcompilant(wrfdates, refdate, tunitsval) 927 844 928 if vdimxn == timename: 845 timevals = objsf.variables[vdimxn][:] 846 timedims = objsf.variables[vdimxn].dimensions 929 if vdimxn == 'WRFtime': 930 timevals = cftimes 931 timedims = ['Time'] 932 else: 933 timevals = objsf.variables[vdimxn][:] 934 timedims = objsf.variables[vdimxn].dimensions 847 935 dimt = 'x' 848 936 ovalaxis = objsf.variables[vdimyn] 849 937 ovalu = ovalaxis.getncattr('units') 850 938 elif vdimyn == timename: 851 timevals = objsf.variables[vdimyn][:] 852 timedims = objsf.variables[vdimyn].dimensions 939 if vdimyn == 'WRFtime': 940 timevals = cftimes 941 timedims = ['Time'] 942 else: 943 timevals = objsf.variables[vdimyn][:] 944 timedims = objsf.variables[vdimyn].dimensions 853 945 dimt = 'y' 854 946 ovalaxis = objsf.variables[vdimxn] … … 863 955 # Getting only that dimensions with coincident names 864 956 dimnvx = ovalaxis.dimensions 865 866 cutslice = [] 867 for idimn in dimnvx: 957 dimsliceaxis = [] 958 for dimv in dimvals.split(','): 959 adimvn = dimv.split(':')[0] 960 adimval = dimv.split(':')[1] 868 961 found = False 869 for dim sn in dimsshad:870 if idimn == dimsn:871 cutslice.append(slice(0,len(objsf.dimensions[idimn])))962 for dimtn in timedims: 963 if adimvn == dimtn: 964 dimsliceaxis.append(adimvn + ':0') 872 965 found = True 873 if not found: cutslice.append(slice(0,len(objsf.dimensions[idimn]))) 874 875 ovalaxisv = ovalaxis[tuple(cutslice)] 966 break 967 if not found: 968 dimsliceaxis.append(dimv) 969 970 dimsliceaxisS = '|'.join(dimsliceaxis) 971 972 ovalaxisv, odimaxisv = drw.slice_variable(ovalaxis,dimsliceaxisS) 973 print fname + '; Lluis odimaxisv:', odimaxisv, timedims[0]+':0' 876 974 877 975 if countlabelfmt == 'None': … … 895 993 Nclevels = int(contlevels.split(',')[2]) 896 994 897 levels_cont = drw.pretty_int(clevmin, clevmax, Nclevels)995 levels_cont = gen.pretty_int(clevmin, clevmax, Nclevels) 898 996 899 997 if len(levels_cont) <= 1: … … 915 1013 drw.plot_2D_shadow_contour_time(valshad, valcont, vnamesfig, ovalaxisv, \ 916 1014 timevals, timepos, timelabels, ovalu, timelabel, dimt, xaxis, yaxis, \ 917 dimnamesv, colbarn, fmtcolbar, colbaror, countkind, countlfmt, shading_nx,\1015 dimnamesv, [colbarn, fmtcolbar, colbaror], countkind, countlfmt, shading_nx, \ 918 1016 levels_cont, varunits, figtitle, figkind, revals, close) 919 1017 … … 4636 4734 not drw.searchInlist(Notcheckingfile, oper): 4637 4735 print errormsg 4638 print ' ' + main + ': File ' + opts.ncfile + ' does not exist !!'4736 print ' ' + mainn + ': File ' + opts.ncfile + ' does not exist !!' 4639 4737 quit(-1) 4640 4738 -
trunk/tools/drawing_tools.py
r1198 r1204 1450 1450 print errormsg 1451 1451 print ' ' + fname + ': longitude values with shape:', lon.shape, \ 1452 'is different tha tlatitude values with shape:', lat.shape, '(dif. size) !!'1452 'is different than latitude values with shape:', lat.shape, '(dif. size) !!' 1453 1453 quit(-1) 1454 1454 … … 2529 2529 print ' first date:',firstTdt 2530 2530 print ' last date:',lastTdt 2531 print ' i crement:',basedt,trefunits2531 print ' increment:',basedt,trefunits 2532 2532 2533 2533 quit(-1) … … 4199 4199 #quit() 4200 4200 4201 def plot_2D_shadow_time(varsv, vnames,dimxv,dimyv,dimxu,dimyu,dimn,colorbar,vs,uts,\4202 v tit,kfig,reva,taxis,tpos,tlabs,ifclose):4201 def plot_2D_shadow_time(varsv, vnames, dimxv, dimyv, dimxu, dimyu, dimn, vaxv, cbarv,\ 4202 vs, uts, vtit, kfig, reva, taxis, tpos, tlabs, ifclose): 4203 4203 """ Plotting a 2D field with one of the axes being time 4204 4204 varsv= 2D values to plot with shading … … 4207 4207 dim[x/y]u= units at the axes of x and y 4208 4208 dimn= dimension names to plot 4209 colorbar= name of the color bar to use 4209 vaxv= list with the non-temporal axis paramteres [style, format, number and orientation] 4210 cbarv= list with the parameters of the color bar [colorbar, cbarfmt, cbaror] 4211 colorbar: name of the color bar to use 4212 cbarfmt: format of the numbers in the colorbar 4213 cbaror: orientation of the colorbar 4210 4214 vs= minmum and maximum values to plot in shadow or: 4211 4215 'Srange': for full range … … 4236 4240 quit() 4237 4241 4242 if len(varsv.shape) != 2: 4243 print errormsg 4244 print ' ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!' 4245 quit(-1) 4246 4247 dimxv0 = dimxv.copy() 4248 dimyv0 = dimyv.copy() 4249 4250 dxn = dimxv.min() 4251 dxx = dimxv.max() 4252 dyn = dimyv.min() 4253 dyx = dimyv.max() 4254 4238 4255 # Definning ticks labels 4239 4256 if taxis == 'x': 4240 txpos = tpos 4241 txlabels = tlabs 4242 plxlabel = dimxu 4243 typos = gen.pretty_int(np.min(dimyv),np.max(dimyv),10) 4244 tylabels = list(typos) 4245 for i in range(len(tylabels)): tylabels[i] = str(tylabels[i]) 4246 plylabel = variables_values(dimn[0])[0].replace('_','\_') + ' (' + \ 4247 units_lunits(dimyu) + ')' 4248 else: 4249 txpos = gen.pretty_int(np.min(dimxv),np.max(dimxv),10) 4250 txlabels = list(txpos) 4251 plxlabel = variables_values(dimn[1])[0].replace('_','\_') + ' (' + \ 4252 units_lunits(dimxu) + ')' 4253 typos = tpos 4254 tylabels = tlabs 4255 plylabel = dimyu 4256 4257 # Transposing/flipping axis 4258 if reva.find('|') != 0: 4259 revas = reva.split('|') 4260 reva0 = '' 4261 else: 4262 revas = [reva] 4263 reva0 = reva 4264 4265 for rev in revas: 4266 if rev[0:4] == 'flip': 4267 reva0 = 'flip' 4268 if len(reva.split('@')) != 2: 4269 print errormsg 4270 print ' ' + fname + ': flip is given', reva, 'but not axis!' 4271 quit(-1) 4272 else: 4273 print " flipping '" + rev.split('@')[1] + "' axis !" 4274 4275 if rev == 'transpose': 4276 print ' reversing the axes of the figure (x-->y, y-->x)!!' 4277 # Flipping values of variable 4278 varsv = np.transpose(varsv) 4279 dxv = dimyv 4280 dyv = dimxv 4281 dimxv = dxv 4282 dimyv = dyv 4257 dimxt0 = tpos 4258 dimxl0 = tlabs 4259 dimxT0 = dimxu 4260 if vaxv[0] == 'pretty': 4261 dimyt0 = np.array(gen.pretty_int(dyn,dyx,vaxv[2])) 4262 elif vaxv[0] == 'Nfix': 4263 dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*vaxv[2])) 4264 elif vaxv[0] == 'Vfix': 4265 dimyt0 = np.arange(0,dyx,vaxv[2]) 4266 dimyl0 = [] 4267 for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], \ 4268 style=vaxv[1])) 4269 dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')' 4270 4271 # No following data values 4272 dimyt0 = np.arange(len(dimyt0),dtype=np.float)/(len(dimyt0)) 4273 pixkind = 'fixpixel' 4274 4275 else: 4276 if vaxv[0] == 'pretty': 4277 dimxt0 = np.array(gen.pretty_int(dxn,dxx,vaxv[2])) 4278 elif vaxv[0] == 'Nfix': 4279 dimxt0 = np.arange(dxn,dxx,(dxx-dxn)/(1.*vaxv[2])) 4280 elif vaxv[0] == 'Vfix': 4281 dimxt0 = np.arange(0,dxx,vaxv[2]) 4282 dimxl0 = [] 4283 for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i], \ 4284 style=vaxv[1])) 4285 dimxT0 = variables_values(dimn[0])[0] + ' (' + units_lunits(dimxu) + ')' 4286 4287 dimyt0 = tpos 4288 dimyl0 = tlabs 4289 dimyT0 = dimyu 4290 # No following data values 4291 dimxt0 = np.arange(len(dimxt0),dtype=np.float)/(len(dimxt0)) 4292 pixkind = 'fixpixel' 4293 4294 if reva is not None: 4295 varsv, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT = \ 4296 transform(varsv, reva, dxv=dimxv0, dyv=dimyv0, dxt=dimxt0, dyt=dimyt0, \ 4297 dxl=dimxl0, dyl=dimyl0, dxtit=dimxT0, dytit=dimyT0) 4298 else: 4299 dimxv = dimxv0 4300 dimyv = dimyv0 4301 dimxt = dimxt0 4302 dimyt = dimyt0 4303 dimxl = dimxl0 4304 dimyl = dimyl0 4305 dimxT = dimxT0 4306 dimyT = dimyT0 4283 4307 4284 4308 if len(dimxv.shape) == 3: … … 4304 4328 quit(-1) 4305 4329 4306 x,y = dxdy_lonlat(dimxv,dimyv,dxget,dyget) 4330 # No following data values 4331 x = (dimxv-np.min(dimxv))/(np.max(dimxv) - np.min(dimxv)) 4332 y = (dimyv-np.min(dimyv))/(np.max(dimyv) - np.min(dimyv)) 4333 4334 # Changing limits of the colors 4335 vsend = graphic_range(vs,varsv) 4307 4336 4308 4337 plt.rc('text', usetex=True) 4309 4338 4310 vsend = np.zeros((2), dtype=np.float) 4311 # Changing limits of the colors 4312 if type(vs[0]) != type(np.float(1.)): 4313 if vs[0] == 'Srange': 4314 vsend[0] = np.min(varsv) 4315 elif vs[0][0:11] == 'Saroundmean': 4316 meanv = np.mean(varsv) 4317 permean = np.float(vs[0].split('@')[1]) 4318 minv = np.min(varsv)*permean 4319 maxv = np.max(varsv)*permean 4320 minextrm = np.min([np.abs(meanv-minv), np.abs(maxv-meanv)]) 4321 vsend[0] = meanv-minextrm 4322 vsend[1] = meanv+minextrm 4323 elif vs[0][0:13] == 'Saroundminmax': 4324 permean = np.float(vs[0].split('@')[1]) 4325 minv = np.min(varsv)*permean 4326 maxv = np.max(varsv)*permean 4327 vsend[0] = minv 4328 vsend[1] = maxv 4329 elif vs[0][0:17] == 'Saroundpercentile': 4330 medianv = np.median(varsv) 4331 valper = np.float(vs[0].split('@')[1]) 4332 minv = np.percentile(varsv, valper) 4333 maxv = np.percentile(varsv, 100.-valper) 4334 minextrm = np.min([np.abs(medianv-minv), np.abs(maxv-medianv)]) 4335 vsend[0] = medianv-minextrm 4336 vsend[1] = medianv+minextrm 4337 elif vs[0][0:5] == 'Smean': 4338 meanv = np.mean(varsv) 4339 permean = np.float(vs[0].split('@')[1]) 4340 minv = np.min(varsv)*permean 4341 maxv = np.max(varsv)*permean 4342 minextrm = np.min([np.abs(meanv-minv), np.abs(maxv-meanv)]) 4343 vsend[0] = -minextrm 4344 vsend[1] = minextrm 4345 elif vs[0][0:7] == 'Smedian': 4346 medianv = np.median(varsv) 4347 permedian = np.float(vs[0].split('@')[1]) 4348 minv = np.min(varsv)*permedian 4349 maxv = np.max(varsv)*permedian 4350 minextrm = np.min([np.abs(medianv-minv), np.abs(maxv-medianv)]) 4351 vsend[0] = -minextrm 4352 vsend[1] = minextrm 4353 elif vs[0][0:11] == 'Spercentile': 4354 medianv = np.median(varsv) 4355 valper = np.float(vs[0].split('@')[1]) 4356 minv = np.percentile(varsv, valper) 4357 maxv = np.percentile(varsv, 100.-valper) 4358 minextrm = np.min([np.abs(medianv-minv), np.abs(maxv-medianv)]) 4359 vsend[0] = -minextrm 4360 vsend[1] = minextrm 4361 else: 4362 print errormsg 4363 print ' ' + fname + ": range '" + vs[0] + "' not ready!!!" 4364 quit(-1) 4365 print ' ' + fname + ': modified shadow min,max:',vsend 4366 else: 4367 vsend[0] = vs[0] 4368 4369 if type(vs[0]) != type(np.float(1.)): 4370 if vs[1] == 'range': 4371 vsend[1] = np.max(varsv) 4372 else: 4373 vsend[1] = vs[1] 4374 4375 plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(colorbar), vmin=vsend[0], vmax=vsend[1]) 4376 cbar = plt.colorbar() 4377 4378 # print 'Lluis reva0:',reva0,'x min,max:',x.min(),x.max(),' y min,max:',y.min(),y.max() 4379 4380 # set the limits of the plot to the limits of the data 4381 if reva0 == 'flip': 4382 if reva.split('@')[1] == 'x': 4383 plt.axis([x.max(), x.min(), y.min(), y.max()]) 4384 elif reva.split('@')[1] == 'y': 4385 plt.axis([x.min(), x.max(), y.max(), y.min()]) 4386 else: 4387 plt.axis([x.max(), x.min(), y.max(), y.min()]) 4388 else: 4389 plt.axis([x.min(), x.max(), y.min(), y.max()]) 4390 4391 if searchInlist(revas, 'transpose'): 4392 plt.xticks(typos, tylabels) 4393 plt.yticks(txpos, txlabels) 4394 plt.xlabel(plylabel) 4395 plt.ylabel(plxlabel) 4396 else: 4397 plt.xticks(txpos, txlabels) 4398 plt.yticks(typos, tylabels) 4399 plt.xlabel(plxlabel) 4400 plt.ylabel(plylabel) 4339 plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(cbarv[0]), vmin=vsend[0], vmax=vsend[1]) 4340 if cbarv[2] == 'horizontal': 4341 cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2]) 4342 # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib 4343 ticklabels= cbar.ax.get_xticklabels() 4344 Nticks = len(ticklabels) 4345 ticklabs = [] 4346 for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text()) 4347 cbar.ax.set_xticklabels(ticklabs,rotation=90) 4348 else: 4349 cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2]) 4350 4351 if taxis == 'x': 4352 plt.xticks((dimxt-dxn)/(dxx-dxn), dimxl) 4353 plt.yticks(dimyt, dimyl, rotation=vaxv[3]) 4354 else: 4355 plt.xticks(dimxt, dimxl, rotation=vaxv[3]) 4356 plt.yticks((dimyt-dyn)/(dyx-dyn), dimyl) 4357 4358 plt.xlabel(dimxT) 4359 plt.ylabel(dimyT) 4360 4361 plt.axis([x.min(), x.max(), y.min(), y.max()]) 4401 4362 4402 4363 # units labels 4403 cbar.set_label( vnames.replace('_','\_') + ' (' + units_lunits(uts) + ')')4364 cbar.set_label(gen.latex_text(vnames) + ' (' + units_lunits(uts) + ')') 4404 4365 4405 4366 figname = '2Dfields_shadow_time' 4406 graphtit = vtit.replace('_','\_').replace('&','\&') 4367 4368 graphtit = gen.latex_text(vtit) 4407 4369 4408 4370 plt.title(graphtit) … … 4413 4375 4414 4376 def plot_2D_shadow_contour(varsv, varcv, vnames, dimxv, dimyv, dimxu, dimyu, xaxv, \ 4415 yaxv, dimn, colorbar, cbarfmt, cbaror, ckind, clabfmt, vs, vc, uts, vtit, kfig, \ 4416 reva, mapv, ifclose): 4377 yaxv, dimn, cbarv, ckind, clabfmt, vs, vc, uts, vtit, kfig, reva, mapv, ifclose): 4417 4378 """ Adding labels and other staff to the graph 4418 4379 varsv= 2D values to plot with shading … … 4424 4385 yaxv= list with the y-axis paramteres [style, format, number and orientation] 4425 4386 dimn= dimension names to plot 4426 colorbar= name of the color bar to use 4427 cbarfmt= format of the numbers in the colorbar 4428 cbaror= orientation of the colorbar 4387 cbarv= list with the parameters of the color bar [colorbar, cbarfmt, cbaror] 4388 colorbar= name of the color bar to use 4389 cbarfmt= format of the numbers in the colorbar 4390 cbaror= orientation of the colorbar 4429 4391 ckind= contour kind 4430 4392 'cmap': as it gets from colorbar … … 4555 4517 dy = lon0.shape[0] 4556 4518 4557 nlon = lon0[0,0]4558 xlon = lon0[dy-1,dx-1]4559 nlat = lat0[0,0]4560 xlat = lat0[dy-1,dx-1]4519 nlon = np.min(lon0) 4520 xlon = np.max(lon0) 4521 nlat = np.min(lat0) 4522 xlat = np.max(lat0) 4561 4523 4562 4524 # Thats too much! :) … … 4611 4573 plt.rc('text', usetex=True) 4612 4574 4613 plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(c olorbar), vmin=vs[0], vmax=vs[1])4614 if cbar or== 'horizontal':4615 cbar = plt.colorbar(format=cbar fmt,orientation=cbaror)4575 plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(cbarv[0]), vmin=vs[0], vmax=vs[1]) 4576 if cbarv[2] == 'horizontal': 4577 cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2]) 4616 4578 # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib 4617 4579 ticklabels= cbar.ax.get_xticklabels() … … 4621 4583 cbar.ax.set_xticklabels(ticklabs,rotation=90) 4622 4584 else: 4623 cbar = plt.colorbar(format=cbar fmt,orientation=cbaror)4585 cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2]) 4624 4586 4625 4587 # contour … … 4651 4613 m.drawcoastlines() 4652 4614 4653 meridians = gen.pretty_int(nlon,xlon, 5)4615 meridians = gen.pretty_int(nlon,xlon,xaxv[2]) 4654 4616 m.drawmeridians(meridians,labels=[True,False,False,True]) 4655 parallels = gen.pretty_int(nlat,xlat, 5)4617 parallels = gen.pretty_int(nlat,xlat,yaxv[2]) 4656 4618 m.drawparallels(parallels,labels=[False,True,True,False]) 4657 4619 … … 4700 4662 4701 4663 def plot_2D_shadow_contour_time(varsv, varcv, vnames, valv, timv, timpos, timlab, \ 4702 valu, timeu, axist, xaxv, yaxv, dimn, c olorbar, cbarfmt, cbaror, ckind, clabfmt,\4703 vs, vc, uts, vtit,kfig, reva, ifclose):4664 valu, timeu, axist, xaxv, yaxv, dimn, cbarv, ckind, clabfmt, vs, vc, uts, vtit, \ 4665 kfig, reva, ifclose): 4704 4666 """ Adding labels and other staff to the graph 4705 4667 varsv= 2D values to plot with shading … … 4716 4678 yaxv= list with the y-axis paramteres [style, format, number and orientation] 4717 4679 dimn= dimension names to plot 4718 colorbar= name of the color bar to use 4719 cbarfmt= format of the numbers in the colorbar 4720 cbaror= orientation of the colorbar 4680 cbarv= list with the parameters of the color bar [colorbar, cbarfmt, cbaror] 4681 colorbar= name of the color bar to use 4682 cbarfmt= format of the numbers in the colorbar 4683 cbaror= orientation of the colorbar 4721 4684 ckind= contour kind 4722 4685 'cmap': as it gets from colorbar … … 4816 4779 x,y = gen.lonlat2D(dimxv,dimyv) 4817 4780 4781 # Changing limits of the colors 4782 vsend = graphic_range(vs,varsv) 4783 4818 4784 plt.rc('text', usetex=True) 4819 4785 … … 4823 4789 # plt.ylim(dimyt[0],dimyt[len(dimyt)-1]) 4824 4790 4825 plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(c olorbar), vmin=vs[0], vmax=vs[1])4826 if cbar or== 'horizontal':4827 cbar = plt.colorbar(format=cbar fmt,orientation=cbaror)4791 plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(cbarv[0]), vmin=vsend[0], vmax=vsend[1]) 4792 if cbarv[2] == 'horizontal': 4793 cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2]) 4828 4794 # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib 4829 4795 ticklabels= cbar.ax.get_xticklabels() … … 4833 4799 cbar.ax.set_xticklabels(ticklabs,rotation=90) 4834 4800 else: 4835 cbar = plt.colorbar(format=cbar fmt,orientation=cbaror)4801 cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2]) 4836 4802 4837 4803 # contour
Note: See TracChangeset
for help on using the changeset viewer.