Changeset 2580 in lmdz_wrf
- Timestamp:
- Jun 2, 2019, 5:47:28 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2579 r2580 43 43 # spheric_line: Function to transform a series of locations in lon, lat coordinates 44 44 # to x,y,z over an 3D spaceFunction to provide coordinates of a line on a 3D space 45 # val_between: Function to provide if a given value is between two consecutive ones 45 46 # write_join_poly: Function to write an ASCII file with the combination of polygons 46 47 … … 435 436 return polys 436 437 438 def val_between(valA, valB, val): 439 """ Function to provide if a given value is between two consecutive ones 440 valA: first value 441 valB: second value 442 val: value to determine if it is between 443 >>> val_between(0.5,1.5,0.8) 444 True 445 >>> val_between(0.5,1.5.,-0.8) 446 False 447 >>> val_between(0.5,1.5,0.5) 448 True 449 """ 450 fname = 'val_between' 451 452 btw = False 453 if (valA <= val and valB > val) or (valA < val and valB >= val): btw =True 454 455 return btw 456 437 457 def cut_ypolygon(polygon, yval, keep='bottom', Nadd=20): 438 458 """ Function to cut a polygon from a given value of the y-axis … … 465 485 ept = [] 466 486 467 if type(polygon) == type(gen.mamat): 487 if type(polygon) == type(gen.mamat) and type(polygon.mask) != \ 488 type(gen.mamat.mask[1]): 468 489 # Assuming clockwise polygons 469 490 for ip in range(N-1): … … 472 493 if eep == N: eep = 0 473 494 474 if polygon[ip,0] <= yval and polygon[eep,0] >= yval:495 if val_between(polygon[ip,0], polygon[eep,0], yval): 475 496 icut.append(ip) 476 497 dx = polygon[eep,1] - polygon[ip,1] … … 485 506 dd = yval - polygon[ip,0] 486 507 ept.append([yval, polygon[ip,1]+dx*dd/dy]) 487 Ncuts = Nc tus + 1508 Ncuts = Ncuts + 1 488 509 else: 489 510 # Assuming clockwise polygons … … 505 526 dd = yval - polygon[ip,0] 506 527 ept.append([yval, polygon[ip,1]+dx*dd/dy]) 507 508 if ipt is None or ept is None: 528 Ncuts = Ncuts + 1 529 530 if ipt is None or ept is None or Ncuts == 0: 509 531 print errormsg 510 532 print ' ' + fname + ': no cutting for polygon at y=', yval, '!!' 533 else: 534 print ' ' + fname + ': found ', Ncuts, ' Ncuts' 535 print ' yval=', yval, 'cut, ip; ipt ep; ept ________' 536 for ic in range(Ncuts): 537 print ic, icut[ic], ';', ipt[ic], ecut[ic], ';', ept[ic] 511 538 512 539 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)) 540 if Ncuts > 1: 541 Naddc = Nadd/(Ncuts-1) 542 for ic in range(Ncuts-1): 543 Nadds.append(Naddc) 544 545 Nadds.append(N-Naddc*(Ncuts-1)) 546 else: 547 Nadds.append(Nadd) 518 548 519 549 iip = 0 … … 550 580 551 581 rmpolygon = [] 582 Npts = cutpolygon.shape[0] 552 583 if keep == 'bottom': 553 584 for ip in range(Npts):
Note: See TracChangeset
for help on using the changeset viewer.