Changeset 2581 in lmdz_wrf
- Timestamp:
- Jun 2, 2019, 5:50:24 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2580 r2581 455 455 return btw 456 456 457 def cut_ypolygon(polygon, yval, keep='b ottom', Nadd=20):457 def cut_ypolygon(polygon, yval, keep='below', Nadd=20): 458 458 """ Function to cut a polygon from a given value of the y-axis 459 459 polygon: polygon to cut 460 460 yval: value to use to cut the polygon 461 keep: part to keep from the height ('b ottom', default)462 'b ottom': below the height461 keep: part to keep from the height ('below', default) 462 'below': below the height 463 463 'above': above the height 464 464 Nadd: additional points to add to draw the line (20, default) … … 467 467 468 468 N = polygon.shape[0] 469 availkeeps = ['b ottom', 'above']469 availkeeps = ['below', 'above'] 470 470 471 471 if not gen.searchInlist(availkeeps, keep): … … 500 500 ipt.append([yval, polygon[ip,1]+dx*dd/dy]) 501 501 502 if polygon[ip,0] >= yval and polygon[eep,0] <= yval:502 if val_between(polygon[ip,0], polygon[eep,0], yval): 503 503 ecut.append(ip) 504 504 dx = polygon[eep,1] - polygon[ip,1] … … 513 513 if eep == N: eep = 0 514 514 515 if polygon[ip,0] <= yval and polygon[eep,0] >= yval:515 if val_between(polygon[ip,0], polygon[eep,0], yval): 516 516 icut.append(ip) 517 517 dx = polygon[eep,1] - polygon[ip,1] … … 520 520 ipt.append([yval, polygon[ip,1]+dx*dd/dy]) 521 521 522 if polygon[ip,0] >= yval and polygon[eep,0] <= yval:522 if val_between(polygon[ip,0], polygon[eep,0], yval): 523 523 ecut.append(ip) 524 524 dx = polygon[eep,1] - polygon[ip,1] … … 535 535 print ' yval=', yval, 'cut, ip; ipt ep; ept ________' 536 536 for ic in range(Ncuts): 537 print ic, icut[ic], ';', ipt[ic], ecut[ic], ';', ept[ic]537 print ' ', ic, icut[ic], ';', ipt[ic], ecut[ic], ';', ept[ic] 538 538 539 539 Nadds = [] … … 550 550 iipc = 0 551 551 for ic in range(Ncuts): 552 if keep == 'b ottom':552 if keep == 'below': 553 553 Npts = icut[ic] + (N-ecut[ic]) + Nadds[ic] 554 554 cutpolygon = np.zeros((Npts,2), dtype=np.float) … … 573 573 cutline[ip,:] = ipt[ic] + np.array([dy*ip,dx*ip]) 574 574 cutline[Nadds[ic]-1,:] = ept[ic] 575 if keep == 'b ottom':575 if keep == 'below': 576 576 cutpolygon[iip:iip+Nadds[ic],:] = cutline 577 577 cutpolygon[iip+Nadds[ic]:Npts,:] = polygon[ecut[ic]+1:N,:] … … 581 581 rmpolygon = [] 582 582 Npts = cutpolygon.shape[0] 583 if keep == 'b ottom':583 if keep == 'below': 584 584 for ip in range(Npts): 585 585 if cutpolygon[ip,0] > yval: … … 2160 2160 Height = np.max(buoy1v[:,0]) 2161 2161 2162 Ncut, halfdown = cut_ypolygon(buoy1v, yval=Height/2., keep='b ottom')2162 Ncut, halfdown = cut_ypolygon(buoy1v, yval=Height/2., keep='below') 2163 2163 Ncut, halfup = cut_ypolygon(buoy1v, yval=Height/2., keep='above') 2164 2164 … … 2215 2215 Height = np.max(buoy1v[:,0]) 2216 2216 2217 Ncut, halfdown = cut_ypolygon(buoy1v, yval=Height/3., keep='b ottom')2217 Ncut, halfdown = cut_ypolygon(buoy1v, yval=Height/3., keep='below') 2218 2218 Ncut, halfbtw = cut_between_ypolygon(buoy1v, yval1=Height/3., yval2=Height*2./3.) 2219 2219 Ncut, halfup = cut_ypolygon(buoy1v, yval=Height*2./3., keep='above') … … 2272 2272 Height = np.max(buoy1v[:,0]) 2273 2273 2274 Ncut, halfdown = cut_ypolygon(buoy1v, yval=Height/2., keep='b ottom')2274 Ncut, halfdown = cut_ypolygon(buoy1v, yval=Height/2., keep='below') 2275 2275 Ncut, halfup = cut_ypolygon(buoy1v, yval=Height/2., keep='above') 2276 2276 … … 2327 2327 Height = np.max(buoy1v[:,0]) 2328 2328 2329 Ncut, halfdown = cut_ypolygon(buoy1v, yval=Height/3., keep='b ottom')2329 Ncut, halfdown = cut_ypolygon(buoy1v, yval=Height/3., keep='below') 2330 2330 Ncut, halfbtw1 = cut_between_ypolygon(buoy1v, yval1=Height/3., yval2=Height*2./3.) 2331 2331 Ncut, halfup = cut_ypolygon(buoy1v, yval=Height*2./3., keep='above') … … 2493 2493 2494 2494 # painting it 2495 Ncut, third1 = cut_ypolygon(buoy1v, yval=Height/3., keep='b ottom')2495 Ncut, third1 = cut_ypolygon(buoy1v, yval=Height/3., keep='below') 2496 2496 Ncut, third2 = cut_between_ypolygon(buoy1v, yval1=Height/3., yval2=Height*2./3.) 2497 2497 Ncut, third3 = cut_ypolygon(buoy1v, yval=Height*2./3., keep='above') … … 2537 2537 2538 2538 # painting it 2539 Ncut, third1 = cut_ypolygon(buoy1v, yval=Height/3., keep='b ottom')2539 Ncut, third1 = cut_ypolygon(buoy1v, yval=Height/3., keep='below') 2540 2540 Ncut, third2 = cut_between_ypolygon(buoy1v, yval1=Height/3., yval2=Height*2./3.) 2541 2541 Ncut, third3 = cut_ypolygon(buoy1v, yval=Height*2./3., keep='above') … … 2581 2581 # painting it 2582 2582 # painting it 2583 Ncut, third1 = cut_ypolygon(buoy1v, yval=Height/3., keep='b ottom')2583 Ncut, third1 = cut_ypolygon(buoy1v, yval=Height/3., keep='below') 2584 2584 Ncut, third2 = cut_between_ypolygon(buoy1v, yval1=Height/3., yval2=Height*2./3.) 2585 2585 Ncut, third3 = cut_ypolygon(buoy1v, yval=Height*2./3., keep='above') … … 2625 2625 # painting it 2626 2626 # painting it 2627 Ncut, third1 = cut_ypolygon(buoy1v, yval=Height/3., keep='b ottom')2627 Ncut, third1 = cut_ypolygon(buoy1v, yval=Height/3., keep='below') 2628 2628 Ncut, third2 = cut_between_ypolygon(buoy1v, yval1=Height/3., yval2=Height*2./3.) 2629 2629 Ncut, third3 = cut_ypolygon(buoy1v, yval=Height*2./3., keep='above') … … 2680 2680 Height = np.max(buoy1v[:,0]) 2681 2681 2682 Ncut, third1 = cut_ypolygon(buoy1v, yval=Height/3., keep='b ottom')2682 Ncut, third1 = cut_ypolygon(buoy1v, yval=Height/3., keep='below') 2683 2683 Ncut, third2 = cut_between_ypolygon(buoy1v, yval1=Height/3., yval2=Height*2./3.) 2684 2684 Ncut, third3 = cut_ypolygon(buoy1v, yval=Height*2./3., keep='above')
Note: See TracChangeset
for help on using the changeset viewer.