Changeset 2697 in lmdz_wrf for trunk


Ignore:
Timestamp:
Aug 15, 2019, 5:25:20 PM (6 years ago)
Author:
lfita
Message:

Starting to include 'geo_topo_boxes' with nice-fixed topography

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r2696 r2697  
    110110# draw_topo_geogrid: plotting geo_em.d[nn].nc topography from WPS files
    111111# draw_topo_geogrid_boxes: plotting different geo_em.d[nn].nc topography from WPS files
     112# draw_topofix_geogrid_boxes: plotting different geo_em.d[nn].nc topography from WPS files
     113#   on a fixed low-level enhanced color mode
    112114# draw_trajectories: Function to draw different trajectories at the same time
    113115# draw_vals_trajectories: Function to draw values from the outputs from 'compute_tevolboxtraj'
     
    146148  'draw_stations_map', 'draw_Taylor',                                                \
    147149  'draw_time_lag', 'draw_timeSeries', 'draw_topo_geogrid',                           \
    148   'draw_topo_geogrid_boxes', 'draw_trajectories', 'draw_vals_trajectories',          \
     150  'draw_topo_geogrid_boxes', 'draw_topofix_geogrid_boxes',  'draw_trajectories',     \
     151  'draw_vals_trajectories',                                                          \
    149152  'draw_vectors',  'draw_vertical_levels', 'list_graphics', 'draw_WindRose',         \
    150153  'draw_WRFeta_levels', 'movie_2D_shad', 'variable_values']
     
    19121915    """ plotting different geo_em.d[nn].nc topography from WPS files
    19131916    draw_topo_geogrid_boxes(ncfiles, values)
    1914       ncfiles= ',' list of geo_em.d[nn].nc files to use (fisrt as topographyc reference)
     1917      ncfiles= ',' list of geo_em.d[nn].nc files to use (first as topographyc reference)
    19151918      values= [minTopo],[maxTopo]:[lonlatL]:[title]:[graphic_kind]:[mapvalues]:[labels]:[legvals]:[close]
    19161919        [min/max]Topo: minimum and maximum values of topography to draw
     
    19301933            * 'f', full
    19311934        legvals: [locleg]|[fontsize]:
    1932           [locleg]: location of the legend (0, autmoatic)
     1935          [locleg]: location of the legend (0, automatic)
    19331936            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    19341937            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    22282231        [title]: title of the plot ('|' for spaces)
    22292232        [legvals]=[locleg]|[fontsize]:
    2230           [locleg]: location of the legend (0, autmoatic)
     2233          [locleg]: location of the legend (0, automatic)
    22312234            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    22322235            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    24212424           [tfmt]; desired format
    24222425        [legvals]=[locleg]|[fontsize]|[Ncols]
    2423           [locleg]: location of the legend (0, autmoatic)
     2426          [locleg]: location of the legend (0, automatic)
    24242427            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    24252428            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    31113114        [pointlabels]: ',' of labels [only used if [collab]='None'] ('None' for no labels, '!' for spaces)
    31123115        [legvals]=[locleg]|[fontsize]:
    3113           [locleg]: location of the legend (0, autmoatic)
     3116          [locleg]: location of the legend (0, automatic)
    31143117            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    31153118            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    33493352        [labels]: ',' list of labels to use
    33503353        [legvals]=[locleg]|[fontsize]:
    3351           [locleg]: location of the legend (0, autmoatic)
     3354          [locleg]: location of the legend (0, automatic)
    33523355            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    33533356            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    34813484        [leglabs]: ',' separated list of labels for the lines
    34823485        [legvals]=[locleg]|[fontsize]: legend values
    3483           [locleg]: location of the legend (0, autmoatic)
     3486          [locleg]: location of the legend (0, automatic)
    34843487            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    34853488            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    36863689             * 'f', full
    36873690        [legvals]=[locleg]@[fontsize]: legend values
    3688           [locleg]: location of the legend (0, autmoatic)
     3691          [locleg]: location of the legend (0, automatic)
    36893692            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    36903693            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    40284031        [leglabels]: ',' separated list of labels for the legend
    40294032        [legvals]=[locleg]|[fontsize]:
    4030           [locleg]: location of the legend (0, autmoatic)
     4033          [locleg]: location of the legend (0, automatic)
    40314034            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    40324035            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    49364939        [kindfig]= kind of figure (png, ps, pdf)
    49374940        [legvals]=[locleg]|[fontsize]:
    4938           [locleg]: location of the legend (0, autmoatic)
     4941          [locleg]: location of the legend (0, automatic)
    49394942            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    49404943            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    51045107        [graphic_kind]= kind of figure (jpg, pdf, png)
    51055108        [legvals]=[locleg]|[fontsize]
    5106           [locleg]: location of the legend (0, autmoatic)
     5109          [locleg]: location of the legend (0, automatic)
    51075110            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    51085111            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    52905293        [graphtit]= title of the graph ('|', for spaces)
    52915294        [legvals]=[locleg]|[fontsize]:
    5292           [locleg]: location of the legend (0, autmoatic)
     5295          [locleg]: location of the legend (0, automatic)
    52935296            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    52945297            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    54075410        [labelaxis]: label in the figure of the common axis ('!' for spaces)
    54085411        [legvals]=[locleg]|[fontsize]:
    5409           [locleg]: location of the legend (0, autmoatic)
     5412          [locleg]: location of the legend (0, automatic)
    54105413            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    54115414            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    55905593        [labelaxis]: label in the figure of the common axis ('!' for spaces)
    55915594        [legvals]=[locleg]|[fontsize]:
    5592           [locleg]: location of the legend (0, autmoatic)
     5595          [locleg]: location of the legend (0, automatic)
    55935596            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    55945597            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    65606563        [graphtit]: title of the figure '!' for spaces
    65616564        [legvalues]=[locleg]|[fontsize]:
    6562           [locleg]: location of the legend (0, autmoatic)
     6565          [locleg]: location of the legend (0, automatic)
    65636566            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    65646567            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    67176720        [graphtit]: title of the figure '!' for spaces
    67186721        [legvalues]=[locleg]|[fontsize]:
    6719           [locleg]: location of the legend (0, autmoatic)
     6722          [locleg]: location of the legend (0, automatic)
    67206723            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    67216724            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    69286931        [graphtit]: title of the figure '!' for spaces
    69296932        [legvalues]=[locleg]|[fontsize]:
    6930           [locleg]: location of the legend (0, autmoatic)
     6933          [locleg]: location of the legend (0, automatic)
    69316934            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    69326935            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    71527155        [graphtit]: title of the figure '!' for spaces
    71537156        [legvalues]=[locleg]|[fontsize]:
    7154           [locleg]: location of the legend (0, autmoatic)
     7157          [locleg]: location of the legend (0, automatic)
    71557158            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    71567159            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    74507453        [graphtit]: title of the figure '!' for spaces
    74517454        [legvalues]=[locleg]|[fontsize]:
    7452           [locleg]: location of the legend (0, autmoatic)
     7455          [locleg]: location of the legend (0, automatic)
    74537456            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    74547457            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    77237726        [graphtit]: title of the figure '!' for spaces
    77247727        [legvalues]=[locleg]|[fontsize]:
    7725           [locleg]: location of the legend (0, autmoatic)
     7728          [locleg]: location of the legend (0, automatic)
    77267729            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    77277730            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    82688271        [graphtit]: title of the figure '!' for spaces
    82698272        [legvalues]=[locleg]|[fontsize]:
    8270           [locleg]: location of the legend (0, autmoatic)
     8273          [locleg]: location of the legend (0, automatic)
    82718274            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    82728275            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    1101611019        [kindfig]= kind of figure (png, ps, pdf)
    1101711020        [legvals]= [locleg]|[fontsize]|[Ncol] ('auto' for 0|12|1)
    11018           [locleg]: location of the legend (0, autmoatic)
     11021          [locleg]: location of the legend (0, automatic)
    1101911022            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    1102011023            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    1126011263#draw_river_pattern(values, riverns)
    1126111264
     11265def draw_topofix_geogrid_boxes(ncfiles, values):
     11266    """ plotting different geo_em.d[nn].nc topography from WPS files
     11267    draw_topo_geogrid_boxes(ncfiles, values) on a fixed low-level enhanced color mode
     11268      ncfiles= ',' list of geo_em.d[nn].nc files to use (first as topographyc
     11269        reference)
     11270      values= [lonlatL]:[title]:[graphic_kind]:[mapvalues]:[labels]:[legvals]:
     11271          [boxlvals]:[iix]:[mervals]:[parvals]:[coastlvals]:[countrylvals]:[ctylvals]
     11272          :[close]
     11273        lonlatL: limits of longitudes and latitudes [lonmin, latmin, lonmax, latmax] or None
     11274        title: title of the graph ('!' for spaces)
     11275        graphic_kind: kind of figure (jpg, pdf, png)
     11276        mapvalues: map characteristics [proj],[res]
     11277          see full documentation: http://matplotlib.org/basemap/
     11278          [proj]: projection
     11279            * 'cyl', cilindric
     11280            * 'lcc', lambert conformal
     11281          [res]: resolution:
     11282            * 'c', crude
     11283            * 'l', low
     11284            * 'i', intermediate
     11285            * 'h', high
     11286            * 'f', full
     11287        legvals: [locleg]|[fontsize]|[Ncol]:
     11288          [locleg]: location of the legend (0, automatic)
     11289            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
     11290            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     11291            9: 'upper center', 10: 'center'
     11292          [fontsize]: font size for the legend (auto for 12)
     11293          [Ncol]: number of columns (1)
     11294        labels: labels to write in the graph ('!' for spaces)
     11295        boxlvals: [line style]|[line width] values for the boxes (['-', 3], auto)
     11296        iix = starting x-figure fraction coordinate to plot the legend with the
     11297          colors (0.8, auto)
     11298        mervals: [fontsize]|[color line]|[labels rotation]|[line width] values for
     11299          the meridians  ([8,'#AAAAAA', 0, 0.5], auto)
     11300        parvals: [fontsize]|[color line]|[labels rotation]|[line width] values for
     11301          the parallels ([8,'#AAAAAA', 0, 0.5], auto)
     11302        coastlvals: [line width|color line] values for the coastline (None for any,
     11303          [0.25,'#161616'], auto)
     11304        countrylvals: [line width|color line] values for the countries (None for any,
     11305          [0.25, '#161616'], auto)
     11306        ctylvals: [line width|color line] values for the counties (None for any, None,
     11307          [0.25, '#080808'], auto)
     11308        close: Whether figure should be finished or not
     11309    """
     11310#    import matplotlib as mpl
     11311#    mpl.use('Agg')
     11312    import matplotlib.pyplot as plt
     11313
     11314    fname = 'draw_topofix_geogrid_boxes'
     11315
     11316    if values == 'h':
     11317        print fname + '_____________________________________________________________'
     11318        print draw_topofix_geogrid_boxes.__doc__
     11319        quit()
     11320
     11321    expectargs = '[lonlatL]:[title]:[graphic_kind]:[mapvalues]:[labels]:[legvals]:'+ \
     11322       '[boxlvals]:[iix]:[mervals]:[parvals]:[coastlvals]:[countrylvals]:[ctyvals]:'+\
     11323       '[close]'
     11324    drw.check_arguments(fname,values,expectargs,':')
     11325
     11326    lonlatLS = values.split(':')[0]
     11327    lonlatLv = lonlatLS.split(',')[0]
     11328
     11329    if lonlatLv == 'None':
     11330        lonlatL = None
     11331    else:
     11332        lonlatL = np.zeros((4), dtype=np.float)
     11333        lonlatL[0] = np.float(lonlatLS.split(',')[0])
     11334        lonlatL[1] = np.float(lonlatLS.split(',')[1])
     11335        lonlatL[2] = np.float(lonlatLS.split(',')[2])
     11336        lonlatL[3] = np.float(lonlatLS.split(',')[3])
     11337
     11338    grtit = values.split(':')[1].replace('!', ' ')
     11339    kindfig = values.split(':')[2]
     11340    mapvalues = values.split(':')[3]
     11341    labels = values.split(':')[4]
     11342    legvals = values.split(':')[5]
     11343    boxlvals = values.split(':')[6]
     11344    iix = values.split(':')[7]
     11345    mervals = values.split(':')[8]
     11346    parvals = values.split(':')[9]
     11347    coastlvals = values.split(':')[10]
     11348    countrylvals = values.split(':')[11]
     11349    ctylvals = values.split(':')[12]
     11350    close = gen.Str_Bool(values.split(':')[13])
     11351
     11352    ncfile = ncfiles.split(',')[0]
     11353    if not os.path.isfile(ncfile):
     11354        print errormsg
     11355        print '  ' + fname + ': domain file "' + ncfile + '" does not exist !!'
     11356        quit(-1)   
     11357
     11358    objdomf = NetCDFFile(ncfile, 'r')
     11359
     11360    objhgt = objdomf.variables['HGT_M']
     11361    objlandsea = objdomf.variables['LANDMASK']
     11362    objlon0 = objdomf.variables['XLONG_M']
     11363    objlat0 = objdomf.variables['XLAT_M']
     11364
     11365    topography = objhgt[0,:,:]
     11366    landsea = objlandsea[0,:,:]
     11367
     11368    Nfiles = len(ncfiles.split(','))
     11369    boxlabels = labels.split(',')
     11370
     11371    Xboxlines = []
     11372    Yboxlines = []
     11373
     11374    for ifile in range(Nfiles):
     11375        ncfile = ncfiles.split(',')[ifile]
     11376#        print ifile, ncfile
     11377        if not os.path.isfile(ncfile):
     11378            print errormsg
     11379            print '  ' + fname + ': domain file "' + ncfile + '" does not exist !!'
     11380            quit(-1)   
     11381
     11382        objdomfi = NetCDFFile(ncfile, 'r')
     11383   
     11384        objlon = objdomfi.variables['XLONG_M']
     11385        objlat = objdomfi.variables['XLAT_M']
     11386
     11387        dx = objlon.shape[2]
     11388        dy = objlon.shape[1]
     11389
     11390        Xboxlines.append(objlon[0,0,:])
     11391        Yboxlines.append(objlat[0,0,:])
     11392        Xboxlines.append(objlon[0,dy-1,:])
     11393        Yboxlines.append(objlat[0,dy-1,:])
     11394        Xboxlines.append(objlon[0,:,0])
     11395        Yboxlines.append(objlat[0,:,0])
     11396        Xboxlines.append(objlon[0,:,dx-1])
     11397        Yboxlines.append(objlat[0,:,dx-1])
     11398
     11399        objdomfi.close()
     11400
     11401    # Legend
     11402    legvals = drw.legend_values(legvals,'|')
     11403
     11404    if boxlvals != 'auto':
     11405        Boxlvals = [str(boxlvals.split('|')[0]), int(boxlvals.split('|')[0])]
     11406    else:
     11407        Boxlvals = ['-', 3]
     11408    if iix != 'auto': Iix = np.float(iix)
     11409    else: Iix = 0.8
     11410
     11411    if mervals != 'auto':
     11412        Mervals = [int(mervals.split('|')[0]), str(mervals.split('|')[1]),           \
     11413          np.float(mervals.split('|')[2]), np.float(mervals.split('|')[3])]
     11414    else:
     11415        Mervals = [8,'#AAAAAA', 0, 0.5]
     11416
     11417    if parvals != 'auto':
     11418        Parvals = [int(parvals.split('|')[0]), str(parvals.split('|')[1]),           \
     11419          np.float(parvals.split('|')[2]), np.float(parvals.split('|')[3])]
     11420    else:
     11421        Parvals = [8,'#AAAAAA', 0, 0.5]
     11422
     11423    if coastlvals != 'auto':
     11424        Coastlvals = [np.float(coastlvals.split('|')[0]),                            \
     11425          str(coastlvals.split('|')[1])]
     11426    else:
     11427        Coastlvals = [0.25,'#161616']
     11428
     11429    if countrylvals != 'auto':
     11430        Countrylvals = [np.float(countrylvals.split('|')[0]),                        \
     11431          str(countrylvals.split('|')[1])]
     11432    else:
     11433        Countrylvals = [0.25,'#161616']
     11434
     11435    if ctylvals != 'auto':
     11436        Ctylvals = [np.float(ctylvals.split('|')[0]), str(ctylvals.split('|')[1])]
     11437    else:
     11438        Ctylvals = [0.25,'#080808']
     11439
     11440    drw.plot_topofix_geogrid_boxes(topography, landsea, Xboxlines, Yboxlines,        \
     11441      boxlabels, objlon0, objlat0, lonlatL, grtit, kindfig, mapvalues, legvals,      \
     11442      Boxlvals, Iix, Mervals, Parvals, Coastlvals, Countrylvals, Ctylvals, close)
     11443
     11444    objdomf.close()
     11445
     11446    return
     11447
    1126211448#quit()
    1126311449
     
    1128711473  'draw_lines_time', 'draw_multiWindRose', 'draw_points', 'draw_river_pattern',      \
    1128811474  'draw_Taylor',                                                                     \
    11289   'draw_time_lag', 'draw_topo_geogrid_boxes',                                        \
     11475  'draw_time_lag', 'draw_topo_geogrid_boxes', 'draw_topofix_geogrid_boxes',          \
    1129011476  'draw_trajectories', 'draw_vals_trajectories', 'draw_WRFeta_levels',               \
    1129111477  'variable_values']
     
    1132811514
    1132911515    if opts.ncfile is not None and not os.path.isfile(opts.ncfile) and                   \
    11330       not drw.searchInlist(Notcheckingfile, oper):
     11516      not gen.searchInlist(Notcheckingfile, oper):
    1133111517        print errormsg
    1133211518        print '  ' + mainn + ': File ' + opts.ncfile + ' does not exist !!'
     
    1141311599    elif oper == 'draw_topo_geogrid_boxes':
    1141411600        draw_topo_geogrid_boxes(opts.ncfile, opts.values)
     11601    elif oper == 'draw_topofix_geogrid_boxes':
     11602        draw_topofix_geogrid_boxes(opts.ncfile, opts.values)
    1141511603    elif oper == 'draw_trajectories':
    1141611604        draw_trajectories(opts.ncfile, opts.values, opts.varname)
  • trunk/tools/drawing_tools.py

    r2696 r2697  
    33053305      tit= title of the graph
    33063306      linesn= list of values fot the legend
    3307       lloc= location of the legend (0, autmoatic)
     3307      lloc= location of the legend (0, automatic)
    33083308        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    33093309        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    43904390          * 'h', high
    43914391          * 'f', full
    4392       gloc= location of the legend (0, autmoatic)
     4392      gloc= location of the legend (0, automatic)
    43934393        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    43944394        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    63726372      vunit= units of the vaxis
    63736373      gtit= main title
    6374       gloc= location of the legend (0, autmoatic)
     6374      gloc= location of the legend (0, automatic)
    63756375        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    63766376        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    67566756      vmax= maximum value for the axis-value 'auto' for use the extreme
    67576757      legv = [gloc, gsize, Ncol] legend values
    6758         gloc= location of the legend (0, autmoatic)
     6758        gloc= location of the legend (0, automatic)
    67596759          1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    67606760          5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    1015510155      width= size of the column
    1015610156      gtit= title of the figure
    10157       lloc= location of the legend (0, autmoatic)
     10157      lloc= location of the legend (0, automatic)
    1015810158        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    1015910159        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    1032310323      width= size of the column
    1032410324      gtit= title of the figure
    10325       lloc= location of the legend (0, autmoatic)
     10325      lloc= location of the legend (0, automatic)
    1032610326        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    1032710327        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    1046210462      ptf= frequency of point plotting, 'all' for all time steps
    1046310463      gtit= title of the figure
    10464       lloc= location of the legend (0, autmoatic)
     10464      lloc= location of the legend (0, automatic)
    1046510465        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    1046610466        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    1068410684      ptf= frequency of point plotting, 'all' for all time steps
    1068510685      gtit= title of the figure
    10686       lloc= location of the legend (0, autmoatic)
     10686      lloc= location of the legend (0, automatic)
    1068710687        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    1068810688        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    1088810888      tlab= labels of the time-ticks
    1088910889      gtit= title of the figure
    10890       lloc= location of the legend (0, autmoatic)
     10890      lloc= location of the legend (0, automatic)
    1089110891        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    1089210892        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    1119011190      tlabs= labels of the time-ticks
    1119111191      gtit= title of the figure
    11192       lloc= location of the legend (0, autmoatic)
     11192      lloc= location of the legend (0, automatic)
    1119311193        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    1119411194        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    1145111451      tlabs= labels of the time-ticks
    1145211452      gtit= title of the figure
    11453       lloc= location of the legend (0, autmoatic)
     11453      lloc= location of the legend (0, automatic)
    1145411454        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
    1145511455        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     
    1456514565 
    1456614566    return
     14567
     14568def plot_topofix_geogrid_boxes(varv, landsea, boxesX, boxesY, boxlabels, olon, olat, \
     14569  lonlatLims, gtit, kfig, mapv, legvals=[0,8,1], boxlvals=['-', 3], iix=0.8,         \
     14570  mervals=[8,'#AAAAAA',0,0.5], parvals=[8,'#AAAAAA',0,0.5],                          \
     14571  coastlvals=[0.25,'#AAAAAA'], countrylvals=[0.25,'#161616'], ctylvals=None,         \
     14572  closeif=True):
     14573    """ plotting geo_em.d[nn].nc topography from WPS files on a fixed low-level     
     14574      enhanced color mode
     14575      varv= topography values of the first domain
     14576      landseamask= landseamask values of the first domain
     14577      boxesX/Y= 4-line sets to draw the boxes
     14578      boxlabels= labels for the legend of the boxes
     14579      o[lon/lat]= longitude and latitude objects
     14580      lonlatLims: limits of longitudes and latitudes [lonmin, latmin, lonmax, latmax]
     14581      gtit= title of the graph
     14582      kfig= kind of figure (jpg, pdf, png)
     14583      mapv= map characteristics: [proj],[res]
     14584        see full documentation: http://matplotlib.org/basemap/
     14585        [proj]: projection
     14586          * 'cyl', cilindric
     14587          * 'lcc', lamvbert conformal
     14588        [res]: resolution:
     14589          * 'c', crude
     14590          * 'l', low
     14591          * 'i', intermediate
     14592          * 'h', high
     14593          * 'f', full
     14594      legvals = [gloc, gsize, Ncols], values for the legend ([0,8,1], default)
     14595        gloc= location of the legend (0, automatic)
     14596          1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
     14597          5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     14598          9: 'upper center', 10: 'center'
     14599        gsiz= fontsize of the legend
     14600        Ncols = number of columns
     14601      boxlvals = values for the boxes [line style, line width] (['-', 3], default)
     14602      iix = starting x-figure fraction coordinate to plot the legend with the colors
     14603        (0.8, default)
     14604      mervals = values for the meridians [fontsize, color line, labels rotation,
     14605        line width] ([8,'#AAAAAA', 0, 0.5], default)
     14606      parvals = values for the parallels [fontsize, color line, labels rotation,
     14607        line width] ([8,'#AAAAAA', 0, 0.5], default)
     14608      coastlvals = values for the coastline [line width, color line] None for any
     14609        ([0.25,'#161616'], default)
     14610      countrylvals = values for the countries [line width, color line] None for any
     14611        ([0.25, '#161616'], default)
     14612      ctylvals = values for the counties [line width, color line] None for any (None,
     14613        default)
     14614      closeif= Boolean value if the figure has to be closed
     14615    """
     14616    fname = 'plot_topofix_geogrid'
     14617
     14618    topobnds=[-140., 0., 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.,\
     14619      1500., 2000., 3000., 4000., 7000.]
     14620    RGBtopocolors = [[119,152,93], [149,181,112], [189,209,137], [233,238,154],      \
     14621      [248,242,168], [251,231,163], [252,225,144], [248,213,133], [251,189,141],     \
     14622      [231,175,139], [202,149,132], [206,156,149], [228,182,192], [250,214,231],     \
     14623      [224,224,224], [255,255,255], [255,255,255]]
     14624
     14625    if type(varv) == type('S') and varv == 'h':
     14626        print fname + '_____________________________________________________________'
     14627        print plot_topofix_geogrid.__doc__
     14628        quit()
     14629
     14630    # Topography
     14631    topobndsS = []
     14632    for t in topobnds: topobndsS.append(str(t))
     14633
     14634    HEXtopocolors = []
     14635    Ncolors = len(RGBtopocolors)
     14636    for ic in range(Ncolors):
     14637        rgbv = np.array(RGBtopocolors[ic], dtype=np.float)/255.
     14638        #rgbvx = np.float(np.max(rgbv))
     14639        #if not np.all(rgbv == rgbvx):
     14640        #    for ii in range(3):
     14641        #        print rgbv[ii] - rgbvx
     14642        #        if rgbv[ii] == rgbvx: rgbv[ii] = 1.
     14643
     14644        rgbv = np.where(rgbv > 0.1, rgbv - 0.1, 0.)
     14645        if np.all(rgbv == 0.9): rgbv = rgbv/0.9
     14646
     14647        hexcol = gen.coldec_hex(rgbv)
     14648        HEXtopocolors.append(hexcol)
     14649
     14650    masktopo = np.where(landsea == 1., varv, gen.fillValueF)
     14651    masktopo = ma.masked_equal(masktopo, gen.fillValueF)
     14652
     14653    Ncolors = len(topobnds)
     14654    cmap = mpl.colors.ListedColormap(HEXtopocolors)
     14655    normc = mpl.colors.BoundaryNorm(topobnds, cmap.N)
     14656
     14657    #cols = color_lines(len(boxlabels))
     14658    cols = colorsauto
     14659
     14660    dx=varv.shape[1]
     14661    dy=varv.shape[0]
     14662
     14663#    plt.rc('text', usetex=True)
     14664
     14665    if mapv is None:
     14666        print emsg
     14667        print '  ' + fname + ': A projection parameter is needed None given !!'
     14668        quit(-1)   
     14669
     14670    m, meridians, parallels, x, y= mapFigure(olon[:], olat[:], lonlatLims, mapv, 5, 5)
     14671
     14672#    plt.rc('font', family='serif')
     14673
     14674    fig, axmat = plt.subplots(1,1)
     14675
     14676    plt.pcolormesh(x,y,masktopo,cmap=cmap, norm=normc, vmin=topobnds[0],             \
     14677      vmax=topobnds[Ncolors-2])
     14678
     14679    Nboxes = len(boxesX)/4
     14680    for ibox in range(Nboxes):
     14681        plt.plot(boxesX[ibox*4], boxesY[ibox*4], linestyle=boxlvals[0],              \
     14682          linewidth=boxlvals[1], color=cols[ibox],                                   \
     14683          label=gen.latex_text(boxlabels[ibox].replace('!',' ')))
     14684        plt.plot(boxesX[ibox*4+1], boxesY[ibox*4+1], linestyle=boxlvals[0],          \
     14685          linewidth=boxlvals[1], color=cols[ibox],                                   \
     14686          label=gen.latex_text(boxlabels[ibox].replace('!',' ')))
     14687        plt.plot(boxesX[ibox*4+2], boxesY[ibox*4+2], linestyle=boxlvals[0],          \
     14688          linewidth=boxlvals[1], color=cols[ibox],                                   \
     14689          label=gen.latex_text(boxlabels[ibox].replace('!',' ')))
     14690        plt.plot(boxesX[ibox*4+3], boxesY[ibox*4+3], linestyle=boxlvals[0],          \
     14691          linewidth=boxlvals[1], color=cols[ibox],                                   \
     14692          label=gen.latex_text(boxlabels[ibox].replace('!',' ')))
     14693
     14694    if coastlvals is not None:
     14695        m.drawcoastlines(linewidth=coastlvals[0], color=coastlvals[1])
     14696    if countrylvals is not None:
     14697        m.drawcountries(linewidth=countrylvals[0], color=countrylvals[1])
     14698    if ctylvals is not None:
     14699        m.drawcounties(linewidth=ctylvals[0], color=ctylvals[1])
     14700
     14701    m.drawmeridians(meridians, labels=[True,False,False,True], fontsize=mervals[0],  \
     14702      color=mervals[1], rotation=mervals[2], linewidth=mervals[3])
     14703    m.drawparallels(parallels, labels=[True,False,False,True], fontsize=parvals[0],  \
     14704      color=parvals[1], rotation=parvals[2], linewidth=parvals[3])
     14705
     14706    # FROM: https://matplotlib.org/examples/color/named_colors.html
     14707    # Get height and width
     14708    ncols = 1
     14709    nrows = len(topobnds)
     14710    X, Y = fig.get_dpi() * fig.get_size_inches()
     14711    h = Y / (nrows + 1)
     14712    w = X / ncols
     14713
     14714    cbox = unichr(9632)#+unichr(9632)+unichr(9632)
     14715    bbox = unichr(9633)
     14716    for i in range(1,Ncolors-2):
     14717        name = topobnds[i]
     14718        col = i % ncols
     14719        row = i // ncols
     14720        y = Y - (row*h) - h
     14721
     14722        xi_line = w*(col+0.05)
     14723        xf_line = w*(col+0.25)
     14724        xi_text = X*0.6+w*(col+0.3)
     14725
     14726        #axf.text(xi_text, y, str(name), fontsize=(h * 0.8), horizontalalignment='left',   \
     14727        #  verticalalignment='center')
     14728        #axf.hlines(y+h*0.1, xi_line, xf_line, color=HEXtopocolors[i], linewidth=(h*0.6))
     14729        #ax.annotate()
     14730
     14731        plt.annotate(str(name), xy=(iix,0.8-i*0.7/nrows), xycoords='figure fraction',    \
     14732          fontsize=10)
     14733        plt.annotate(cbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',    \
     14734          fontsize=10, color=HEXtopocolors[i])
     14735        plt.annotate(bbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',    \
     14736          fontsize=10, color='k')
     14737
     14738    i = 0
     14739    plt.annotate('< 0', xy=(iix,0.8-i*0.7/nrows), xycoords='figure fraction',            \
     14740      fontsize=10)
     14741    plt.annotate(cbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',        \
     14742      fontsize=10, color=HEXtopocolors[i])
     14743    plt.annotate(bbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',        \
     14744      fontsize=10, color='k')
     14745
     14746    i = Ncolors - 2
     14747    name = topobnds[i]
     14748    plt.annotate('> ' + str(name), xy=(iix,0.8-i*0.7/nrows), xycoords='figure fraction', \
     14749      fontsize=10)
     14750    plt.annotate(cbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',        \
     14751      fontsize=10, color=HEXtopocolors[i])
     14752    plt.annotate(bbox, xy=(iix-0.03,0.8-i*0.7/nrows), xycoords='figure fraction',        \
     14753      fontsize=10, color='k')
     14754
     14755    figname = 'plot_topofix_geogrid'
     14756    graphtit = gen.latex_text(gtit)
     14757    #cbar.set_label('height ($m$)')
     14758
     14759    plt.title(graphtit)
     14760    plt.legend(loc=legvals[0], prop={'size':legvals[1]}, ncol=legvals[2])
     14761   
     14762    output_kind(kfig, figname, closeif)
     14763
     14764    return
     14765
Note: See TracChangeset for help on using the changeset viewer.