Changeset 2628 in lmdz_wrf
- Timestamp:
- Jun 23, 2019, 9:08:30 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2627 r2628 547 547 prevpt = polygon[0,:] 548 548 newpolygon.append(prevpt) 549 for ip in range(1,polygon.shape[0] -1):549 for ip in range(1,polygon.shape[0]): 550 550 if polygon[ip,0] != prevpt[0] or polygon[ip,1] != prevpt[1]: 551 551 prevpt = polygon[ip,:] … … 1567 1567 >>> plgs = {'sqra': polya, 'sqrb': polyb} 1568 1568 >>> pile_polygons(pns, plgs) 1569 # sqrb : 1570 [[-0.75 -0.5] 1571 [-0.5 -0.5] 1572 [-- --] 1573 [0.5 -0.5] 1574 [0.75 -0.5] 1575 [0.75 -0.5] 1576 [0.75 0.5] 1577 [0.5 0.5] 1578 [-- --] 1579 [-0.5 0.5] 1580 [-0.75 0.5] 1581 [-0.75 0.5] 1582 [-0.75 -0.5]] 1583 # sqra : [[-0.5 -0.75] 1584 [ 0.5 -0.75] 1585 [ 0.5 0.75] 1586 [-0.5 0.75] 1587 [-0.5 -0.75]] 1588 1589 1569 1590 [[-0.75 -0.5 ] 1570 1591 [ 0.75 -0.5 ] … … 1574 1595 fname = 'pile_polygons' 1575 1596 pilepolygons = dict(polygons) 1576 1577 1597 Npolys = len(polyns) 1578 ipoly = polygons[polyns[Npolys-1]] 1579 iNpts = ipoly.shape[0] 1580 1581 pilesortpolys = polyns[::-1] 1582 pilesortpolys.remove(polyns[Npolys-1]) 1583 newipoly = [] 1584 for polyn in pilesortpolys: 1585 poly = polygons[polyn] 1598 1599 for ipolyp in range(Npolys-2,-1,-1): 1600 polyn = polyns[ipolyp] 1601 poly = pilepolygons[polyn] 1586 1602 Npts = poly.shape[0] 1587 Nint, inti, intp, pts = fsci.module_scientific.crossingpoints_polys( \ 1588 nvertexa=iNpts, nvertexb=Npts, nvertexab=iNpts*Npts, polya=ipoly, \ 1589 polyb=poly) 1590 # We're in C-mode ! 1591 inti = inti-1 1592 intp = intp-1 1593 1594 # Re-constructing below polygon looking for respective crossings 1595 linti = list(inti) 1596 for ip in range(iNpts): 1597 iip1 = ip+1 1598 if ip == iNpts-1: iip1 = 0 1599 print ip, ipoly[ip,:], ':', ipoly[iip1,:] 1600 Nc = linti.count(ip) 1601 ldists = [] 1602 ddists = {} 1603 if Nc > 0: 1604 iic = gen.multi_index_vec(inti,ip) 1605 mindist = 1000000. 1606 # Sorting from distance respect the vertex ip 1607 for ic in range(Nc): 1608 ddists[iic[ic]] = dist_points(ipoly[ip,:], pts[iic[ic],:]) 1609 ldists.append(ddists[iic[ic]]) 1610 print ' ', ic, ';', iic[ic], '=', pts[iic[ic],:], ddists[iic[ic]] 1611 ldists.sort() 1612 print ' ldists', ldists 1613 newipoly.append(ipoly[ip,:]) 1614 for ic in range(Nc): 1615 iic = gen.dictionary_key(ddists,ldists[ic]) 1616 newipoly.append(pts[iic,:]) 1617 print ' ', ic, '|', iic, ';', pts[iic,:] 1618 if ic < Nc-1: newipoly.append([gen.fillValueF, gen.fillValueF]) 1619 newipoly.append(ipoly[iip1,:]) 1620 1621 else: 1622 newipoly.append(ipoly[ip,:]) 1603 for ipolyi in range(ipolyp+1,Npolys,1): 1604 ipolyn = polyns[ipolyi] 1605 #print ' Lluis ' + polyn + ' above ' + ipolyn 1606 ipoly = pilepolygons[ipolyn] 1607 iNpts = ipoly.shape[0] 1608 newipoly = [] 1609 1610 Nint, inti, intp, pts = fsci.module_scientific.crossingpoints_polys( \ 1611 nvertexa=iNpts, nvertexb=Npts, nvertexab=iNpts*Npts, polya=ipoly, \ 1612 polyb=poly) 1613 # We're in C-mode ! 1614 inti = inti-1 1615 intp = intp-1 1616 1617 # Re-constructing below polygon looking for respective crossings 1618 linti = list(inti) 1619 for ip in range(iNpts): 1620 iip1 = ip+1 1621 if ip == iNpts-1: iip1 = 0 1622 #print ip, ipoly[ip,:], ':', ipoly[iip1,:] 1623 Nc = linti.count(ip) 1624 ldists = [] 1625 ddists = {} 1626 if Nc > 0: 1627 iic = gen.multi_index_vec(inti,ip) 1628 mindist = 1000000. 1629 # Sorting from distance respect the vertex ip 1630 for ic in range(Nc): 1631 ddists[iic[ic]] = dist_points(ipoly[ip,:], pts[iic[ic],:]) 1632 ldists.append(ddists[iic[ic]]) 1633 #print ' ', ic, ';', iic[ic], '=', pts[iic[ic],:], ddists[iic[ic]] 1634 ldists.sort() 1635 #print ' ldists', ldists 1636 newipoly.append(ipoly[ip,:]) 1637 for ic in range(Nc): 1638 iic = gen.dictionary_key(ddists,ldists[ic]) 1639 newipoly.append(pts[iic,:]) 1640 #print ' ', ic, '|', iic, ';', pts[iic,:] 1641 if ic < Nc-1: newipoly.append([gen.fillValueF, gen.fillValueF]) 1642 newipoly.append(ipoly[iip1,:]) 1643 1644 else: 1645 newipoly.append(ipoly[ip,:]) 1623 1646 1624 pilepolygons[polyns[Npolys-1]] = newipoly 1647 newipoly = np.array(newipoly) 1648 pilepolygons[polyns[Npolys-1]] = rm_consecpt_polygon(newipoly) 1625 1649 1626 for polyn in polyns:1627 poly = pilepolygons[polyn]1628 poly = ma.masked_equal(poly, gen.fillValueF)1629 pilepolygons[polyn] = poly1650 for polyn in polyns: 1651 poly = pilepolygons[polyn] 1652 poly = ma.masked_equal(poly, gen.fillValueF) 1653 pilepolygons[polyn] = poly 1630 1654 1631 1655 return pilepolygons
Note: See TracChangeset
for help on using the changeset viewer.