Changeset 2592 in lmdz_wrf
- Timestamp:
- Jun 4, 2019, 4:38:08 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2587 r2592 687 687 print ' ' + fname + ': no cutting for polygon at x=', xval, '!!' 688 688 else: 689 print ' ' + fname + ': found ', Ncuts, ' Ncuts' 690 print ' xval=', xval, 'cut, ip; ipt ep; ept ________' 691 for ic in range(Ncuts): 692 print ' ', ic, icut[ic], ';', ipt[ic], ecut[ic], ';', ept[ic] 689 ##print ' ' + fname + ': found ', Ncuts, ' Ncuts' 690 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, .... 693 newicut = icut + [] 694 newecut = ecut + [] 695 newipt = ipt + [] 696 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 706 ##print ' xval=', xval, 'cut, ip; ipt ep; ept ________' 707 ##for ic in range(Ncuts): 708 ## print ' ', ic, icut[ic], ';', ipt[ic], ecut[ic], ';', ept[ic] 693 709 694 710 # Length of joining lines 695 711 Nadds = [] 696 712 if Ncuts > 1: 697 Naddc = (Nadd-Ncuts)/(Ncuts -1)713 Naddc = (Nadd-Ncuts)/(Ncuts) 698 714 if Naddc < 3: 699 715 print errormsg … … 704 720 Nadds.append(Naddc) 705 721 706 Nadds.append(N -Naddc*(Ncuts-1))722 Nadds.append(Nadd-Naddc*(Ncuts-1)) 707 723 else: 708 724 Nadds.append(Nadd) … … 712 728 Ncpts = [] 713 729 for ic in range(Ncuts): 714 ip = ipt[ic] 715 if ic == 0: 716 dpts = ecut[ic] - icut[ic] + Nadds[ic] + icut[ic] 730 if keep == 'left': 731 if ic == 0: 732 dpts = icut[ic] + Nadds[ic] + (N - ecut[ic]) 733 else: 734 dpts = ecut[ic] - icut[ic] + Nadds[ic] - 1 735 736 # Adding end of the polygon in 'left' keeps 737 if ic == Ncuts - 1: dpts = dpts + N-ecut[ic] 717 738 else: 718 739 dpts = ecut[ic] - icut[ic] + Nadds[ic] - 1 719 740 720 # Adding end of the polygon in 'left' keeps721 if keep == 'left' and ic == Ncuts - 1: dpts = dpts + N-ecut[ic]722 Ncpts.append(dpts)723 741 Ntotpts = Ntotpts + dpts 724 725 cutpolygon = np.ones((Ntotpts+Ncuts-1,2), dtype=np.float)*gen.fillValue 726 727 iip = 0 742 Ncpts.append(ecut[ic] - icut[ic]) 743 744 cutpolygon = np.ones((Ntotpts+Ncuts,2), dtype=np.float)*gen.fillValue 745 728 746 iipc = 0 729 747 for ic in range(Ncuts): 730 Npts= Ncpts[ic]748 dcpt = Ncpts[ic] 731 749 if keep == 'left': 732 750 if ic == 0: 733 751 cutpolygon[0:icut[ic],:] = polygon[0:icut[ic],:] 734 iip = icut[ic]735 752 iipc = icut[ic] 736 dcpt = ecut[ic]-icut[ic]737 print ic, ':', 0, icut[ic], 'iipc:', iipc, 'dcpt', dcpt738 753 else: 739 dcpt = Ncpts[ic]-Nadds[ic] 740 print ic, 'dcpt:', dcpt, '<Ncpts>', Ncpts[ic], '<--', icut[ic]-1,ecut[ic]+1, '=', iipc+1, iipc+dcpt+1 741 cutpolygon[iipc+1:iipc+dcpt+1,:] = polygon[icut[ic]-1:ecut[ic]+1,:] 742 iipc = iipc + dcpt 754 cutpolygon[iipc:iipc+dcpt-1,:] = polygon[icut[ic]+1:ecut[ic],:] 755 iipc = iipc + dcpt -1 743 756 else: 744 757 cutpolygon[iipc,:] = ipt[ic] 745 cutpolygon[iipc +1:iipc+ecut[ic]-icut[ic],:]=polygon[icut[ic]+1:ecut[ic],:]746 iipc = iipc+ ecut[ic]-icut[ic]-1758 cutpolygon[iipc:iipc+dcpt-1,:]=polygon[icut[ic]+1:ecut[ic],:] 759 iipc = iipc+dcpt-1 747 760 748 761 # cutting line 749 762 cutline = np.zeros((Nadds[ic],2), dtype=np.float) 750 dx = (ept[ic][1] - ipt[ic][1])/(Nadds[ic]- 2)751 dy = (ept[ic][0] - ipt[ic][0])/(Nadds[ic]- 2)763 dx = (ept[ic][1] - ipt[ic][1])/(Nadds[ic]-1) 764 dy = (ept[ic][0] - ipt[ic][0])/(Nadds[ic]-1) 752 765 cutline[0,:] = ipt[ic] 753 766 for ip in range(1,Nadds[ic]-1): 754 767 cutline[ip,:] = ipt[ic] + np.array([dy*ip,dx*ip]) 755 cutline[Nadd -1,:] = ept[ic]768 cutline[Nadds[ic]-1,:] = ept[ic] 756 769 if keep == 'left': 757 cutpolygon[iipc:iipc+Nadds[ic],:] = cutline 758 # cutpolygon[iip+Nadd:Npts,:] = polygon[ecut+1:N,:] 770 if ic == 0: cutpolygon[iipc:iipc+Nadds[ic],:] = cutline 771 else: cutpolygon[iipc:iipc+Nadds[ic],:] = cutline[::-1] 772 iipc = iipc+Nadds[ic] 773 if ic == 0: 774 cutpolygon[iipc:iipc+N-ecut[ic]-1,:] = polygon[ecut[ic]+1:N,:] 775 iipc = iipc + N-ecut[ic]-1 776 cutpolygon[iipc,:] = polygon[0,:] 777 iipc = iipc + 1 759 778 else: 760 779 cutpolygon[iipc:iipc+Nadds[ic],:] = cutline[::-1,:] 780 iipc = iipc+Nadds[ic] 781 iipc = iipc + 1 761 782 762 783 rmpolygon = []
Note: See TracChangeset
for help on using the changeset viewer.