6161 winding_number_grid_in_poly ,
6262 winding_number_poly ,
6363 create_vertice ,
64+ poly_area ,
6465)
6566
6667logger = logging .getLogger ("pet" )
@@ -126,10 +127,32 @@ def mean_on_regular_contour(
126127 return values .mean ()
127128
128129
129- def fit_circle_path (self ):
130+ def fit_circle_path (self , method = "fit" ):
130131 if not hasattr (self , "_circle_params" ):
131- self ._circle_params = _fit_circle_path (self .vertices )
132- return self ._circle_params
132+ self ._circle_params = dict ()
133+ if method not in self ._circle_params .keys ():
134+ if method == "fit" :
135+ self ._circle_params ["fit" ] = _fit_circle_path (self .vertices )
136+ if method == "equal_area" :
137+ self ._circle_params ["equal_area" ] = _circle_from_equal_area (self .vertices )
138+ return self ._circle_params [method ]
139+
140+
141+ @njit (cache = True , fastmath = True )
142+ def _circle_from_equal_area (vertice ):
143+ lons , lats = vertice [:, 0 ], vertice [:, 1 ]
144+ # last coordinates == first
145+ lon0 , lat0 = lons [1 :].mean (), lats [1 :].mean ()
146+ c_x , c_y = coordinates_to_local (lons , lats , lon0 , lat0 )
147+ # Some time, edge is only a dot of few coordinates
148+ d_lon = lons .max () - lons .min ()
149+ d_lat = lats .max () - lats .min ()
150+ if d_lon < 1e-7 and d_lat < 1e-7 :
151+ # logger.warning('An edge is only define in one position')
152+ # logger.debug('%d coordinates %s,%s', len(lons),lons,
153+ # lats)
154+ return 0 , - 90 , nan , nan
155+ return lon0 , lat0 , (poly_area (create_vertice (c_x , c_y )) / pi ) ** 0.5 , nan
133156
134157
135158@njit (cache = True , fastmath = True )
@@ -146,10 +169,10 @@ def _fit_circle_path(vertice):
146169 # logger.debug('%d coordinates %s,%s', len(lons),lons,
147170 # lats)
148171 return 0 , - 90 , nan , nan
149- centlon_e , centlat_e , eddy_radius_e , aerr = fit_circle (c_x , c_y )
150- centlon_e , centlat_e = local_to_coordinates (centlon_e , centlat_e , lon0 , lat0 )
151- centlon_e = (centlon_e - lon0 + 180 ) % 360 + lon0 - 180
152- return centlon_e , centlat_e , eddy_radius_e , aerr
172+ centlon , centlat , eddy_radius , err = fit_circle (c_x , c_y )
173+ centlon , centlat = local_to_coordinates (centlon , centlat , lon0 , lat0 )
174+ centlon = (centlon - lon0 + 180 ) % 360 + lon0 - 180
175+ return centlon , centlat , eddy_radius , err
153176
154177
155178@njit (cache = True , fastmath = True )
0 commit comments