3030from numpy import empty , array , concatenate , ma , zeros , unique , round , ones , int_
3131from matplotlib .figure import Figure
3232from numba import njit , types as numba_types
33+ from .poly import winding_number_poly
3334
3435
3536class Amplitude (object ):
@@ -488,19 +489,58 @@ def get_index_nearest_path_bbox_contain_pt(self, level, xpt, ypt):
488489 else :
489490 return self .contours .collections [level ]._paths [index ]
490491
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 ):
492493 from matplotlib .collections import LineCollection
493494 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 ))
499505
500506 if hasattr (self .contours , '_mins' ):
501507 ax .update_datalim ([self .contours ._mins , self .contours ._maxs ])
502508 ax .autoscale_view ()
503509
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+
504544
505545@njit (cache = True , fastmath = True )
506546def index_from_nearest_path_with_pt_in_bbox_ (
@@ -517,7 +557,7 @@ def index_from_nearest_path_with_pt_in_bbox_(
517557 y_max_per_c ,
518558 xpt ,
519559 ypt ,
520- ):
560+ ):
521561 """Get index from nearest path in edge bbox contain pt
522562 """
523563 # Nb contour in level
0 commit comments