Changeset 1204 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Oct 19, 2016, 12:19:50 AM (8 years ago)
Author:
lfita
Message:

Fixing to the final standard format the: shad_time', shad_cont', `shad_cont_time'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1198 r1204  
    99
    1010## 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
    1315## 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
    1416## 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'
     
    3537## 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'
    3638
    37 main = 'drawing.py'
     39mainn = 'drawing.py'
    3840
    3941errormsg = 'ERROR -- error -- ERROR -- error'
     
    237239def draw_2D_shad_time(ncfile, values, varn):
    238240    """ plotting a fields with shading with time values
    239     draw_2D_shad(ncfile, values, varn)
     241    draw_2D_shad_time(ncfile, values, varn)
    240242      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]~
    242244       [kindfig]~[reverse]~[timevals]~[close]
    243245        [vnamefs]: Name in the figure of the variable to be shaded
    244246        [dimvals]: ',' list of [dimname]|[value] telling at which dimension of the
    245247          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')
    248261        [smin/axv]: minimum and maximum value for the shading or:
    249262          'Srange': for full range
     
    262275          * 'flip'@[x/y]: flip the axis x or y
    263276        [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)
    265278           [units]; units string according to CF conventions ([tunits] since
    266279             [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces)
     
    274287           [label]; label at the graph ('!' for spaces)
    275288        [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|'
    277290        'dtcon~pdf~transpose~time|hours!since!1949-12-01|exct,2,d|%d|date!([DD])~True
    278291      varn= [varsn] name of the variable to plot with shading
     
    285298        quit()
    286299
    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]'
    289302    drw.check_arguments(fname,values,farguments,'~')
    290303
     
    293306    vdimxn = values.split('~')[2]
    294307    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])
    302316
    303317    ncfiles = ncfile
     
    327341    varunits = objvars.getncattr('units')
    328342
    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 + " !!'"
    356352        quit(-1)
    357353
     
    362358    timelabel = timevals.split('|')[4].replace('!',' ')
    363359
     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
    364413# 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']
    367425
    368426    if vdimxn == timename:
    369         odimxv = objsf.variables[vdimxn][:]
     427        odimxv = odxv
    370428        odimxu = timelabel
    371429        timeaxis = 'x'
    372         odimyv = objsf.variables[vdimyn]
    373         odimyu = odimyv.getncattr('units')
     430        odimyv = odyv
     431        odimyu = objdimy.getncattr('units')
    374432        timepos, timelabels = drw.CFtimes_plot(odxv, timeunit, timekind, timefmt)
    375433    elif vdimyn == timename:
    376         odimyv = objsf.variables[vdimyn]
     434        odimyv = odyv
    377435        odimyu = timelabel
    378436        timeaxis = 'y'
    379         odimxv = objsf.variables[vdimxn]
    380         odimxu = odimxv.getncattr('units')
     437        odimxv = odxv
     438        odimxu = objdimx.getncattr('units')
    381439        timepos, timelabels = drw.CFtimes_plot(odyv, timeunit, timekind, timefmt)
    382440    else:
     
    396454        shading_nx.append(shadminmax.split(',')[1])
    397455
    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
    399465
    400466    drw.plot_2D_shadow_time(valshad, vnamesfig, odxv, odyv, odimxu, odimyu,          \
    401       dimnamesv, colbarn, shading_nx, varunits, figtitle, figkind, revals, timeaxis, \
    402       timepos, timelabels, closeval)
     467      dimnamesv, vaxis, colormapv, shading_nx, varunits, figtitle, figkind, revals, \
     468      timeaxis, timepos, timelabels, close)
    403469
    404470    return
     
    639705    Nclevels = int(contlevels.split(',')[2])
    640706
    641     levels_cont = drw.pretty_int(clevmin, clevmax, Nclevels)
     707    levels_cont = gen.pretty_int(clevmin, clevmax, Nclevels)
    642708
    643709    if len(levels_cont) <= 1:
     
    660726
    661727    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,    \
    663729      countlfmt, shading_nx, levels_cont, varunits, figtitle, figkind, revals,       \
    664730      mapvalue, close)
     
    675741        [dimvals/c]: list of [dimname]|[value] telling at which dimension of the
    676742          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)
    679745        [dimxyf]=[dxf],[Ndx],[dyf],[Ndy]: format of the values at each axis
    680746          [dxs]: style of x-axis ('auto' for 'pretty')
     
    715781          'flip',[x/y]: flip only the dimension [x] or [y]
    716782        [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)
    718784          [units]; units string according to CF conventions ([tunits] since
    719785            [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces)
     
    825891    varunits.append(objvarc.getncattr('units'))
    826892
    827     if not objsf.variables.has_key(vdimxn):
     893    if vdimxn != 'WRFtime' and not objsf.variables.has_key(vdimxn):
    828894        print errormsg
    829895        print '  ' + fname + ': shading file "' + ncfiles +                          \
    830896          '" does not have dimension variable "' +  vdimxn + '" !!'
    831897        quit(-1)
    832     if not objsf.variables.has_key(vdimyn):
     898    if vdimyn != 'WRFtime' and not objsf.variables.has_key(vdimyn):
    833899        print errormsg
    834900        print '  ' + fname + ': shading file "' + ncfiles +                          \
     
    842908    timelabel = timevals.split('|')[4].replace('!',' ')
    843909
     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
    844928    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
    847935        dimt = 'x'
    848936        ovalaxis = objsf.variables[vdimyn]
    849937        ovalu = ovalaxis.getncattr('units')
    850938    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
    853945        dimt = 'y'
    854946        ovalaxis = objsf.variables[vdimxn]
     
    863955# Getting only that dimensions with coincident names
    864956    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]
    868961        found = False
    869         for dimsn 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')
    872965                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'
    876974
    877975    if countlabelfmt == 'None':
     
    895993    Nclevels = int(contlevels.split(',')[2])
    896994
    897     levels_cont = drw.pretty_int(clevmin, clevmax, Nclevels)
     995    levels_cont = gen.pretty_int(clevmin, clevmax, Nclevels)
    898996
    899997    if len(levels_cont) <= 1:
     
    9151013    drw.plot_2D_shadow_contour_time(valshad, valcont, vnamesfig, ovalaxisv,         \
    9161014      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,  \
    9181016      levels_cont, varunits, figtitle, figkind, revals, close)
    9191017
     
    46364734      not drw.searchInlist(Notcheckingfile, oper):
    46374735        print errormsg
    4638         print '  ' + main + ': File ' + opts.ncfile + ' does not exist !!'
     4736        print '  ' + mainn + ': File ' + opts.ncfile + ' does not exist !!'
    46394737        quit(-1)
    46404738
  • trunk/tools/drawing_tools.py

    r1198 r1204  
    14501450        print errormsg
    14511451        print '  ' + fname + ': longitude values with shape:', lon.shape,            \
    1452           'is different that latitude values with shape:', lat.shape, '(dif. size) !!'
     1452          'is different than latitude values with shape:', lat.shape, '(dif. size) !!'
    14531453        quit(-1)
    14541454
     
    25292529        print '      first date:',firstTdt
    25302530        print '      last date:',lastTdt
    2531         print '      icrement:',basedt,trefunits
     2531        print '      increment:',basedt,trefunits
    25322532
    25332533        quit(-1)
     
    41994199#quit()
    42004200
    4201 def plot_2D_shadow_time(varsv,vnames,dimxv,dimyv,dimxu,dimyu,dimn,colorbar,vs,uts,   \
    4202   vtit,kfig,reva,taxis,tpos,tlabs,ifclose):
     4201def plot_2D_shadow_time(varsv, vnames, dimxv, dimyv, dimxu, dimyu, dimn, vaxv, cbarv,\
     4202  vs, uts, vtit, kfig, reva, taxis, tpos, tlabs, ifclose):
    42034203    """ Plotting a 2D field with one of the axes being time
    42044204      varsv= 2D values to plot with shading
     
    42074207      dim[x/y]u= units at the axes of x and y
    42084208      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
    42104214      vs= minmum and maximum values to plot in shadow or:
    42114215        'Srange': for full range
     
    42364240        quit()
    42374241
     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
    42384255# Definning ticks labels
    42394256    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
    42834307
    42844308    if len(dimxv.shape) == 3:
     
    43044328        quit(-1)
    43054329
    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)
    43074336
    43084337    plt.rc('text', usetex=True)
    43094338
    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()])
    44014362
    44024363# units labels
    4403     cbar.set_label(vnames.replace('_','\_') + ' (' + units_lunits(uts) + ')')
     4364    cbar.set_label(gen.latex_text(vnames) + ' (' + units_lunits(uts) + ')')
    44044365
    44054366    figname = '2Dfields_shadow_time'
    4406     graphtit = vtit.replace('_','\_').replace('&','\&')
     4367
     4368    graphtit = gen.latex_text(vtit)
    44074369
    44084370    plt.title(graphtit)
     
    44134375
    44144376def 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):
    44174378    """ Adding labels and other staff to the graph
    44184379      varsv= 2D values to plot with shading
     
    44244385      yaxv= list with the y-axis paramteres [style, format, number and orientation]
    44254386      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
    44294391      ckind= contour kind
    44304392        'cmap': as it gets from colorbar
     
    45554517        dy = lon0.shape[0]
    45564518
    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)
    45614523
    45624524# Thats too much! :)
     
    46114573    plt.rc('text', usetex=True)
    46124574
    4613     plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(colorbar), vmin=vs[0], vmax=vs[1])
    4614     if cbaror == 'horizontal':
    4615         cbar = plt.colorbar(format=cbarfmt,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])
    46164578        # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib
    46174579        ticklabels= cbar.ax.get_xticklabels()
     
    46214583        cbar.ax.set_xticklabels(ticklabs,rotation=90)
    46224584    else:
    4623         cbar = plt.colorbar(format=cbarfmt,orientation=cbaror)
     4585        cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2])
    46244586
    46254587# contour
     
    46514613        m.drawcoastlines()
    46524614
    4653         meridians = gen.pretty_int(nlon,xlon,5)
     4615        meridians = gen.pretty_int(nlon,xlon,xaxv[2])
    46544616        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])
    46564618        m.drawparallels(parallels,labels=[False,True,True,False])
    46574619
     
    47004662
    47014663def plot_2D_shadow_contour_time(varsv, varcv, vnames, valv, timv, timpos, timlab,    \
    4702   valu, timeu, axist, xaxv, yaxv, dimn, colorbar, 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):
    47044666    """ Adding labels and other staff to the graph
    47054667      varsv= 2D values to plot with shading
     
    47164678      yaxv= list with the y-axis paramteres [style, format, number and orientation]
    47174679      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
    47214684      ckind= contour kind
    47224685        'cmap': as it gets from colorbar
     
    48164779    x,y = gen.lonlat2D(dimxv,dimyv)
    48174780
     4781# Changing limits of the colors
     4782    vsend = graphic_range(vs,varsv)
     4783
    48184784    plt.rc('text', usetex=True)
    48194785
     
    48234789#    plt.ylim(dimyt[0],dimyt[len(dimyt)-1])
    48244790
    4825     plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(colorbar), vmin=vs[0], vmax=vs[1])
    4826     if cbaror == 'horizontal':
    4827         cbar = plt.colorbar(format=cbarfmt,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])
    48284794        # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib
    48294795        ticklabels= cbar.ax.get_xticklabels()
     
    48334799        cbar.ax.set_xticklabels(ticklabs,rotation=90)
    48344800    else:
    4835         cbar = plt.colorbar(format=cbarfmt,orientation=cbaror)
     4801        cbar = plt.colorbar(format=cbarv[1],orientation=cbarv[2])
    48364802   
    48374803# contour
Note: See TracChangeset for help on using the changeset viewer.