Changeset 2579 in lmdz_wrf
- Timestamp:
- Jun 2, 2019, 5:32:08 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2578 r2579 458 458 ept = None 459 459 460 # There might be more than 1 cut... 461 Ncuts = 0 462 icut = [] 463 ecut = [] 464 ipt = [] 465 ept = [] 466 460 467 if type(polygon) == type(gen.mamat): 461 468 # Assuming clockwise polygons … … 466 473 467 474 if polygon[ip,0] <= yval and polygon[eep,0] >= yval: 468 icut = ip475 icut.append(ip) 469 476 dx = polygon[eep,1] - polygon[ip,1] 470 477 dy = polygon[eep,0] - polygon[ip,0] 471 478 dd = yval - polygon[ip,0] 472 ipt = [yval, polygon[ip,1]+dx*dd/dy]479 ipt.append([yval, polygon[ip,1]+dx*dd/dy]) 473 480 474 481 if polygon[ip,0] >= yval and polygon[eep,0] <= yval: 475 ecut = ip482 ecut.append(ip) 476 483 dx = polygon[eep,1] - polygon[ip,1] 477 484 dy = polygon[eep,0] - polygon[ip,0] 478 485 dd = yval - polygon[ip,0] 479 ept = [yval, polygon[ip,1]+dx*dd/dy] 486 ept.append([yval, polygon[ip,1]+dx*dd/dy]) 487 Ncuts = Nctus + 1 480 488 else: 481 489 # Assuming clockwise polygons … … 485 493 486 494 if polygon[ip,0] <= yval and polygon[eep,0] >= yval: 487 icut = ip495 icut.append(ip) 488 496 dx = polygon[eep,1] - polygon[ip,1] 489 497 dy = polygon[eep,0] - polygon[ip,0] 490 498 dd = yval - polygon[ip,0] 491 ipt = [yval, polygon[ip,1]+dx*dd/dy]499 ipt.append([yval, polygon[ip,1]+dx*dd/dy]) 492 500 493 501 if polygon[ip,0] >= yval and polygon[eep,0] <= yval: 494 ecut = ip502 ecut.append(ip) 495 503 dx = polygon[eep,1] - polygon[ip,1] 496 504 dy = polygon[eep,0] - polygon[ip,0] 497 505 dd = yval - polygon[ip,0] 498 ept = [yval, polygon[ip,1]+dx*dd/dy]506 ept.append([yval, polygon[ip,1]+dx*dd/dy]) 499 507 500 508 if ipt is None or ept is None: … … 502 510 print ' ' + fname + ': no cutting for polygon at y=', yval, '!!' 503 511 504 if keep == 'bottom': 505 Npts = icut + (N-ecut) + Nadd 506 cutpolygon = np.zeros((Npts,2), dtype=np.float) 507 if type(polygon) == type(gen.mamat): 508 cutpolygon[0:icut+1,:] = polygon[0:icut+1,:] 512 Nadds = [] 513 Naddc = Nadd/(Ncuts-1) 514 for ic in range(Ncuts-1): 515 Nadds.append(Naddc) 516 517 Nadds.append(N-Naddc*(Ncuts-1)) 518 519 iip = 0 520 iipc = 0 521 for ic in range(Ncuts): 522 if keep == 'bottom': 523 Npts = icut[ic] + (N-ecut[ic]) + Nadds[ic] 524 cutpolygon = np.zeros((Npts,2), dtype=np.float) 525 if type(polygon) == type(gen.mamat): 526 cutpolygon[iipc:icut[ic]+1,:] = polygon[iip:icut[ic]+1,:] 527 else: 528 cutpolygon[iipc:icut[ic]+1,:] = polygon[iip:icut[ic]+1,:] 529 iip = icut[ic]+1 509 530 else: 510 cutpolygon[0:icut+1,:] = polygon[0:icut+1,:] 511 iip = icut+1 512 else: 513 Npts = ecut - icut + Nadd-1 514 cutpolygon = np.zeros((Npts,2), dtype=np.float) 515 cutpolygon[0,:] = ipt 516 cutpolygon[1:ecut-icut,:] = polygon[icut+1:ecut,:] 517 iip = ecut-icut-1 518 519 # cutting line 520 cutline = np.zeros((Nadd,2), dtype=np.float) 521 dx = (ept[1] - ipt[1])/(Nadd-2) 522 dy = (ept[0] - ipt[0])/(Nadd-2) 523 cutline[0,:] = ipt 524 for ip in range(1,Nadd-1): 525 cutline[ip,:] = ipt + np.array([dy*ip,dx*ip]) 526 cutline[Nadd-1,:] = ept 527 if keep == 'bottom': 528 cutpolygon[iip:iip+Nadd,:] = cutline 529 if type(polygon) == type(gen.mamat): 530 cutpolygon[iip+Nadd:Npts,:] = polygon[ecut+1:N,:] 531 Npts = ecut[ec] - icut[ic] + Nadds[ic]-1 532 cutpolygon = np.zeros((Npts,2), dtype=np.float) 533 cutpolygon[iipc,:] = ipt[ic] 534 cutpolygon[iipc+1:ecut[ic]-icut[ic],:] = polygon[icut[ic]+1:ecut[ic],:] 535 iip = ecut[ic]-icut[ic]-1 536 537 # cutting line 538 cutline = np.zeros((Nadds[ic],2), dtype=np.float) 539 dx = (ept[ic][1] - ipt[ic][1])/(Nadds[ic]-2) 540 dy = (ept[ic][0] - ipt[ic][0])/(Nadds[ic]-2) 541 cutline[0,:] = ipt[ic] 542 for ip in range(1,Nadds[ic]-1): 543 cutline[ip,:] = ipt[ic] + np.array([dy*ip,dx*ip]) 544 cutline[Nadds[ic]-1,:] = ept[ic] 545 if keep == 'bottom': 546 cutpolygon[iip:iip+Nadds[ic],:] = cutline 547 cutpolygon[iip+Nadds[ic]:Npts,:] = polygon[ecut[ic]+1:N,:] 531 548 else: 532 cutpolygon[iip+Nadd:Npts,:] = polygon[ecut+1:N,:] 533 else: 534 cutpolygon[iip:iip+Nadd,:] = cutline[::-1,:] 549 cutpolygon[iip:iip+Nadds[ic],:] = cutline[::-1,:] 535 550 536 551 rmpolygon = [] … … 577 592 ept = None 578 593 579 if type(polygon) == type(gen.mamat): 594 if type(polygon) == type(gen.mamat) and type(polygon.mask) != \ 595 type(gen.mamat.mask[1]): 580 596 # Assuming clockwise polygons 581 597 for ip in range(N-1): 582 if not polygon.mask[ip, 0]:598 if not polygon.mask[ip,1]: 583 599 eep = ip + 1 584 600 if eep == N: eep = 0 … … 619 635 if ipt is None or ept is None: 620 636 print errormsg 621 print ' ' + fname + ': no cutting for polygon at y=', yval, '!!'637 print ' ' + fname + ': no cutting for polygon at x=', xval, '!!' 622 638 623 639 if keep == 'left':
Note: See TracChangeset
for help on using the changeset viewer.