30
30
from numpy import empty , array , concatenate , ma , zeros , unique , round , ones , int_
31
31
from matplotlib .figure import Figure
32
32
from numba import njit , types as numba_types
33
+ from .poly import winding_number_poly
33
34
34
35
35
36
class Amplitude (object ):
@@ -488,19 +489,58 @@ def get_index_nearest_path_bbox_contain_pt(self, level, xpt, ypt):
488
489
else :
489
490
return self .contours .collections [level ]._paths [index ]
490
491
491
- def display (self , ax , step = 1 , ** kwargs ):
492
+ def display (self , ax , step = 1 , only_used = False , only_unused = False , only_contain_eddies = False , ** kwargs ):
492
493
from matplotlib .collections import LineCollection
493
494
for collection in self .contours .collections [::step ]:
494
- ax .add_collection (LineCollection (
495
- (i .vertices for i in collection .get_paths ()),
496
- color = collection .get_color (),
497
- ** kwargs
498
- ))
495
+ paths = list ()
496
+ for i in collection .get_paths ():
497
+ if only_used and not i .used :
498
+ continue
499
+ elif only_unused and i .used :
500
+ continue
501
+ elif only_contain_eddies and not i .contain_eddies :
502
+ continue
503
+ paths .append (i .vertices )
504
+ ax .add_collection (LineCollection (paths , color = collection .get_color (), ** kwargs ))
499
505
500
506
if hasattr (self .contours , '_mins' ):
501
507
ax .update_datalim ([self .contours ._mins , self .contours ._maxs ])
502
508
ax .autoscale_view ()
503
509
510
+ def label_contour_unused_which_contain_eddies (self , eddies ):
511
+ """Select contour which contain several eddies"""
512
+ if eddies .sign_type == 1 :
513
+ # anticyclonic
514
+ sl = slice (None ,- 1 )
515
+ cor = 1
516
+ else :
517
+ # cylonic
518
+ sl = slice (1 , None )
519
+ cor = - 1
520
+
521
+ # On each level
522
+ for j , collection in enumerate (self .contours .collections [sl ]):
523
+ # get next height
524
+ contour_height = self .contours .cvalues [j + cor ]
525
+ # On each contour
526
+ for i in collection .get_paths ():
527
+ i .contain_eddies = False
528
+ if i .used :
529
+ continue
530
+ nb = 0
531
+ # try with each eddy
532
+ for eddy in eddies :
533
+ if abs (eddy ['height_external_contour' ] - contour_height ) > 1e-8 :
534
+ continue
535
+ # If eddy center in contour
536
+ wn = winding_number_poly (eddy ['lon_max' ], eddy ['lat_max' ], i .vertices )
537
+ if wn != 0 :
538
+ # Count
539
+ nb += 1
540
+
541
+ if nb > 1 :
542
+ i .contain_eddies = True
543
+
504
544
505
545
@njit (cache = True , fastmath = True )
506
546
def index_from_nearest_path_with_pt_in_bbox_ (
@@ -517,7 +557,7 @@ def index_from_nearest_path_with_pt_in_bbox_(
517
557
y_max_per_c ,
518
558
xpt ,
519
559
ypt ,
520
- ):
560
+ ):
521
561
"""Get index from nearest path in edge bbox contain pt
522
562
"""
523
563
# Nb contour in level
0 commit comments