3636from  .tracking_objects  import  uniform_resample , nearest 
3737from  .observations  import  EddiesObservations 
3838from  .property_objects  import  Amplitude 
39- from  .tools  import  distance , winding_number_poly , fit_circle_c 
39+ from  .tools  import  distance , winding_number_poly , fit_circle_c ,  poly_contain_poly 
4040from  matplotlib .path  import  Path  as  BasePath 
4141from  scipy .interpolate  import  griddata 
4242
@@ -166,7 +166,6 @@ def get_uavg(eddy, contours, centlon_e, centlat_e, poly_eff, grd,
166166
167167    if  'RectBivariate'  in  eddy .interp_method :
168168        uavg  =  eddy .uspd_coeffs .ev (theseglat [1 :], theseglon [1 :]).mean ()
169- 
170169    elif  'griddata'  in  eddy .interp_method :
171170        uspd1d  =  eddy .uspd [eddy .slice_j , eddy .slice_i ].ravel ()
172171        uavg  =  griddata (points , uspd1d ,
@@ -201,7 +200,6 @@ def get_uavg(eddy, contours, centlon_e, centlat_e, poly_eff, grd,
201200        # Leave loop if no contours at level citer.index 
202201        theindex  =  eddy .swirl .get_index_nearest_path (
203202            corrected_coll_index , centlon_e , centlat_e )
204- 
205203        if  theindex  is  None :
206204            continue 
207205
@@ -212,15 +210,14 @@ def get_uavg(eddy, contours, centlon_e, centlat_e, poly_eff, grd,
212210            continue 
213211
214212        # 2. Ensure polygon_i is within polygon_e 
215-         if  not  poly_eff .contains_path ( poly_i ):
213+         if  not  poly_contain_poly ( poly_eff .vertices ,  poly_i . vertices ):
216214            continue 
217215
218216        # 3. Respect size range 
219217        mask_i_sum  =  poly_i .contains_points (points ).sum ()
220218        if  not  (mask_i_sum  >=  pixel_min  and 
221219                mask_i_sum  <=  eddy .pixel_threshold [1 ]):
222220            continue 
223- 
224221        any_inner_contours  =  True 
225222
226223        seglon , seglat  =  (poly_i .vertices [:, 0 ], poly_i .vertices [:, 1 ])
@@ -249,27 +246,14 @@ def get_uavg(eddy, contours, centlon_e, centlat_e, poly_eff, grd,
249246
250247    if  not  any_inner_contours :
251248        # set speed based contour parameters 
252-         # proj = Proj('+proj=aeqd +lat_0=%s +lon_0=%s' 
253-                     # % (theseglat.mean(), theseglon.mean())) 
254-         # cx, cy = proj(theseglon, theseglat) 
255-         # # cx, cy = eddy.m_val(theseglon, theseglat) 
256-         # centx_s, centy_s, eddy_radius_s, junk = fit_circle(cx, cy) 
257-         # centlon_s, centlat_s = proj(centx_s, centy_s, inverse=True) 
258-         # # centlon_s, centlat_s = eddy.m_val(centx_s, centy_s, inverse=True) 
259- 
260-     # else:  # use the effective contour 
261- #         centlon_s, centlat_s = centlon_e, centlat_e 
262-         # eddy_radius_s = eddy_radius_e 
263249        inner_seglon , inner_seglat  =  theseglon , theseglat 
264250
265251    if  not  save_all_uavg :
266-         # return (uavg, centlon_s, centlat_s, eddy_radius_s, 
267-                 # theseglon, theseglat, inner_seglon, inner_seglat) 
268-         return  (uavg , theseglon , theseglat , inner_seglon , inner_seglat )
269- 
252+         return  (uavg , theseglon , theseglat ,
253+                 inner_seglon , inner_seglat , any_inner_contours )
270254    else :
271-         return  (uavg , theseglon , theseglat ,  inner_seglon ,  inner_seglat , 
272-                 all_uavg )
255+         return  (uavg , theseglon , theseglat ,
256+                 inner_seglon ,  inner_seglat ,  any_inner_contours ,  all_uavg )
273257
274258
275259def  isvalid (self ):
@@ -438,8 +422,6 @@ def collection_loop(contours, grd, rtime, a_list_obj, c_list_obj,
438422                if  'Q'  in  eddy .diagnostic_type :
439423                    # KCCMC11 
440424                    # Note, eddy amplitude == max(abs(vort/f)) within eddy, 
441-                     # amplitude = np.abs(x_i[jmin:jmax,imin:imax 
442-                     #                         ].flat[mask_eff]).max() 
443425                    amplitude  =  np .abs (x_i [eddy .slice_j , eddy .slice_i 
444426                                           ][eddy .mask_eff ]).max ()
445427
@@ -475,19 +457,15 @@ def collection_loop(contours, grd, rtime, a_list_obj, c_list_obj,
475457                    #~ if eddy.track_array_variables > 0: 
476458
477459                    if  not  eddy .track_extra_variables :
478-                         # (uavg, centlon_s, centlat_s, 
479-                         # eddy_radius_s, contlon_s, contlat_s, 
480-                         # inner_contlon, inner_contlat) = get_uavg(*args) 
481460                        (uavg , contlon_s , contlat_s ,
482-                          inner_contlon , inner_contlat ) =  get_uavg (* args )
461+                          inner_contlon , inner_contlat ,
462+                          any_inner_contours 
463+                          ) =  get_uavg (* args )
483464                    else :
484-                         # (uavg, centlon_s, centlat_s, 
485-                         # eddy_radius_s, contlon_s, contlat_s, 
486-                         # inner_contlon, inner_contlat, 
487-                         # uavg_profile) = get_uavg(*args, save_all_uavg=True) 
488465                        (uavg , contlon_s , contlat_s ,
489466                         inner_contlon , inner_contlat ,
490-                          uavg_profile ) =  get_uavg (
467+                          any_inner_contours , uavg_profile 
468+                          ) =  get_uavg (
491469                            * args , save_all_uavg = True )
492470
493471                    # Use azimuth equal projection for radius 
0 commit comments