Changeset 2546 in lmdz_wrf for trunk


Ignore:
Timestamp:
May 19, 2019, 3:33:49 PM (6 years ago)
Author:
lfita
Message:

Adding in `cut_ypolygon', 'keep' value

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/geometry_tools.py

    r2545 r2546  
    428428      yval: value to use to cut the polygon
    429429      keep: part to keep from the height ('bottom', default)
     430         'bottom': below the height
     431         'above': above the height
    430432      Nadd: additional points to add to draw the line (20, default)
    431433    """
     
    433435
    434436    N = polygon.shape[0]
     437    availkeeps = ['bottom', 'above']
     438
     439    if not gen.searchInlist(availkeeps, keep):
     440        print errormsg
     441        print '  ' + fname + ": wring keep '" + keep + "' value !!"
     442        print '    available ones:', availkeeps
     443        quit(-1)
    435444
    436445    ipt = None
     
    469478                dd = yval - polygon[ip,0]
    470479                ipt = [yval, polygon[ip,1]+dx*dd/dy]
    471                 print ip, 'Lluis pi:', polygon[ip,:], 'pi+1', polygon[eep,:]
    472                 print '    yval', yval, 'dx', dx, 'dy', dy
    473                 print '      ipt', ipt
    474480
    475481            if polygon[ip,0] >= yval and polygon[eep,0] <= yval:
     
    479485                dd = yval - polygon[ip,0]
    480486                ept = [yval, polygon[ip,1]+dx*dd/dy]
    481                 print ip, 'Lluis pi:', polygon[ip,:], 'pi+1', polygon[eep,:]
    482                 print '    yval', yval, 'dx', dx, 'dy', dy
    483                 print '      ept', ept
    484487
    485488    if ipt is None or ept is None:
     
    488491        irmv = 0
    489492        rmpolygon = []
    490         for ip in range(N):
    491             if polygon[ip,0] > yval:
    492                 rmpolygon.append([gen.fillValueF, gen.fillValueF])
    493             else:
    494                 rmpolygon.append(polygon[ip,:])
     493        if keep == 'bottom':
     494            for ip in range(N):
     495                if polygon[ip,0] > yval:
     496                    rmpolygon.append([gen.fillValueF, gen.fillValueF])
     497                else:
     498                    rmpolygon.append(polygon[ip,:])
     499        else:
     500            for ip in range(N):
     501                if polygon[ip,0] < yval:
     502                    rmpolygon.append([gen.fillValueF, gen.fillValueF])
     503                else:
     504                    rmpolygon.append(polygon[ip,:])
     505
    495506        Npts = len(rmpolygon)
    496507        cutpolygon = np.array(rmpolygon)
    497508    else:
    498         Npts = icut + (N-ecut) + Nadd
    499 
    500         cutpolygon = np.zeros((Npts,2), dtype=np.float)
    501         if type(polygon) == type(gen.mamat):
    502             cutpolygon[0:icut+1,:] = polygon[0:icut+1,:].filled(gen.fillValueF)
     509        if keep == 'bottom':
     510            Npts = icut + (N-ecut) + Nadd
     511
     512            cutpolygon = np.zeros((Npts,2), dtype=np.float)
     513            if type(polygon) == type(gen.mamat):
     514                cutpolygon[0:icut+1,:] = polygon[0:icut+1,:].filled(gen.fillValueF)
     515            else:
     516                cutpolygon[0:icut+1,:] = polygon[0:icut+1,:]
     517            iip = icut+1
    503518        else:
    504             cutpolygon[0:icut+1,:] = polygon[0:icut+1,:]
     519            Npts = ecut - icut + Nadd-1
     520
     521            cutpolygon = np.zeros((Npts,2), dtype=np.float)
     522            if type(polygon) == type(gen.mamat):
     523                cutpolygon[0:ecut-icut-1,:] = polygon[icut+1:ecut,:].filled(gen.fillValueF)
     524            else:
     525                cutpolygon[0:ecut-icut-1,:] = polygon[icut+1:ecut,:]
     526            iip = ecut-icut-1
    505527
    506528        # cutting line
     
    512534            cutline[ip,:] = ipt + np.array([dy*ip,dx*ip])
    513535        cutline[Nadd-1,:] = ept
    514         cutpolygon[icut+1:icut+1+Nadd,:] = cutline
    515         cutpolygon[icut+1+Nadd:Npts,:] = polygon[ecut+1:N,:]
     536        cutpolygon[iip:iip+Nadd,:] = cutline
     537        if keep == 'bottom':
     538            cutpolygon[iip+Nadd:Npts,:] = polygon[ecut+1:N,:]
    516539
    517540    cutpolygon = ma.masked_equal(cutpolygon, gen.fillValueF)
Note: See TracChangeset for help on using the changeset viewer.