Changeset 2105 in lmdz_wrf


Ignore:
Timestamp:
Aug 27, 2018, 5:49:19 PM (7 years ago)
Author:
lfita
Message:

Adding example for `draw_2Dshad_map'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r2103 r2105  
    6666## e.g. # drawing.py -o draw_stations_map -f stations.inf -S 'snd|x|#FFAAAA|2|8@sfc|x|#AAFFAA|2|8:cyl,l:1.,20.,35.,49.:FPS!Alps!stations:pdf:true'
    6767## e.g. # drawing.py -o draw_WRFeta_levels -f 120lev/simin_vars.nc,80lev/simin_vars.nc,50lev/simin_vars.nc,50lev_assigned/simin_vars.nc,38lev/simin_vars.nc -f '120lev,80lev,50lev,50leva,38lev:auto:auto:0|6|2:FPS!Alps!vert!levels:pdf:no:true'
    68 
     68## e.g. # drawing.py -o draw_2Dshad_map -S 'orog;$conv^{ini}$;lat|-1,lon|-1;lon;lat;auto;rainbow#auto#auto#time@minutes!since!1949-12-01!00:00:00|exct,6,h|%d$^{%H}$|date!([DD]$^{[HH]}$);Srange,Srange;convini|Case1|1a;pdf;binary|shadow,NW,auto|-70.,-36,-62.,-30.;cyl,c;yes' -v convini -f UBA_ERA-I_1a_2D.nc
    6969
    7070#######
     
    1063210632        [figt]: title of the figure ('|' for spaces)
    1063310633        [kindfig]: kind of file for the figure output (ps, eps, png, pdf, ...)
    10634         [mapfmt] = [cbarmap]|[mapkind] values for the map
     10634        [mapfmt] = [cbarmap]|[mapkind]|[lonlatbox] values for the map
    1063510635          cbarmap: name of the colorbar for the map
    1063610636          mapkind: kind of map to use in the plot
    1063710637            'direct': values are they come
    10638             'shadow',[pos]: pseudo-shadding from a given location of the sun
     10638            'shadow',[pos],[enhance]: pseudo-shadding from a given location of the sun
    1063910639              [pos]: 'N', 'NW'
     10640              [enhance]: enhance factor for the shading ('auto' for 1./5.)
     10641          lonlatbox: [lonSW],[latSW],[lonNE],[latNE] to plot only a lon,lat box
     10642            'full': for the whole domain
    1064010643        [mapv]: map characteristics: [proj],[res]
    1064110644          see full documentation: http://matplotlib.org/basemap/
     
    1071210715
    1071310716    mapkind = mapfmt[1]
     10717    if mapfmt[2] == 'full':
     10718        lonlatbox = None
     10719    elif len(mapfmt[2].split(',')) == 4:
     10720        lonlatbox = []
     10721        for lL in mapfmt[2].split(','):
     10722            lonlatbox.append(np.float(lL))
     10723    else:
     10724        print errormsg
     10725        print '  ' + fname + ": lonlatbox value '" + mapfmt[2] + "' not ready !!"
     10726        print '    for a lonlatbox 4 values are required. Values passed:',           \
     10727          mapfmt[2].splot(',')
     10728        quit(-1)
     10729   
    1071410730
    1071510731    if mapkind == 'direct':
     
    1071810734        mapv = np.zeros((dy,dx), dtype=np.float)
    1071910735        sunpos = mapkind.split(',')[1]
     10736        enhance = gen.auto_val(mapkind.split(',')[2], 1./5.)
    1072010737        if sunpos == 'N':
    1072110738            ## Linear shadow from N
     
    1073310750            print '    available ones:', availsunpos
    1073410751            quit(-1)
     10752        xmapv = np.max(mapv)*enhance
     10753        mapv = np.where(mapv > xmapv, xmapv, mapv)
     10754        mapv = ma.masked_less(mapv, 0.)
    1073510755    else:
    1073610756        print errormsg
     
    1082410844            cbarlab.append('{:6g}'.format(cpos))
    1082510845    elif colorbarv[3][0:4] == 'time':
    10826         print 'Lluis colorbarv', colorbarv
    1082710846        timevals = colorbarv[3].split('@')[1]
    1082810847        timeunit = timevals.split('|')[0].replace('!',' ')
     
    1083210851        cbarpos, cbarlab = drw.CFtimes_plot([nbarv, xbarv], timeunit, timekind, timefmt)
    1083310852        vnamesfig = timelabel
    10834         varunits = '-'
     10853        varunits = None
    1083510854        fmtcolbar = '%s'
    1083610855
     
    1084210861
    1084310862    drw.plot_2Dshad_map(mapv, valshad, mapfmt[0], colormapv, xaxis, yaxis, odimxv,   \
    10844       odimyv, mapvalue, shading_nx, figtitle, figkind, close)
     10863      odimyv, lonlatbox, mapvalue, shading_nx, figtitle, figkind, close)
    1084510864
    1084610865    return
     
    1085110870#values='orog;$conv^{ini}$;lat|-1,lon|-1;lon;lat;auto;rainbow#auto#auto#' +     \
    1085210871#  'time@minutes!since!1949-12-01!00:00:00|exct,12,h|%d$^{%H}$|date!'+          \
    10853 #  '([DD]$^{[HH]}$);Srange,Srange;Case1|1a;pdf;binary|shadow,NW;cyl,c;yes'
     10872#  '([DD]$^{[HH]}$);Srange,Srange;Case1|1a;pdf;binary|shadow,NW,auto|' +        \
     10873#  '-70.,-36,-62.,-30.;cyl,c;yes'
    1085410874#draw_2Dshad_map(ncfile, values, 'convini', axfig=None, fig=None)
    1085510875
  • trunk/tools/drawing_tools.py

    r2102 r2105  
    148148# date_CFtime:
    149149# pot_values: Function to modify a seies of values by their potency of 10
    150 # CFtimes_plot:
     150# CFtimes_plot: Function to provide a list of string values from a CF time values in order
     151#   to use them in a plot, according to the series of characteristics.
    151152# color_lines:
    152153# output_kind:
     
    24162417        if trefu == 'd': timev = timev - secs0001_1901/(24.*3600.)
    24172418        if trefu == 'h': timev = timev - secs0001_1901/(3600.)
    2418         if trefu == 'm': timev = timev - secs0001_1901/(60.)
     2419        if trefu == 'i': timev = timev - secs0001_1901/(60.)
    24192420        if trefu == 's': timev = timev - secs0001_1901
    24202421        if trefu == 'l': timev = timev - secs0001_1901*1000.
     
    26182619                timeout.append(datev)
    26192620                it = it + 1                 
     2621
    26202622        elif tu == 'i':
    26212623            datev=firstTdt
     
    26432645                datev = firstTdt + dt.timedelta(seconds=Nunits*60*it)
    26442646                timeout.append(datev)
    2645                 it = it + 1                 
     2647                it = it + 1       
    26462648        elif tu == 's':
    26472649            datev=firstTdt
     
    1346513467#prop={'size':legvs[1]}, ncol=legvs[2])prop={'size':8})prop={'size':8})prop={'size':8})
    1346613468
    13467 def plot_2Dshad_map(mapvals, values, cbarmap, cbarv, xaxv, yaxv, dimxv, dimyv, mapv, \
    13468   vs, figtitle, figk, close):
     13469def plot_2Dshad_map(mapvals, values, cbarmap, cbarv, xaxv, yaxv, dimxv, dimyv, lLbox,\
     13470  mapv, vs, figtitle, figk, close):
    1346913471    """ Function to plot a map of mask values on top of a map in shadow
    1347013472      mapvals: 2D values to use for the map
     
    1348313485      yaxv= list with the y-axis paramteres [style, format, number and orientation]
    1348413486      dim[x/y]v: values along x/y axes
     13487      lLbox: whether only a lonlatbox for the map should be used or not
    1348513488      mapv: values of the map
    1348613489      vs: range of values in the figure
     
    1354413547        dy = lat0.shape[0]
    1354513548
    13546         nlon = np.min(lon0)
    13547         xlon = np.max(lon0)
    13548         nlat = np.min(lat0)
    13549         xlat = np.max(lat0)
     13549        if lLbox is None:
     13550            nlon = np.min(lon0)
     13551            xlon = np.max(lon0)
     13552            nlat = np.min(lat0)
     13553            xlat = np.max(lat0)
     13554        else:
     13555            nlon = lLbox[0]
     13556            xlon = lLbox[2]
     13557            nlat = lLbox[1]
     13558            xlat = lLbox[3]
    1355013559
    1355113560        lon2 = lon0[dy/2,dx/2]
     
    1358013589    plt.pcolormesh(x, y, values, cmap=plt.get_cmap(cbarv[2]), vmin=vsend[0], vmax=vsend[1])
    1358113590
    13582     print 'Lluis cbarv:', cbarv
    13583 
    13584     cbar = plt.colorbar(format=cbarv[3],orientation=cbarv[4], ticks=cbarv[5])
     13591    cbar = plt.colorbar(orientation=cbarv[4], ticks=cbarv[5])
    1358513592    if cbarv[4] == 'horizontal':
    1358613593        # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib
    1358713594        cbar.ax.set_xticklabels(cbarv[6],rotation=90)
    1358813595    else:
    13589         cbar.ax.set_xticklabels(cbarv[6])
     13596        cbar.ax.set_yticklabels(cbarv[6])
    1359013597
    1359113598    if not mapv is None:
     
    1366813675
    1366913676# units labels
    13670     cbar.set_label(gen.latex_text(cbarv[0]) + ' (' + units_lunits(cbarv[1]) + ')')
     13677    if cbarv[1] is not None:
     13678        cbar.set_label(gen.latex_text(cbarv[0]) + ' (' + units_lunits(cbarv[1]) + ')')
     13679    else:
     13680        cbar.set_label(gen.latex_text(cbarv[0]))
    1367113681   
    1367213682    plt.title(gen.latex_text(figtitle))
Note: See TracChangeset for help on using the changeset viewer.