Changeset 2586 in lmdz_wrf


Ignore:
Timestamp:
Jun 3, 2019, 12:20:31 AM (6 years ago)
Author:
lfita
Message:

Changing name from val_between' to val_consec_between'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/geometry_tools.py

    r2585 r2586  
    4343# spheric_line: Function to transform a series of locations in lon, lat coordinates
    4444#   to x,y,z over an 3D spaceFunction to provide coordinates of a line  on a 3D space
    45 # val_between: Function to provide if a given value is between two consecutive ones
     45# val_consec_between: Function to provide if a given value is between two consecutive ones
    4646# write_join_poly: Function to write an ASCII file with the combination of polygons
    4747
     
    436436    return polys
    437437
    438 def val_between(valA, valB, val):
     438def val_consec_between(valA, valB, val):
    439439    """ Function to provide if a given value is between two consecutive ones
    440440      valA: first value
    441441      valB: second value
    442442      val: value to determine if it is between
    443       >>> val_between(0.5,1.5,0.8)
     443      >>> val_consec_between(0.5,1.5,0.8)
    444444      True
    445       >>> val_between(0.5,1.5.,-0.8)
     445      >>> val_consec_between(0.5,1.5.,-0.8)
    446446      False
    447       >>> val_between(0.5,1.5,0.5)
     447      >>> val_consec_between(0.5,1.5,0.5)
    448448      True
    449     """
    450     fname = 'val_between'
     449      >>> val_consec_between(-1.58, -1.4, -1.5)
     450      True
     451      >>> val_consec_between(-1.48747753212, -1.57383530044, -1.5)
     452      False
     453    """
     454    fname = 'val_consec_between'
    451455
    452456    btw = False
     457    diffA = valA - val
     458    diffB = valB - val
     459    absdA = np.abs(diffA)
     460    absdB = np.abs(diffB)
     461    #if (diffA/absdA)* (diffB/absdB) < 0.: btw = True
     462#    if valA < 0. and valB < 0. and val < 0.:
     463#        if (valA >= val and valB < val) or (valA > val and valB <= val): btw =True
     464#    else:
     465#        if (valA <= val and valB > val) or (valA < val and valB >= val): btw =True
    453466    if (valA <= val and valB > val) or (valA < val and valB >= val): btw =True
    454     if (valA >= val and valB < val) or (valA > val and valB <= val): btw =True
    455467
    456468    return btw
     
    494506                if eep == N: eep = 0
    495507     
    496                 if val_between(polygon[ip,0], polygon[eep,0], yval):
     508                if val_consec_between(polygon[ip,0], polygon[eep,0], yval):
    497509                    icut.append(ip)
    498510                    dx = polygon[eep,1] - polygon[ip,1]
     
    501513                    ipt.append([yval, polygon[ip,1]+dx*dd/dy])
    502514
    503                 if val_between(polygon[ip,0], polygon[eep,0], yval):
     515                if val_consec_between(polygon[ip,0], polygon[eep,0], yval):
    504516                    ecut.append(ip)
    505517                    dx = polygon[eep,1] - polygon[ip,1]
     
    514526            if eep == N: eep = 0
    515527     
    516             if val_between(polygon[ip,0], polygon[eep,0], yval):
     528            if val_consec_between(polygon[ip,0], polygon[eep,0], yval):
    517529                icut.append(ip)
    518530                dx = polygon[eep,1] - polygon[ip,1]
     
    521533                ipt.append([yval, polygon[ip,1]+dx*dd/dy])
    522534
    523             if val_between(polygon[ip,0], polygon[eep,0], yval):
     535            if val_consec_between(polygon[ip,0], polygon[eep,0], yval):
    524536                ecut.append(ip)
    525537                dx = polygon[eep,1] - polygon[ip,1]
     
    636648                if eep == N: eep = 0
    637649     
    638                 if val_between(polygon[ip,1], polygon[eep,1], xval):
     650                if val_consec_between(polygon[ip,1], polygon[eep,1], xval):
    639651                    icut.append(ip)
    640652                    dx = polygon[eep,1] - polygon[ip,1]
     
    643655                    ipt.append([polygon[ip,0]+dy*dd/dx, xval])
    644656
    645                 if val_between(polygon[ip,1], polygon[eep,1], xval):
     657                if val_consec_between(polygon[eep,1], polygon[ip,1], xval):
    646658                    ecut.append(ip)
    647659                    dx = polygon[eep,1] - polygon[ip,1]
     
    656668            if eep == N: eep = 0
    657669     
    658             print ip, polygon[ip,1], polygon[eep,1], xval, ':', val_between(polygon[ip,1], polygon[eep,1], xval)
    659             if val_between(polygon[ip,1], polygon[eep,1], xval):
     670            print ip, polygon[ip,1], polygon[eep,1], xval, ':', val_consec_between(polygon[ip,1], polygon[eep,1], xval)
     671            if val_consec_between(polygon[ip,1], polygon[eep,1], xval):
    660672                icut.append(ip)
    661673                dx = polygon[eep,1] - polygon[ip,1]
     
    664676                ipt.append([polygon[ip,0]+dy*dd/dx, xval])
    665677
    666             if val_between(polygon[ip,1], polygon[eep,1], xval):
     678            if val_consec_between(polygon[eep,1], polygon[ip,1], xval):
    667679                ecut.append(ip)
    668680                dx = polygon[eep,1] - polygon[ip,1]
     
    677689    else:
    678690        print '  ' + fname + ': found ', Ncuts, ' Ncuts'
    679         print '    yval=', xval, 'cut, ip; ipt ep; ept ________'
     691        print '    xval=', xval, 'cut, ip; ipt ep; ept ________'
    680692        for ic in range(Ncuts):
    681693            print '      ', ic, icut[ic], ';', ipt[ic], ecut[ic], ';', ept[ic]
     
    703715        ip = ipt[ic]
    704716        if ic == 0:
    705             dpts = icut[ic] + ecut[ic] + Nadds[ic]
     717            dpts = ecut[ic] - icut[ic] + Nadds[ic] + icut[ic]
    706718        else:
    707719            dpts = ecut[ic] - icut[ic] + Nadds[ic] - 1
     
    712724        Ntotpts = Ntotpts + dpts
    713725
    714     cutpolygon = np.ones((Ntotpts,2), dtype=np.float)*gen.fillValue
     726    cutpolygon = np.ones((Ntotpts+Ncuts-1,2), dtype=np.float)*gen.fillValue
    715727
    716728    iip = 0
     
    720732        if keep == 'left':
    721733            if ic == 0:
    722                 cutpolygon[0:icut[ic]] = polygon[0:icut[ic],:]
     734                cutpolygon[0:icut[ic],:] = polygon[0:icut[ic],:]
    723735                iip = icut[ic]
    724736                iipc = icut[ic]
    725             dcpt = Ncpts[ic]-Nadds[ic]
    726             cutpolygon[iipc+1:iipc+dcpt,:] = polygon[icut[ic]-1:ecut[ic]+1,:]
     737                dcpt = ecut[ic]-icut[ic]
     738                print ic, ':', 0, icut[ic], 'iipc:', iipc, 'dcpt', dcpt
     739            else:
     740                dcpt = Ncpts[ic]-Nadds[ic]
     741            print ic, 'dcpt:', dcpt, '<Ncpts>', Ncpts[ic], '<--', icut[ic]-1,ecut[ic]+1, '=',  iipc+1, iipc+dcpt+1
     742            cutpolygon[iipc+1:iipc+dcpt+1,:] = polygon[icut[ic]-1:ecut[ic]+1,:]
    727743            iipc = iipc + dcpt
    728744        else:
Note: See TracChangeset for help on using the changeset viewer.