Skip to content

Commit 7c8fc73

Browse files
committed
Add visvalingam test
1 parent 64efe1b commit 7c8fc73

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/py_eddy_tracker/observations/network.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
in1d,
1717
ones,
1818
uint32,
19+
uint16,
1920
unique,
2021
where,
2122
zeros,
@@ -513,7 +514,6 @@ def relatives(self, obs, order=2):
513514
else:
514515
segments_connexion[seg][0] = i_slice
515516

516-
517517
if i_p != -1:
518518

519519
if p_seg not in segments_connexion:
@@ -531,15 +531,9 @@ def relatives(self, obs, order=2):
531531
segments_connexion[seg][1].append(n_seg)
532532
segments_connexion[n_seg][1].append(seg)
533533

534+
i_obs = [obs] if not hasattr(obs, "__iter__") else obs
534535

535-
i_obs = (
536-
[obs]
537-
if not hasattr(obs, "__iter__")
538-
else obs
539-
)
540-
import numpy as np
541-
542-
distance = zeros(segment.size, dtype=np.uint16) - 1
536+
distance = zeros(segment.size, dtype=uint16) - 1
543537

544538
def loop(seg, dist=1):
545539
i_slice, links = segments_connexion[seg]

src/py_eddy_tracker/observations/observation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,8 +2054,8 @@ def contains(self, x, y, intern=False):
20542054
:rtype: array[int32]
20552055
"""
20562056
xname, yname = self.intern(intern)
2057-
m = ~ (isnan(x) + isnan(y))
2058-
i = -ones(x.shape, dtype='i4')
2057+
m = ~(isnan(x) + isnan(y))
2058+
i = -ones(x.shape, dtype="i4")
20592059
i[m] = poly_indexs(x[m], y[m], self[xname], self[yname])
20602060
return i
20612061

tests/test_poly.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
from numpy import array, pi
22
from pytest import approx
33

4-
from py_eddy_tracker.poly import convex, fit_circle, get_convex_hull, poly_area_vertice
4+
from py_eddy_tracker.poly import (
5+
convex,
6+
fit_circle,
7+
get_convex_hull,
8+
poly_area_vertice,
9+
visvalingam,
10+
)
511

612
# Vertices for next test
713
V = array(((2, 2, 3, 3, 2), (-10, -9, -9, -10, -10)))
@@ -29,3 +35,11 @@ def test_convex():
2935

3036
def test_convex_hull():
3137
assert convex(*get_convex_hull(*V_concave)) is True
38+
39+
40+
def test_visvalingam():
41+
x = array([1, 2, 3, 4, 5, 6.75, 6, 1])
42+
y = array([-0.5, -1.5, -1, -1.75, -1, -1, -0.5, -0.5])
43+
x_, y_ = visvalingam(x, y, 6)
44+
assert ([1, 2, 3, 4, 6, 1] == x_).all()
45+
assert ([-0.5, -1.5, -1, -1.75, -0.5, -0.5] == y_).all()

0 commit comments

Comments
 (0)