Changeset 2547 in lmdz_wrf
- Timestamp:
- May 19, 2019, 4:46:20 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2546 r2547 23 23 24 24 ####### Contents: 25 # cut_ ypolygon: Function to cut a polygon from a given value of the y-axis25 # cut_[x/y]polygon: Function to cut a polygon from a given value of the [x/y]-axis 26 26 # deg_deci: Function to pass from degrees [deg, minute, sec] to decimal angles [rad] 27 27 # dist_points: Function to provide the distance between two points … … 448 448 if type(polygon) == type(gen.mamat): 449 449 # Assuming clockwise polygons 450 for ip in range(N ):450 for ip in range(N-1): 451 451 if not polygon.mask[ip,0]: 452 452 eep = ip + 1 … … 464 464 dx = polygon[eep,1] - polygon[ip,1] 465 465 dy = polygon[eep,0] - polygon[ip,0] 466 dd = yval - polygon[eep,0] 467 ept = [yval, polygon[eep,1]+dx*dd/dy] 466 dd = yval - polygon[ip,0] 467 print polygon[ip,:], ':', polygon[eep,:] 468 print 'dx', dx, 'dy', dy, 'dd', dd 469 ept = [yval, polygon[ip,1]+dx*dd/dy] 468 470 else: 469 471 # Assuming clockwise polygons 470 for ip in range(N ):472 for ip in range(N-1): 471 473 eep = ip + 1 472 474 if eep == N: eep = 0 … … 484 486 dy = polygon[eep,0] - polygon[ip,0] 485 487 dd = yval - polygon[ip,0] 488 print polygon[ip,:], ':', polygon[eep,:] 489 print 'dx', dx, 'dy', dy, 'dd', dd 486 490 ept = [yval, polygon[ip,1]+dx*dd/dy] 491 492 print 'Lluis ipt:', ipt, 'ept:', ept 487 493 488 494 if ipt is None or ept is None: 489 495 print errormsg 490 496 print ' ' + fname + ': no cutting for polygon at y=', yval, '!!' 497 498 if keep == 'bottom': 499 Npts = icut + (N-ecut) + Nadd 500 cutpolygon = np.zeros((Npts,2), dtype=np.float) 501 if type(polygon) == type(gen.mamat): 502 cutpolygon[0:icut+1,:] = polygon[0:icut+1,:].filled(gen.fillValueF) 503 else: 504 cutpolygon[0:icut+1,:] = polygon[0:icut+1,:] 505 iip = icut+1 506 else: 507 Npts = ecut - icut + Nadd-1 508 cutpolygon = np.zeros((Npts,2), dtype=np.float) 509 if type(polygon) == type(gen.mamat): 510 cutpolygon[0:ecut-icut-1,:] = polygon[icut+1:ecut,:].filled(gen.fillValueF) 511 else: 512 cutpolygon[0:ecut-icut-1,:] = polygon[icut+1:ecut,:] 513 iip = ecut-icut-1 514 515 # cutting line 516 cutline = np.zeros((Nadd,2), dtype=np.float) 517 dx = (ept[1] - ipt[1])/(Nadd-2) 518 dy = (ept[0] - ipt[0])/(Nadd-2) 519 cutline[0,:] = ipt 520 for ip in range(1,Nadd-1): 521 cutline[ip,:] = ipt + np.array([dy*ip,dx*ip]) 522 cutline[Nadd-1,:] = ept 523 cutpolygon[iip:iip+Nadd,:] = cutline 524 if keep == 'bottom': 525 if type(polygon) == type(gen.mamat): 526 cutpolygon[iip+Nadd:Npts,:] = polygon[ecut+1:N,:].filled(gen.fillValueF) 527 else: 528 cutpolygon[iip+Nadd:Npts,:] = polygon[ecut+1:N,:] 529 530 rmpolygon = [] 531 if keep == 'bottom': 532 for ip in range(N): 533 if polygon[ip,0] > yval: 534 rmpolygon.append([gen.fillValueF, gen.fillValueF]) 535 else: 536 rmpolygon.append(polygon[ip,:]) 537 else: 538 for ip in range(N): 539 if polygon[ip,0] < yval: 540 rmpolygon.append([gen.fillValueF, gen.fillValueF]) 541 else: 542 rmpolygon.append(polygon[ip,:]) 543 Npts = len(rmpolygon) 544 cutpolygon = np.array(rmpolygon) 545 546 cutpolygon = ma.masked_equal(cutpolygon, gen.fillValueF) 547 548 return Npts, cutpolygon 549 550 def cut_xpolygon(polygon, xval, keep='left', Nadd=20): 551 """ Function to cut a polygon from a given value of the x-axis 552 polygon: polygon to cut 553 xval: value to use to cut the polygon 554 keep: part to keep from the cut ('left', default) 555 'left': left from the cut 556 'right': right from the cut 557 Nadd: additional points to add to draw the line (20, default) 558 """ 559 fname = 'cut_xpolygon' 560 561 N = polygon.shape[0] 562 availkeeps = ['left', 'right'] 563 564 if not gen.searchInlist(availkeeps, keep): 565 print errormsg 566 print ' ' + fname + ": wring keep '" + keep + "' value !!" 567 print ' available ones:', availkeeps 568 quit(-1) 569 570 ipt = None 571 ept = None 572 573 if type(polygon) == type(gen.mamat): 574 # Assuming clockwise polygons 575 for ip in range(N): 576 if not polygon.mask[ip,0]: 577 eep = ip + 1 578 if eep == N: eep = 0 579 580 if polygon[ip,1] <= xval and polygon[eep,1] >= xval: 581 icut = ip 582 dx = polygon[eep,1] - polygon[ip,1] 583 dy = polygon[eep,0] - polygon[ip,0] 584 dd = xval - polygon[ip,1] 585 ipt = [ polygon[ip,0]+dy*dd/dx, xval] 586 587 if polygon[ip,1] >= xval and polygon[eep,1] <= xval: 588 ecut = ip 589 dx = polygon[eep,1] - polygon[ip,1] 590 dy = polygon[eep,0] - polygon[ip,0] 591 dd = xval - polygon[eep,1] 592 ept = [polygon[eep,0]+dy*dd/dx, xval] 593 else: 594 # Assuming clockwise polygons 595 for ip in range(N): 596 eep = ip + 1 597 if eep == N: eep = 0 598 599 if polygon[ip,1] <= xval and polygon[eep,1] >= xval: 600 icut = ip 601 dx = polygon[eep,1] - polygon[ip,1] 602 dy = polygon[eep,0] - polygon[ip,0] 603 dd = xval - polygon[ip,1] 604 ipt = [polygon[ip,0]+dy*dd/dx, xval] 605 606 if polygon[ip,1] >= xval and polygon[eep,1] <= xval: 607 ecut = ip 608 dx = polygon[eep,1] - polygon[ip,1] 609 dy = polygon[eep,0] - polygon[ip,0] 610 dd = xval - polygon[ip,1] 611 ept = [polygon[ip,0]+dy*dd/dx, xval] 612 613 if ipt is None or ept is None: 614 print errormsg 615 print ' ' + fname + ': no cutting for polygon at y=', xval, '!!' 491 616 irmv = 0 492 617 rmpolygon = [] 493 if keep == ' bottom':618 if keep == 'left': 494 619 for ip in range(N): 495 if polygon[ip, 0] > yval:620 if polygon[ip,1] > xval: 496 621 rmpolygon.append([gen.fillValueF, gen.fillValueF]) 497 622 else: … … 499 624 else: 500 625 for ip in range(N): 501 if polygon[ip,0] < yval:626 if polygon[ip,0] < xval: 502 627 rmpolygon.append([gen.fillValueF, gen.fillValueF]) 503 628 else: … … 507 632 cutpolygon = np.array(rmpolygon) 508 633 else: 509 if keep == ' bottom':634 if keep == 'left': 510 635 Npts = icut + (N-ecut) + Nadd 511 636 … … 535 660 cutline[Nadd-1,:] = ept 536 661 cutpolygon[iip:iip+Nadd,:] = cutline 537 if keep == ' bottom':662 if keep == 'left': 538 663 cutpolygon[iip+Nadd:Npts,:] = polygon[ecut+1:N,:] 539 664 … … 1567 1692 'sign2': [buoy[N2+N32+2:N,:],'-','k',1.5]} 1568 1693 1694 # painting it 1695 Height = height + 1.8*bradii 1696 # print 'Lluis Height', Height 1697 # Ncut, halfdown = cut_ypolygon(buoy, yval=Height/2., keep='bottom') 1698 # Ncut, halfup = cut_ypolygon(buoy, yval=Height/2., keep='above') 1699 1700 # buoysecs.append('halfk') 1701 # buoydic['halfk'] = [halfup, '-', 'k', 1.] 1702 # buoysecs.append('halfy') 1703 # buoydic['halfy'] = [halfdown, '-', '#FFFF00', 1.] 1704 1569 1705 return buoy, buoysecs, buoydic 1570 1706
Note: See TracChangeset
for help on using the changeset viewer.