Changeset 2609 in lmdz_wrf


Ignore:
Timestamp:
Jun 17, 2019, 11:42:22 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `add_secpolygon_list': Function to add a range of points of a polygon into a list (previously add, but uncommented)
  • `rm_consecpt_polygon': Function to remove consecutive same point of a polygon
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/geometry_tools.py

    r2608 r2609  
    2323
    2424####### Contents:
     25# add_secpolygon_list: Function to add a range of points of a polygon into a list
    2526# cut_between_[x/y]polygon: Function to cut a polygon between 2 given value of the [x/y]-axis
    2627# cut_[x/y]polygon: Function to cut a polygon from a given value of the [x/y]-axis
     
    3536#   cartesian coordinates over an sphere
    3637# read_join_poly: Function to read an ASCII file with the combination of polygons
     38# rm_consecpt_polygon: Function to remove consecutive same point of a polygon
    3739# rotate_2D: Function to rotate a vector by a certain angle in the plain
    3840# rotate_polygon_2D: Function to rotate 2D plain the vertices of a polygon
     
    483485
    484486    return
     487
     488def rm_consecpt_polygon(polygon):
     489    """ Function to remove consecutive same point of a polygon
     490      poly: polygon
     491    >>> poly = np.ones((5,2), dtype=np.float)
     492    >>> poly[2,:] = [2., 1.]
     493    rm_consecpt_polygon(poly)
     494    [[ 1.  1.]
     495     [ 2.  1.]
     496     [ 1.  1.]]
     497    """
     498    fname = 'rm_consecpt_polygon'
     499
     500    newpolygon = []
     501    prevpt = polygon[0,:]
     502    newpolygon.append(prevpt)
     503    for ip in range(1,polygon.shape[0]-1):
     504        if polygon[ip,0] != prevpt[0] or polygon[ip,1] != prevpt[1]:
     505            prevpt = polygon[ip,:]
     506            newpolygon.append(prevpt)
     507
     508    newpolygon = np.array(newpolygon)
     509
     510    return newpolygon
    485511
    486512def cut_ypolygon(polygon, yval, keep='below', Nadd=20):
     
    961987                rmpolygon.append(cutpolygon[ip,:])
    962988    Npts = len(rmpolygon)
    963     cutpolygon = np.array(rmpolygon)
     989
     990    rmpolygon = np.array(rmpolygon)
     991    cutpolygon = rm_consecpt_polygon(rmpolygon)
    964992
    965993    cutpolygon = ma.masked_equal(cutpolygon, gen.fillValueF)
Note: See TracChangeset for help on using the changeset viewer.