@@ -449,11 +449,11 @@ def calc_uavg(points, uspd, lon, lat):
449449        return  np .mean (uavg [np .isfinite (uavg )])
450450
451451    # True for debug figures 
452-     debug_U  =  False 
453-     if  debug_U :
454-         schem_dic  =  {}
455-         conts_x  =  np .array ([])
456-         conts_y  =  np .array ([])
452+     # debug_U = False
453+     # if debug_U:
454+         # schem_dic = {}
455+         # conts_x = np.array([])
456+         # conts_y = np.array([])
457457
458458    # Unpack indices for convenience 
459459    istr , iend , jstr , jend  =  Eddy .i0 , Eddy .i1 , Eddy .j0 , Eddy .j1 
@@ -520,42 +520,42 @@ def calc_uavg(points, uspd, lon, lat):
520520                seglon , seglat  =  poly_i .vertices [:,0 ], poly_i .vertices [:,1 ]
521521                seglon , seglat  =  eddy_tracker .uniform_resample (seglon , seglat )
522522
523-                 if  debug_U :
524-                     px , py  =  pcol_2dxy (grd .lon ()[jmin :jmax ,imin :imax ],
525-                                        grd .lat ()[jmin :jmax ,imin :imax ])
526-                     plt .figure (55 )
527-                     ax1  =  plt .subplot (121 )
528-                     if  start :
529-                         pcm  =  ax1 .pcolormesh (px , py , Eddy .Uspd [jmin :jmax ,imin :imax ], cmap = plt .cm .gist_earth_r )
530-                         pcm .set_clim (0 , .5 )
531-                         plt .colorbar (pcm , orientation = 'horizontal' )
532-                         plt .scatter (grd .lon ()[jmin :jmax ,imin :imax ],
533-                                     grd .lat ()[jmin :jmax ,imin :imax ], s = 5 , c = 'k' )
534-                         start  =  False 
535-                     plt .plot (seglon , seglat , '.-r' )
536-                     plt .plot (Eddy .circlon , Eddy .circlat , 'b' )
537-                     plt .scatter (centlon_e , centlat_e , s = 125 , c = 'r' )
538-                     plt .axis ('image' )
539-                     ax2  =  plt .subplot (122 )
540-                     ax2 .set_title ('sum mask: %s'  % np .sum (mask_i ))
541-                     plt .pcolormesh (px , py , mask_i .reshape (px .shape ), cmap = plt .cm .Accent , edgecolors = 'orange' )
542-                     plt .scatter (grd .lon ()[jmin :jmax ,imin :imax ],
543-                                 grd .lat ()[jmin :jmax ,imin :imax ], s = 5 , c = 'k' )
544-                     plt .plot (seglon , seglat , '.-r' )
545-                     conts_x  =  np .append (conts_x , seglon )
546-                     conts_y  =  np .append (conts_y , seglat )
547-                     conts_x  =  np .append (conts_x , 9999 )
548-                     conts_y  =  np .append (conts_y , 9999 )
549-                     plt .plot (Eddy .circlon , Eddy .circlat , 'b' )
550-                     plt .scatter (centlon_e , centlat_e , s = 125 , c = 'r' )
523+                 # if debug_U:
524+                     # px, py = pcol_2dxy(grd.lon()[jmin:jmax,imin:imax],
525+                                        # grd.lat()[jmin:jmax,imin:imax])
526+                     # plt.figure(55)
527+                     # ax1 = plt.subplot(121)
528+                     # if start:
529+                         # pcm = ax1.pcolormesh(px, py, Eddy.Uspd[jmin:jmax,imin:imax], cmap=plt.cm.gist_earth_r)
530+                         # pcm.set_clim(0, .5)
531+                         # plt.colorbar(pcm, orientation='horizontal')
532+                         # plt.scatter(grd.lon()[jmin:jmax,imin:imax],
533+                                     # grd.lat()[jmin:jmax,imin:imax], s=5, c='k')
534+                         # start = False
535+                     # plt.plot(seglon, seglat, '.-r')
536+                     # plt.plot(Eddy.circlon, Eddy.circlat, 'b')
537+                     # plt.scatter(centlon_e, centlat_e, s=125, c='r')
538+                     # plt.axis('image')
539+                     # ax2 = plt.subplot(122)
540+                     # ax2.set_title('sum mask: %s' %np.sum(mask_i))
541+                     # plt.pcolormesh(px, py, mask_i.reshape(px.shape), cmap=plt.cm.Accent, edgecolors='orange')
542+                     # plt.scatter(grd.lon()[jmin:jmax,imin:imax],
543+                                 # grd.lat()[jmin:jmax,imin:imax], s=5, c='k')
544+                     # plt.plot(seglon, seglat, '.-r')
545+                     # conts_x = np.append(conts_x, seglon)
546+                     # conts_y = np.append(conts_y, seglat)
547+                     # conts_x = np.append(conts_x, 9999)
548+                     # conts_y = np.append(conts_y, 9999)
549+                     # plt.plot(Eddy.circlon, Eddy.circlat, 'b')
550+                     # plt.scatter(centlon_e, centlat_e, s=125, c='r')
551551
552552                # Interpolate Uspd to seglon, seglat, then get mean 
553553                Uavgseg  =  calc_uavg (points , Eddy .Uspd [jmin :jmax ,imin :imax ], seglon [:- 1 ], seglat [:- 1 ])
554554
555555                if  save_all_uavg :
556556                    all_uavg .append (Uavgseg )
557557
558-                 if  Uavgseg  >=  Uavg :
558+                 if  Uavgseg  >=  Uavg   and   np . sum ( mask_i )  >=   Eddy . pixel_threshold [ 0 ] :
559559                    Uavg  =  Uavgseg .copy ()
560560                    theseglon , theseglat  =  seglon .copy (), seglat .copy ()
561561
@@ -569,42 +569,42 @@ def calc_uavg(points, uspd, lon, lat):
569569        # Speed based eddy radius (eddy_radius_s) 
570570        centx_s , centy_s , eddy_radius_s , junk , junk  =  fit_circle (cx , cy )
571571        centlon_s , centlat_s  =  Eddy .M .projtran (centx_s , centy_s , inverse = True )
572-         if  debug_U :
573-             ax1 .set_title ('Speed-based radius: %s km'  % np .int (eddy_radius_s / 1e3 ))
574-             ax1 .plot (poly_e .vertices [:,0 ], poly_e .vertices [:,1 ], 'om' )
575-             ax1 .plot (theseglon , theseglat , 'g' , lw = 3 )
576-             ax1 .plot (inner_seglon , inner_seglat , 'k' )
577-             ax1 .scatter (centlon_s , centlat_s , s = 50 , c = 'g' )
578-             ax1 .axis ('image' )
579-             ax2 .plot (theseglon , theseglat , 'g' , lw = 3 )
580-             ax1 .plot (inner_seglon , inner_seglat , 'k' )
581-             ax2 .axis ('image' )
582-             plt .show ()
583-             schem_dic ['lon' ] =  grd .lon ()[jmin :jmax ,imin :imax ]
584-             schem_dic ['lat' ] =  grd .lat ()[jmin :jmax ,imin :imax ]
585-             schem_dic ['spd' ] =  Eddy .Uspd [jmin :jmax ,imin :imax ]
586-             schem_dic ['inner_seg' ] =  np .array ([inner_seglon , inner_seglat ]).T 
587-             schem_dic ['effective_seg' ] =  np .array ([poly_e .vertices [:,0 ], poly_e .vertices [:,1 ]]).T 
588-             schem_dic ['effective_circ' ] =  np .array ([Eddy .circlon , Eddy .circlat ]).T 
589-             schem_dic ['speed_seg' ] =  np .array ([theseglon , theseglat ]).T 
590-             schem_dic ['all_segs' ] =  np .array ([conts_x , conts_y ]).T 
591-             schem_dic ['Ls_centroid' ] =  np .array ([centlon_s , centlat_s ])
592-             schem_dic ['Leff_centroid' ] =  np .array ([centlon_e , centlat_e ])
593-             io .savemat ('schematic_fig_%s'  % np .round (eddy_radius_s / 1e3 , 3 ), schem_dic )
572+         # if debug_U:
573+             # ax1.set_title('Speed-based radius: %s km' %np.int(eddy_radius_s/1e3))
574+             # ax1.plot(poly_e.vertices[:,0], poly_e.vertices[:,1], 'om')
575+             # ax1.plot(theseglon, theseglat, 'g', lw=3)
576+             # ax1.plot(inner_seglon, inner_seglat, 'k')
577+             # ax1.scatter(centlon_s, centlat_s, s=50, c='g')
578+             # ax1.axis('image')
579+             # ax2.plot(theseglon, theseglat, 'g', lw=3)
580+             # ax1.plot(inner_seglon, inner_seglat, 'k')
581+             # ax2.axis('image')
582+             # plt.show()
583+             # schem_dic['lon'] = grd.lon()[jmin:jmax,imin:imax]
584+             # schem_dic['lat'] = grd.lat()[jmin:jmax,imin:imax]
585+             # schem_dic['spd'] = Eddy.Uspd[jmin:jmax,imin:imax]
586+             # schem_dic['inner_seg'] = np.array([inner_seglon, inner_seglat]).T
587+             # schem_dic['effective_seg'] = np.array([poly_e.vertices[:,0], poly_e.vertices[:,1]]).T
588+             # schem_dic['effective_circ'] = np.array([Eddy.circlon, Eddy.circlat]).T
589+             # schem_dic['speed_seg'] = np.array([theseglon, theseglat]).T
590+             # schem_dic['all_segs'] = np.array([conts_x, conts_y]).T
591+             # schem_dic['Ls_centroid'] = np.array([centlon_s, centlat_s])
592+             # schem_dic['Leff_centroid'] = np.array([centlon_e, centlat_e])
593+             # io.savemat('schematic_fig_%s' %np.round(eddy_radius_s/1e3, 3), schem_dic)
594594        if  not  save_all_uavg :
595595            return  Uavg , centlon_s , centlat_s , eddy_radius_s , theseglon , theseglat , inner_seglon , inner_seglat 
596596        else :  
597597            return  Uavg , centlon_s , centlat_s , eddy_radius_s , theseglon , theseglat , inner_seglon , inner_seglat , all_uavg 
598598
599599    except  Exception : # If no interior contours found, use eddy_radius_e 
600600
601-         if  debug_U  and  0 :
602-             plt .title ('Effective radius: %s km'  % np .int (eddy_radius_e / 1e3 ))
603-             plt .plot (poly_e .vertices [:,0 ], poly_e .vertices [:,1 ], 'om' )
604-             plt .plot (theseglon , theseglat , 'g' )
605-             plt .scatter (centlon_e , centlat_e , s = 125 , c = 'r' )
606-             plt .axis ('image' )
607-             plt .show ()
601+         # if debug_U and 0:
602+             # plt.title('Effective radius: %s km' %np.int(eddy_radius_e/1e3))
603+             # plt.plot(poly_e.vertices[:,0], poly_e.vertices[:,1], 'om')
604+             # plt.plot(theseglon, theseglat, 'g')
605+             # plt.scatter(centlon_e, centlat_e, s=125, c='r')
606+             # plt.axis('image')
607+             # plt.show()
608608        if  not  save_all_uavg :
609609            return  Uavg , centlon_e , centlat_e , eddy_radius_e , theseglon , theseglat , theseglon , theseglat 
610610        else :
0 commit comments