Changeset 2586 in lmdz_wrf
- Timestamp:
- Jun 3, 2019, 12:20:31 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2585 r2586 43 43 # spheric_line: Function to transform a series of locations in lon, lat coordinates 44 44 # 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 ones45 # val_consec_between: Function to provide if a given value is between two consecutive ones 46 46 # write_join_poly: Function to write an ASCII file with the combination of polygons 47 47 … … 436 436 return polys 437 437 438 def val_ between(valA, valB, val):438 def val_consec_between(valA, valB, val): 439 439 """ Function to provide if a given value is between two consecutive ones 440 440 valA: first value 441 441 valB: second value 442 442 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) 444 444 True 445 >>> val_ between(0.5,1.5.,-0.8)445 >>> val_consec_between(0.5,1.5.,-0.8) 446 446 False 447 >>> val_ between(0.5,1.5,0.5)447 >>> val_consec_between(0.5,1.5,0.5) 448 448 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' 451 455 452 456 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 453 466 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 =True455 467 456 468 return btw … … 494 506 if eep == N: eep = 0 495 507 496 if val_ between(polygon[ip,0], polygon[eep,0], yval):508 if val_consec_between(polygon[ip,0], polygon[eep,0], yval): 497 509 icut.append(ip) 498 510 dx = polygon[eep,1] - polygon[ip,1] … … 501 513 ipt.append([yval, polygon[ip,1]+dx*dd/dy]) 502 514 503 if val_ between(polygon[ip,0], polygon[eep,0], yval):515 if val_consec_between(polygon[ip,0], polygon[eep,0], yval): 504 516 ecut.append(ip) 505 517 dx = polygon[eep,1] - polygon[ip,1] … … 514 526 if eep == N: eep = 0 515 527 516 if val_ between(polygon[ip,0], polygon[eep,0], yval):528 if val_consec_between(polygon[ip,0], polygon[eep,0], yval): 517 529 icut.append(ip) 518 530 dx = polygon[eep,1] - polygon[ip,1] … … 521 533 ipt.append([yval, polygon[ip,1]+dx*dd/dy]) 522 534 523 if val_ between(polygon[ip,0], polygon[eep,0], yval):535 if val_consec_between(polygon[ip,0], polygon[eep,0], yval): 524 536 ecut.append(ip) 525 537 dx = polygon[eep,1] - polygon[ip,1] … … 636 648 if eep == N: eep = 0 637 649 638 if val_ between(polygon[ip,1], polygon[eep,1], xval):650 if val_consec_between(polygon[ip,1], polygon[eep,1], xval): 639 651 icut.append(ip) 640 652 dx = polygon[eep,1] - polygon[ip,1] … … 643 655 ipt.append([polygon[ip,0]+dy*dd/dx, xval]) 644 656 645 if val_ between(polygon[ip,1], polygon[eep,1], xval):657 if val_consec_between(polygon[eep,1], polygon[ip,1], xval): 646 658 ecut.append(ip) 647 659 dx = polygon[eep,1] - polygon[ip,1] … … 656 668 if eep == N: eep = 0 657 669 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): 660 672 icut.append(ip) 661 673 dx = polygon[eep,1] - polygon[ip,1] … … 664 676 ipt.append([polygon[ip,0]+dy*dd/dx, xval]) 665 677 666 if val_ between(polygon[ip,1], polygon[eep,1], xval):678 if val_consec_between(polygon[eep,1], polygon[ip,1], xval): 667 679 ecut.append(ip) 668 680 dx = polygon[eep,1] - polygon[ip,1] … … 677 689 else: 678 690 print ' ' + fname + ': found ', Ncuts, ' Ncuts' 679 print ' yval=', xval, 'cut, ip; ipt ep; ept ________'691 print ' xval=', xval, 'cut, ip; ipt ep; ept ________' 680 692 for ic in range(Ncuts): 681 693 print ' ', ic, icut[ic], ';', ipt[ic], ecut[ic], ';', ept[ic] … … 703 715 ip = ipt[ic] 704 716 if ic == 0: 705 dpts = icut[ic] + ecut[ic] + Nadds[ic]717 dpts = ecut[ic] - icut[ic] + Nadds[ic] + icut[ic] 706 718 else: 707 719 dpts = ecut[ic] - icut[ic] + Nadds[ic] - 1 … … 712 724 Ntotpts = Ntotpts + dpts 713 725 714 cutpolygon = np.ones((Ntotpts ,2), dtype=np.float)*gen.fillValue726 cutpolygon = np.ones((Ntotpts+Ncuts-1,2), dtype=np.float)*gen.fillValue 715 727 716 728 iip = 0 … … 720 732 if keep == 'left': 721 733 if ic == 0: 722 cutpolygon[0:icut[ic] ] = polygon[0:icut[ic],:]734 cutpolygon[0:icut[ic],:] = polygon[0:icut[ic],:] 723 735 iip = icut[ic] 724 736 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,:] 727 743 iipc = iipc + dcpt 728 744 else:
Note: See TracChangeset
for help on using the changeset viewer.