Changeset 2608 in lmdz_wrf
- Timestamp:
- Jun 17, 2019, 4:53:10 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2607 r2608 467 467 468 468 return btw 469 470 def 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 469 485 470 486 def cut_ypolygon(polygon, yval, keep='below', Nadd=20): … … 881 897 Ncpts.append(ecut[ic] - icut[ic]) 882 898 883 cutpolygon = np.ones((Ntotpts+Ncuts,2), dtype=np.float)*gen.fillValue899 cutpolygon = [] 884 900 885 901 iipc = 0 … … 888 904 if keep == 'left': 889 905 if ic == 0: 890 cutpolygon[0:icut[ic],:] = polygon[0:icut[ic],:]906 add_secpolygon_list(cutpolygon,0,icut[ic],polygon) 891 907 iipc = icut[ic] 892 908 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],:] 894 911 iipc = iipc + dcpt -1 895 912 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],:] 898 916 iipc = iipc+dcpt-1 899 917 … … 906 924 cutline[ip,:] = ipt[ic] + np.array([dy*ip,dx*ip]) 907 925 cutline[Nadds[ic]-1,:] = ept[ic] 926 print 'Lluis ipt0', ipt[ic], 'cutline[Nadds-ic,:]', cutline[Nadds[ic]-1,:], 'ept', ept[ic] 908 927 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,:]) 911 932 iipc = iipc+Nadds[ic] 912 933 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,:]) 916 940 iipc = iipc + 1 917 941 else: 918 cutpolygon[iipc:iipc+Nadds[ic],:] = cutline[::-1,:]942 for ip in range(Nadds[ic]-1,0,-1): cutpolygon.append(cutline[ip,:]) 919 943 iipc = iipc+Nadds[ic] 944 cutpolygon.append([gen.fillValueF, gen.fillValueF]) 920 945 iipc = iipc + 1 921 946 947 cutpolygon = np.array(cutpolygon) 922 948 rmpolygon = [] 923 949 Npts = cutpolygon.shape[0] … … 1318 1344 ept = cutvs[3] 1319 1345 Ncuts = cutvs[4] 1320 if Ncuts > 1:1346 if Ncuts > 0: 1321 1347 # Re-shifting cuts by closest heigth. 1322 1348 yis = [] … … 1362 1388 cutv = cuts[icc] 1363 1389 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] 1367 1397 1368 1398 # Length of joining lines … … 1399 1429 for ic in range(Ncuts-1): 1400 1430 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) 1408 1433 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 1410 1439 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]) 1413 1445 # right side 1414 1446 else: … … 1416 1448 cutpolygon.append(ipt[ic]) 1417 1449 1418 for ip in range(icut[ic],ecut[ic]): cutpolygon.append(polygon[ip,:])1419 1450 # 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) 1422 1453 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 1424 1458 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]) 1427 1466 sides[iic] = cutpolygon 1428 for ip in range(len(cutpolygon)): iic, ip, ':', cutpolygon[ip]1429 1467 1430 1468 # joining sides by e1[Ncuts1-1] --> i2[0]; e2[Ncuts2-1] --> i1[0] 1431 1469 cutv1 = cuts[0] 1432 1470 Ncuts1 = cutv1[4] 1433 ec1 = cutv1[1][ Ncuts1-1]1471 ec1 = cutv1[1][np.max([0,Ncuts1-1])] 1434 1472 ic1 = cutv1[0][0] 1435 ept1 = cutv1[3][ Ncuts1-1]1473 ept1 = cutv1[3][np.max([0,Ncuts1-1])] 1436 1474 ipt1 = cutv1[2][0] 1437 1475 1438 cutv2 = cuts[ 0]1476 cutv2 = cuts[1] 1439 1477 Ncuts2 = cutv2[4] 1440 ec2 = cutv2[1][ Ncuts1-1]1478 ec2 = cutv2[1][np.max([0,Ncuts2-1])] 1441 1479 ic2 = cutv2[0][0] 1442 ept2 = cutv2[3][ Ncuts1-1]1480 ept2 = cutv2[3][np.max([0,Ncuts2-1])] 1443 1481 ipt2 = cutv2[2][0] 1444 1482 1445 1483 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,:]) 1447 1485 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) 1450 1488 1451 1489 finalcutpolygon = np.array(finalcutpolygon) … … 3414 3452 buoydic = {'buoy': [buoy[0:N2,:],'-','#FFFF00',1.5], \ 3415 3453 '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]} 3418 3456 3419 3457 return buoy, buoysecs, buoydic … … 3566 3604 if drwxline: 3567 3605 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') 3569 3608 3570 3609 # y line … … 3572 3611 if drwyline: 3573 3612 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') 3575 3615 3576 3616 # z line … … 3578 3618 if drwzline: 3579 3619 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') 3581 3622 3582 3623 plt.legend() … … 3597 3638 pvals = secvals[0] 3598 3639 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]): 3601 3643 fillsec.append(pvals[ip,:]) 3602 #plt.fill(pvals[:,1], pvals[:,0], color=secvals[2])3644 # plt.fill(pvals[:,1], pvals[:,0], color=secvals[2]) 3603 3645 fillsec = np.array(fillsec) 3604 3646 plt.fill(fillsec[:,1], fillsec[:,0], color=secvals[2])
Note: See TracChangeset
for help on using the changeset viewer.