Changeset 2374 in lmdz_wrf


Ignore:
Timestamp:
Mar 5, 2019, 2:19:03 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `drawpolygon_map': Function to plot a polygon into a map
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing_tools.py

    r2369 r2374  
    127127# draw_MerPara: Function to add the parallels and meridians into a figure with a
    128128#   panel of plots
     129# drawpolygon_map: Function to plot a polygon into a map
    129130# figureMap_size: Function to determine the real size of a figure adjusted to the
    130131#   ratio of the maps
     
    1438314384
    1438414385    return mapv
     14386
     14387def drawpolygon_map(vertices, mape, polylab, Nint, linev):
     14388    """ Function to plot a polygon into a map
     14389      vertices: Matrix of vertices of the polygon [[lon1,lat1], ..., [lonM,latM]]
     14390      mape: basemap map environtment where to draw the polygon
     14391      polylab: label of the polygon (already LaTeX freindly)
     14392      Nint: number of intermediate grid points to use in order to have lon, lat
     14393        following polygon borders
     14394      linev: list with the values for the line to be drawn [color, width, type]
     14395    """
     14396    fname = 'drawpolygon_map'
     14397
     14398    Lvert = vertices.shape[0]
     14399    for iv in range(Lvert-1):
     14400        pti = [vertices[iv,0], vertices[iv,1]]
     14401        pte = [vertices[iv+1,0], vertices[iv+1,1]]
     14402        ddx = (pte[0]-pti[0])/(Nint-1)
     14403        ddy = (pte[1]-pti[1])/(Nint-1)
     14404        if ddx != 0.:
     14405            ipti = np.arange(pti[0],pte[0]+ddx,ddx)
     14406        else:
     14407            ipti = np.ones((Nint), dtype=np.float)*pti[0]
     14408        if ddy != 0.:
     14409            iptj = np.arange(pti[1],pte[1]+ddy,ddy)
     14410        else:
     14411            iptj = np.ones((Nint), dtype=np.float)*pti[1]
     14412        pptii, pptjj = mape(ipti[0:Nint], iptj[0:Nint])
     14413        for ij in range(Nint-1):
     14414            if iv == 0 and ij == 0:
     14415                plt.plot([pptii[ij],pptii[ij+1]],[pptjj[ij],pptjj[ij+1]], linev[2],  \
     14416                  color=linev[0], linewidth=linev[1], label=polylab)
     14417            else:
     14418                plt.plot([pptii[ij],pptii[ij+1]],[pptjj[ij],pptjj[ij+1]], linev[2],  \
     14419                  color=linev[0], linewidth=linev[1])
     14420    pti = [vertices[Lvert-1,0], vertices[Lvert-1,1]]
     14421    pte = [vertices[0,0], vertices[0,1]]
     14422    ddx = (pte[0]-pti[0])/(Nint-1)
     14423    ddy = (pte[1]-pti[1])/(Nint-1)
     14424    if ddx != 0.:
     14425        ipti = np.arange(pti[0],pte[0]+ddx,ddx)
     14426    else:
     14427        ipti = np.ones((Nint), dtype=np.float)*pti[0]
     14428    if ddy != 0.:
     14429        iptj = np.arange(pti[1],pte[1]+ddy,ddy)
     14430    else:
     14431        iptj = np.ones((Nint), dtype=np.float)*pti[1]
     14432    pptii, pptjj = mape(ipti[0:Nint], iptj[0:Nint])
     14433    for ij in range(Nint-1):
     14434        plt.plot([pptii[ij],pptii[ij+1]],[pptjj[ij],pptjj[ij+1]], linev[2],          \
     14435          color=linev[0], linewidth=linev[1])
     14436
     14437    return
Note: See TracChangeset for help on using the changeset viewer.