Changeset 2597 in lmdz_wrf
- Timestamp:
- Jun 7, 2019, 6:44:13 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2592 r2597 513 513 ipt.append([yval, polygon[ip,1]+dx*dd/dy]) 514 514 515 if val_consec_between(polygon[ ip,0], polygon[eep,0], yval):515 if val_consec_between(polygon[eep,0], polygon[ip,0], yval): 516 516 ecut.append(ip) 517 517 dx = polygon[eep,1] - polygon[ip,1] … … 533 533 ipt.append([yval, polygon[ip,1]+dx*dd/dy]) 534 534 535 if val_consec_between(polygon[ ip,0], polygon[eep,0], yval):535 if val_consec_between(polygon[eep,0], polygon[ip,0], yval): 536 536 ecut.append(ip) 537 537 dx = polygon[eep,1] - polygon[ip,1] … … 541 541 Ncuts = Ncuts + 1 542 542 543 # Looking for repeated 544 newicut = icut + [] 545 newecut = ecut + [] 546 newipt = ipt + [] 547 newept = ept + [] 548 newNcuts = Ncuts 549 for ic in range(newNcuts-1): 550 for ic2 in range(ic+1,newNcuts): 551 if newipt[ic] == newipt[ic2]: 552 Ncuts = Ncuts-1 553 icut.pop(ic2) 554 ecut.pop(ic2) 555 ipt.pop(ic2) 556 ept.pop(ic2) 557 newNcuts = Ncuts + 0 558 543 559 if ipt is None or ept is None or Ncuts == 0: 544 560 print errormsg … … 546 562 else: 547 563 print ' ' + fname + ': found ', Ncuts, ' Ncuts' 548 print ' yval=', yval, 'cut, ip; ipt ep; ept ________' 549 for ic in range(Ncuts): 550 print ' ', ic, icut[ic], ';', ipt[ic], ecut[ic], ';', ept[ic] 551 564 if Ncuts > 1 and keep == 'below': 565 # Re-shifting cuts by closest distance. 566 xis = [] 567 xes = [] 568 for ic in range(Ncuts): 569 xp = ipt[ic] 570 xis.append(xp[1]) 571 xp = ept[ic] 572 xes.append(xp[1]) 573 xs = xis + xes 574 xs.sort() 575 newicut = icut + [] 576 newecut = ecut + [] 577 newipt = ipt + [] 578 newept = ept + [] 579 icut = [] 580 ecut = [] 581 ipt = [] 582 ept = [] 583 for xv in xs: 584 ic = xis.count(xv) 585 if ic != 0: 586 icc = xis.index(xv) 587 if len(icut) > len(ecut): 588 ecut.append(newicut[icc]) 589 ept.append(newipt[icc]) 590 else: 591 icut.append(newicut[icc]) 592 ipt.append(newipt[icc]) 593 else: 594 icc = xes.index(xv) 595 if len(icut) > len(ecut): 596 ecut.append(newecut[icc]) 597 ept.append(newept[icc]) 598 else: 599 icut.append(newecut[icc]) 600 ipt.append(newept[icc]) 601 602 # # Re-shifting cuts. 1st icut --> last ecut; 1st ecut as 1st icut; 603 # # 2nd icut --> last-1 ecut, .... 604 # newicut = icut + [] 605 # newecut = ecut + [] 606 # newipt = ipt + [] 607 # newept = ept + [] 608 # for ic in range(Ncuts-1): 609 # ecut[ic] = newecut[Ncuts-ic-1] 610 # ept[ic] = newept[Ncuts-ic-1] 611 # icut[ic+1] = newecut[ic] 612 # ipt[ic+1] = newept[ic] 613 614 # ecut[Ncuts-1] = newicut[Ncuts-1] 615 # ept[Ncuts-1] = newipt[Ncuts-1] 616 617 ## print ' yval=', yval, 'cut, ip; ipt ep; ept ________' 618 ## for ic in range(Ncuts): 619 ## print ' ', ic, icut[ic], ';', ipt[ic], ecut[ic], ';', ept[ic] 620 621 # Length of joining lines 552 622 Nadds = [] 553 623 if Ncuts > 1: 554 Naddc = Nadd/(Ncuts-1) 624 Naddc = (Nadd-Ncuts)/(Ncuts) 625 if Naddc < 3: 626 print errormsg 627 print ' ' + fname + ': too few points for jioning lines !!' 628 print ' increase Nadd at least to:', Ncuts*3+Ncuts 629 quit(-1) 555 630 for ic in range(Ncuts-1): 556 631 Nadds.append(Naddc) 557 632 558 Nadds.append(N -Naddc*(Ncuts-1))633 Nadds.append(Nadd-Naddc*(Ncuts-1)) 559 634 else: 560 635 Nadds.append(Nadd) 561 636 562 iip = 0 637 # Total points cut polygon 638 Ntotpts = 0 639 Ncpts = [] 640 for ic in range(Ncuts): 641 if keep == 'below': 642 if ic == 0: 643 dpts = icut[ic] + Nadds[ic] + (N - ecut[ic]) 644 else: 645 dpts = ecut[ic] - icut[ic] + Nadds[ic] - 1 646 647 # Adding end of the polygon in 'left' keeps 648 if ic == Ncuts - 1: dpts = dpts + N-ecut[ic] 649 else: 650 dpts = ecut[ic] - icut[ic] + Nadds[ic] - 1 651 652 Ntotpts = Ntotpts + dpts 653 Ncpts.append(ecut[ic] - icut[ic]) 654 655 cutpolygon = np.ones((Ntotpts+Ncuts,2), dtype=np.float)*gen.fillValue 656 563 657 iipc = 0 564 658 for ic in range(Ncuts): 659 dcpt = Ncpts[ic] 565 660 if keep == 'below': 566 Npts = icut[ic] + (N-ecut[ic]) + Nadds[ic] 567 cutpolygon = np.zeros((Npts,2), dtype=np.float) 568 cutpolygon[iipc:iipc+icut[ic]+1,:] = polygon[iip:iip+icut[ic]+1,:] 569 iip = iip+icut[ic]+1 570 iipc = iipc+icut[ic]+1 661 if ic == 0: 662 cutpolygon[0:icut[ic],:] = polygon[0:icut[ic],:] 663 iipc = icut[ic] 664 else: 665 cutpolygon[iipc:iipc+dcpt-1,:] = polygon[icut[ic]+1:ecut[ic],:] 666 iipc = iipc + dcpt -1 571 667 else: 572 Npts = ecut[ec] - icut[ic] + Nadds[ic]-1573 cutpolygon = np.zeros((Npts,2), dtype=np.float)574 668 cutpolygon[iipc,:] = ipt[ic] 575 cutpolygon[iipc+1:ecut[ic]-icut[ic],:] = polygon[icut[ic]+1:ecut[ic],:] 576 iip = ecut[ic]-icut[ic]-1 577 iipc = iipc + ecut[ic]-icut[ic]-1 669 cutpolygon[iipc:iipc+dcpt-1,:]=polygon[icut[ic]+1:ecut[ic],:] 670 iipc = iipc+dcpt-1 578 671 579 672 # cutting line 580 673 cutline = np.zeros((Nadds[ic],2), dtype=np.float) 581 dx = (ept[ic][1] - ipt[ic][1])/(Nadds[ic]- 2)582 dy = (ept[ic][0] - ipt[ic][0])/(Nadds[ic]- 2)674 dx = (ept[ic][1] - ipt[ic][1])/(Nadds[ic]-1) 675 dy = (ept[ic][0] - ipt[ic][0])/(Nadds[ic]-1) 583 676 cutline[0,:] = ipt[ic] 584 677 for ip in range(1,Nadds[ic]-1): … … 586 679 cutline[Nadds[ic]-1,:] = ept[ic] 587 680 if keep == 'below': 588 cutpolygon[iip:iip+Nadds[ic],:] = cutline 589 cutpolygon[iip+Nadds[ic]:Npts,:] = polygon[ecut[ic]+1:N,:] 681 if ic == 0: cutpolygon[iipc:iipc+Nadds[ic],:] = cutline 682 else: cutpolygon[iipc:iipc+Nadds[ic],:] = cutline[::-1,:] 683 iipc = iipc+Nadds[ic] 684 if ic == 0: 685 cutpolygon[iipc:iipc+N-ecut[ic]-1,:] = polygon[ecut[ic]+1:N,:] 686 iipc = iipc + N-ecut[ic]-1 687 cutpolygon[iipc,:] = polygon[0,:] 688 iipc = iipc + 1 590 689 else: 591 cutpolygon[iip:iip+Nadds[ic],:] = cutline[::-1,:] 690 cutpolygon[iipc:iipc+Nadds[ic],:] = cutline[::-1,:] 691 iipc = iipc+Nadds[ic] 692 iipc = iipc + 1 592 693 593 694 rmpolygon = [] … … 635 736 ept = None 636 737 738 # There might be more than 1 cut ... 637 739 icut = [] 638 740 ecut = [] … … 683 785 Ncuts = Ncuts + 1 684 786 787 # Looking for repeated 788 newicut = icut + [] 789 newecut = ecut + [] 790 newipt = ipt + [] 791 newept = ept + [] 792 newNcuts = Ncuts 793 for ic in range(newNcuts-1): 794 for ic2 in range(ic+1,newNcuts): 795 if newipt[ic] == newipt[ic2]: 796 Ncuts = Ncuts-1 797 icut.pop(ic2) 798 ecut.pop(ic2) 799 ipt.pop(ic2) 800 ept.pop(ic2) 801 newNcuts = Ncuts + 0 802 685 803 if ipt is None or ept is None or Ncuts == 0: 686 804 print errormsg … … 689 807 ##print ' ' + fname + ': found ', Ncuts, ' Ncuts' 690 808 if Ncuts > 1 and keep == 'left': 691 # Re-shifting cuts. 1st icut --> last ecut; 1st ecut as 1st icut; 692 # 2nd icut --> last-1 ecut, .... 809 # Re-shifting cuts by closest heigth. 810 yis = [] 811 yes = [] 812 for ic in range(Ncuts): 813 yp = ipt[ic] 814 yis.append(yp[0]) 815 yp = ept[ic] 816 yes.append(yp[0]) 817 ys = yis + yes 818 ys.sort() 693 819 newicut = icut + [] 694 820 newecut = ecut + [] 695 821 newipt = ipt + [] 696 822 newept = ept + [] 697 for ic in range(Ncuts-1): 698 ecut[ic] = newecut[Ncuts-ic-1] 699 ept[ic] = newept[Ncuts-ic-1] 700 icut[ic+1] = newecut[ic] 701 ipt[ic+1] = newept[ic] 702 703 ecut[Ncuts-1] = newicut[Ncuts-1] 704 ept[Ncuts-1] = newipt[Ncuts-1] 705 823 icut = [] 824 ecut = [] 825 ipt = [] 826 ept = [] 827 for yv in ys: 828 ic = yis.count(yv) 829 if ic != 0: 830 icc = yis.index(yv) 831 if len(icut) > len(ecut): 832 ecut.append(newicut[icc]) 833 ept.append(newipt[icc]) 834 else: 835 icut.append(newicut[icc]) 836 ipt.append(newipt[icc]) 837 else: 838 icc = yes.index(yv) 839 if len(icut) > len(ecut): 840 ecut.append(newecut[icc]) 841 ept.append(newept[icc]) 842 else: 843 icut.append(newecut[icc]) 844 ipt.append(newept[icc]) 706 845 ##print ' xval=', xval, 'cut, ip; ipt ep; ept ________' 707 846 ##for ic in range(Ncuts):
Note: See TracChangeset
for help on using the changeset viewer.