Changeset 2608 in lmdz_wrf


Ignore:
Timestamp:
Jun 17, 2019, 4:53:10 AM (5 years ago)
Author:
lfita
Message:

Almost there? Not fully working cut_x

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/geometry_tools.py

    r2607 r2608  
    467467
    468468    return btw
     469
     470def add_secpolygon_list(listv, iip, eep, polygon):
     471    """ Function to add a range of points of a polygon into a list
     472      listv: list into which add values of the polygon
     473      iip: initial value of the range
     474      eep: ending value of the range
     475      polygon: array with the points of the polygon
     476    """
     477    fname = 'add_secpolygon_list'
     478
     479    if eep > iip:
     480        for ip in range(iip,eep): listv.append(polygon[ip,:])
     481    else:
     482        for ip in range(iip,eep,-1): listv.append(polygon[ip,:])
     483
     484    return
    469485
    470486def cut_ypolygon(polygon, yval, keep='below', Nadd=20):
     
    881897        Ncpts.append(ecut[ic] - icut[ic])
    882898
    883     cutpolygon = np.ones((Ntotpts+Ncuts,2), dtype=np.float)*gen.fillValue
     899    cutpolygon = []
    884900
    885901    iipc = 0
     
    888904        if keep == 'left':
    889905            if ic == 0:
    890                 cutpolygon[0:icut[ic],:] = polygon[0:icut[ic],:]
     906                add_secpolygon_list(cutpolygon,0,icut[ic],polygon)
    891907                iipc = icut[ic]
    892908            else:
    893                 cutpolygon[iipc:iipc+dcpt-1,:] = polygon[icut[ic]+1:ecut[ic],:]
     909                add_secpolygon_list(cutpolygon,icut[ic]+1,ecut[ic],polygon)
     910                #cutpolygon[iipc:iipc+dcpt-1,:] = polygon[icut[ic]+1:ecut[ic],:]
    894911                iipc = iipc + dcpt -1
    895912        else:
    896             cutpolygon[iipc,:] = ipt[ic]
    897             cutpolygon[iipc:iipc+dcpt-1,:]=polygon[icut[ic]+1:ecut[ic],:]
     913            cutpolygon.append(ipt[ic])
     914            add_secpolygon_list(cutpolygon,icut[ic]+1,ecut[ic],polygon)
     915            #cutpolygon[iipc:iipc+dcpt-1,:]=polygon[icut[ic]+1:ecut[ic],:]
    898916            iipc = iipc+dcpt-1
    899917
     
    906924            cutline[ip,:] = ipt[ic] + np.array([dy*ip,dx*ip])
    907925        cutline[Nadds[ic]-1,:] = ept[ic]
     926        print 'Lluis ipt0', ipt[ic], 'cutline[Nadds-ic,:]', cutline[Nadds[ic]-1,:], 'ept', ept[ic]
    908927        if keep == 'left':
    909             if ic == 0: cutpolygon[iipc:iipc+Nadds[ic],:] = cutline
    910             else: cutpolygon[iipc:iipc+Nadds[ic],:] = cutline[::-1]
     928            if ic == 0:
     929                for ip in range(Nadds[ic]): cutpolygon.append(cutline[ip,:])
     930            else:
     931                for ip in range(Nadds[ic]-1,0,-1): cutpolygon.append(cutline[ip,:])
    911932            iipc = iipc+Nadds[ic]
    912933            if ic == 0:
    913                 cutpolygon[iipc:iipc+N-ecut[ic]-1,:] = polygon[ecut[ic]+1:N,:]
    914                 iipc = iipc + N-ecut[ic]-1
    915                 cutpolygon[iipc,:] = polygon[0,:]
     934#                cutpolygon[iipc:iipc+N-ecut[ic]-1,:] = polygon[ecut[ic]+1:N,:]
     935#                iipc = iipc + N-ecut[ic]-1
     936                add_secpolygon_list(cutpolygon,ecut[ic]-2,N,polygon)
     937                #cutpolygon[iipc:iipc+N-ecut[ic]+2,:] = polygon[ecut[ic]-2:N,:]
     938                iipc = iipc + N-ecut[ic]+2
     939                cutpolygon.append(polygon[0,:])
    916940                iipc = iipc + 1
    917941        else:
    918             cutpolygon[iipc:iipc+Nadds[ic],:] = cutline[::-1,:]
     942            for ip in range(Nadds[ic]-1,0,-1): cutpolygon.append(cutline[ip,:])
    919943            iipc = iipc+Nadds[ic]
     944        cutpolygon.append([gen.fillValueF, gen.fillValueF])
    920945        iipc = iipc + 1
    921946
     947    cutpolygon = np.array(cutpolygon)
    922948    rmpolygon = []
    923949    Npts = cutpolygon.shape[0]
     
    13181344        ept = cutvs[3]
    13191345        Ncuts = cutvs[4]
    1320         if Ncuts > 1:
     1346        if Ncuts > 0:
    13211347            # Re-shifting cuts by closest heigth.
    13221348            yis = []
     
    13621388        cutv = cuts[icc]
    13631389        Ncuts = cutv[4]
    1364         print '  icc:', icc, 'ic ec ipt ept _______'
    1365         for ic in range(Ncuts):
    1366             print ic, ':', cutv[0][ic], cutv[1][ic], cutv[2][ic], cutv[3][ic]
     1390        if Ncuts == 0:
     1391            print errormsg
     1392            print '  ' + fname + ": no cuts for xval=", xvals[icc], '!!'
     1393            quit(-1)
     1394        #print '  icc:', icc, 'ic ec ipt ept _______'
     1395        #for ic in range(Ncuts):
     1396        #    print ic, ':', cutv[0][ic], cutv[1][ic], cutv[2][ic], cutv[3][ic]
    13671397
    13681398        # Length of joining lines
     
    13991429            for ic in range(Ncuts-1):
    14001430                cutpolygon.append(ipt[ic])
    1401                 if ic == 0:
    1402                     for ip in range(icut[ic],N-1): cutpolygon.append(polygon[ip,:])
    1403                 for ip in range(icut[ic],ecut[ic]): cutpolygon.append(polygon[ip,:])
    1404                 # line
    1405                 print 'Lluis ept', ept[ic], 'ipt+1', ipt[ic+1], 'Nadds:', Nadds[ic]
    1406                 dx = (ipt[ic+1][1] - ept[ic][1])/(Nadds[ic]-1)
    1407                 dy = (ipt[ic+1][0] - ept[ic][0])/(Nadds[ic]-1)
     1431                dx = (ept[ic][1] - ipt[ic][1])/(Nadds[ic]-1)
     1432                dy = (ept[ic][0] - ipt[ic][0])/(Nadds[ic]-1)
    14081433                for ip in range(1,Nadds[ic]-1):
    1409                     cutpolygon.append([ept[ic][0]+dy*ip, ept[ic][1]+dy*ip])
     1434                    cutpolygon.append([ipt[ic][0]+dy*ip, ipt[ic][1]+dx*ip])
     1435                cutpolygon.append(ept[ic])
     1436                for ip in range(ecut[ic]+1,icut[ic+1]): cutpolygon.append(polygon[ip,:])
     1437
     1438            print 'Lluis ', Ncuts, 'ic', Ncuts-1
    14101439            ic = Ncuts-1
    1411             print ic, 'final', iic,' :', icut[ic], ecut[ic]
    1412             for ip in range(icut[ic],ecut[ic]): cutpolygon.append(polygon[ip,:])
     1440            cutpolygon.append(ipt[ic])
     1441            dx = (ept[ic][1] - ipt[ic][1])/(Nadds[ic]-1)
     1442            dy = (ept[ic][0] - ipt[ic][0])/(Nadds[ic]-1)
     1443            for ip in range(1,Nadds[ic]-1):
     1444                cutpolygon.append([ipt[ic][0]+dy*ip, ipt[ic][1]+dx*ip])
    14131445        # right side
    14141446        else:
     
    14161448                cutpolygon.append(ipt[ic])
    14171449
    1418                 for ip in range(icut[ic],ecut[ic]): cutpolygon.append(polygon[ip,:])
    14191450                # line
    1420                 dx = (ipt[ic+1][1] - ept[ic][1])/(Nadds[ic]-1)
    1421                 dy = (ipt[ic+1][0] - ept[ic][0])/(Nadds[ic]-1)
     1451                dx = (ept[ic][1] - ipt[ic][1])/(Nadds[ic]-1)
     1452                dy = (ept[ic][0] - ipt[ic][0])/(Nadds[ic]-1)
    14221453                for ip in range(1,Nadds[ic]-1):
    1423                     cutpolygon.append([ept[ic,0]+dy*ip, ept[ic,0]+dy*ip])
     1454                    cutpolygon.append([ipt[ic][0]+dy*ip, ipt[ic][1]+dx*ip])
     1455                cutpolygon.append(ept[ic])
     1456                for ip in range(ecut[ic],icut[ic+1]): cutpolygon.append(polygon[ip,:])
     1457
    14241458            ic = Ncuts-1
    1425             for ip in range(icut[ic],ecut[ic]): cutpolygon.append(polygon[ip,:])
    1426             for ip in range(ecut[ic],N-1): cutpolygon.append(polygon[ip,:])
     1459            cutpolygon.append(ipt[ic])
     1460            # line
     1461            dx = (ept[ic][1] - ipt[ic][1])/(Nadds[ic]-1)
     1462            dy = (ept[ic][0] - ipt[ic][0])/(Nadds[ic]-1)
     1463            for ip in range(1,Nadds[ic]-1):
     1464                cutpolygon.append([ipt[ic][0]+dy*ip, ipt[ic][1]+dx*ip])
     1465            cutpolygon.append(ept[ic])
    14271466        sides[iic] = cutpolygon
    1428         for ip in range(len(cutpolygon)): iic, ip, ':', cutpolygon[ip]
    14291467       
    14301468    # joining sides by e1[Ncuts1-1] --> i2[0]; e2[Ncuts2-1] --> i1[0]
    14311469    cutv1 = cuts[0]
    14321470    Ncuts1 = cutv1[4]
    1433     ec1 = cutv1[1][Ncuts1-1]
     1471    ec1 = cutv1[1][np.max([0,Ncuts1-1])]
    14341472    ic1 = cutv1[0][0]
    1435     ept1 = cutv1[3][Ncuts1-1]
     1473    ept1 = cutv1[3][np.max([0,Ncuts1-1])]
    14361474    ipt1 = cutv1[2][0]
    14371475
    1438     cutv2 = cuts[0]
     1476    cutv2 = cuts[1]
    14391477    Ncuts2 = cutv2[4]
    1440     ec2 = cutv2[1][Ncuts1-1]
     1478    ec2 = cutv2[1][np.max([0,Ncuts2-1])]
    14411479    ic2 = cutv2[0][0]
    1442     ept2 = cutv2[3][Ncuts1-1]
     1480    ept2 = cutv2[3][np.max([0,Ncuts2-1])]
    14431481    ipt2 = cutv2[2][0]
    14441482
    14451483    finalcutpolygon = sides[0]
    1446     for ip in range(ec1,ic2): finalcutpolygon.append(polygon[ip,:])
     1484    for ip in range(ec1+1,ic2): finalcutpolygon.append(polygon[ip,:])
    14471485    finalcutpolygon = finalcutpolygon + sides[1]
    1448     for ip in range(ec2,ic1): finalcutpolygon.append(polygon[ip,:])
    1449 
     1486    for ip in range(ec2+1,ic1): finalcutpolygon.append(polygon[ip,:])
     1487    finalcutpolygon.append(ipt1)
    14501488
    14511489    finalcutpolygon = np.array(finalcutpolygon)
     
    34143452    buoydic = {'buoy': [buoy[0:N2,:],'-','#FFFF00',1.5],                             \
    34153453      'sign': [buoy[N2+1:N,:],'-','#FFFF00',1.5],'fifth1':[fifth1,'-','#FFFF00',1.5],\
    3416       'fifth2': [fifth2,'-','#FFFF00',1.5],'fifth3': [fifth3,'-','#0000FF',1.5],     \
    3417       'fifth4': [fifth4,'-','#FFFF00',1.5],'fifth5': [fifth5,'-','#0000FF',1.5]}
     3454      'fifth2': [fifth2,'-','#0000FF',1.5],'fifth3': [fifth3,'-','#FFFF00',1.5],     \
     3455      'fifth4': [fifth4,'-','#0000FF',1.5],'fifth5': [fifth5,'-','#FFFF00',1.5]}
    34183456
    34193457    return buoy, buoysecs, buoydic
     
    35663604    if drwxline:
    35673605        ax.plot([xline[0,0],xline[1,0]], [xline[0,1],xline[1,1]],                    \
    3568           [xline[0,2],xline[1,2]], linev[0], color=linev[1], linewidth=linev[2],  label='xline')
     3606          [xline[0,2],xline[1,2]], linev[0], color=linev[1], linewidth=linev[2],     \
     3607          label='xline')
    35693608
    35703609    # y line
     
    35723611    if drwyline:
    35733612        ax.plot([yline[0,0],yline[1,0]], [yline[0,1],yline[1,1]],                    \
    3574           [yline[0,2],yline[1,2]], linev[0], color=linev[1], linewidth=linev[2],  label='yline')
     3613          [yline[0,2],yline[1,2]], linev[0], color=linev[1], linewidth=linev[2],     \
     3614          label='yline')
    35753615
    35763616    # z line
     
    35783618    if drwzline:
    35793619        ax.plot([zline[0,0],zline[1,0]], [zline[0,1],zline[1,1]],                    \
    3580           [zline[0,2],zline[1,2]], linev[0], color=linev[1], linewidth=linev[2],  label='zline')
     3620          [zline[0,2],zline[1,2]], linev[0], color=linev[1], linewidth=linev[2],     \
     3621          label='zline')
    35813622
    35823623    plt.legend()
     
    35973638        pvals = secvals[0]
    35983639        fillsec = []
    3599         for ip in range(pvals.shape[0]):
    3600             if type(pvals[ip,0]) != type(gen.mamat[1]) and type(pvals[ip,1]) != type(gen.mamat[1]):
     3640        Nvals = pvals.shape[0]
     3641        for ip in range(Nvals-1):
     3642            if type(pvals[ip][0]) != type(gen.mamat[1]) and type(pvals[ip+1][0]) != type(gen.mamat[1]):
    36013643                fillsec.append(pvals[ip,:])
    3602         #plt.fill(pvals[:,1], pvals[:,0], color=secvals[2])
     3644#        plt.fill(pvals[:,1], pvals[:,0], color=secvals[2])
    36033645        fillsec = np.array(fillsec)
    36043646        plt.fill(fillsec[:,1], fillsec[:,0], color=secvals[2])
Note: See TracChangeset for help on using the changeset viewer.