Skip to content

Commit d30248e

Browse files
committed
Add method to found close center
1 parent 9b2d526 commit d30248e

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/py_eddy_tracker/observations/observation.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -893,24 +893,38 @@ def intern(flag, public_label=False):
893893
labels = [VAR_DESCR[label]["nc_name"] for label in labels]
894894
return labels
895895

896-
def match(self, other, intern=False, cmin=0):
896+
def match(self, other, method="overlap", intern=False, cmin=0, **kwargs):
897897
"""return index and score compute with area
898898
899899
:param EddiesObservations other: Observations to compare
900+
:param str method:
901+
if method is "overlap" method will use contour to compute score,
902+
if method is "circle" method will apply a formula of circle overlap
900903
:param bool intern: if True, speed contour will be used
901904
:param float cmin: 0 < cmin < 1, return only couple above cmin
905+
:param dict kwargs: look at :py:meth:`vertice_overlap`
902906
:return: return index of couple in self and other and cost value
903907
:rtype: (array(int), array(int), array(float))
904908
905909
.. minigallery:: py_eddy_tracker.EddiesObservations.match
906910
"""
907911
x_name, y_name = self.intern(intern)
908-
i, j = bbox_intersection(
909-
self[x_name], self[y_name], other[x_name], other[y_name]
910-
)
911-
c = vertice_overlap(
912-
self[x_name][i], self[y_name][i], other[x_name][j], other[y_name][j]
913-
)
912+
if method == "overlap":
913+
i, j = bbox_intersection(
914+
self[x_name], self[y_name], other[x_name], other[y_name]
915+
)
916+
c = vertice_overlap(
917+
self[x_name][i],
918+
self[y_name][i],
919+
other[x_name][j],
920+
other[y_name][j],
921+
**kwargs,
922+
)
923+
elif method == "close_center":
924+
i, j, c = close_center(
925+
self.latitude, self.longitude, other.latitude, other.longitude, **kwargs
926+
)
927+
914928
m = c > cmin
915929
return i[m], j[m], c[m]
916930

src/py_eddy_tracker/poly.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,31 @@ def winding_number_grid_in_poly(x_1d, y_1d, i_x0, i_x1, x_size, i_y0, xy_poly):
171171
return i_x, i_y
172172

173173

174+
@njit(cache=True, fastmath=True)
175+
def close_center(x0, y0, x1, y1, delta=.1):
176+
"""
177+
Compute an overlap with circle parameter and return a percentage
178+
179+
:param array x0: x centers of dataset 0
180+
:param array y0: y centers of dataset 0
181+
:param array x1: x centers of dataset 1
182+
:param array y1: y centers of dataset 1
183+
:return: Result of cost function
184+
:rtype: array
185+
"""
186+
nb0, nb1 = x0.shape[0], x1.shape[0]
187+
i, j, c = list(), list(), list()
188+
for i0 in range(nb0):
189+
xi0, yi0 = x0[i0], y0[i0]
190+
for i1 in range(nb1):
191+
if abs(x1[i1] - xi0) > delta:
192+
continue
193+
if abs(y1[i1] - yi0) > delta:
194+
continue
195+
i.append(i0), j.append(i1), c.append(1)
196+
return array(i), array(j), array(c)
197+
198+
174199
@njit(cache=True, fastmath=True)
175200
def bbox_intersection(x0, y0, x1, y1):
176201
"""

0 commit comments

Comments
 (0)