forked from svangennip/py-eddy-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_generic.py
More file actions
51 lines (43 loc) · 1.5 KB
/
test_generic.py
File metadata and controls
51 lines (43 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from numpy import arange, array, nan, ones, zeros
from py_eddy_tracker.generic import cumsum_by_track, simplify, wrap_longitude
def test_simplify():
x = arange(10, dtype="f4")
y = zeros(10, dtype="f4")
# Will jump one value on two
x_, y_ = simplify(x, y, precision=1)
assert x_.shape[0] == 5
x_, y_ = simplify(x, y, precision=0.99)
assert x_.shape[0] == 10
# check nan management
x[4] = nan
x_, y_ = simplify(x, y, precision=1)
assert x_.shape[0] == 6
x[3] = nan
x_, y_ = simplify(x, y, precision=1)
assert x_.shape[0] == 6
x[:4] = nan
x_, y_ = simplify(x, y, precision=1)
assert x_.shape[0] == 3
x[:] = nan
x_, y_ = simplify(x, y, precision=1)
assert x_.shape[0] == 0
def test_cumsum_by_track():
a = ones(10, dtype="i4") * 2
track = array([1, 1, 2, 2, 2, 2, 44, 44, 44, 48])
assert (cumsum_by_track(a, track) == [2, 4, 2, 4, 6, 8, 2, 4, 6, 2]).all()
def test_wrapping():
y = x = arange(-5, 5, dtype="f4")
x_, _ = wrap_longitude(x, y, ref=-10)
assert (x_ == x).all()
x_, _ = wrap_longitude(x, y, ref=1)
assert x.size == x_.size
assert (x_[6:] == x[6:]).all()
assert (x_[:6] == x[:6] + 360).all()
x_, _ = wrap_longitude(x, y, ref=1, cut=True)
assert x.size + 3 == x_.size
assert (x_[6 + 3 :] == x[6:]).all()
assert (x_[:7] == x[:7] + 360).all()
# FIXME Need evolution in wrap_longitude
# x %= 360
# x_, _ = wrap_longitude(x, y, ref=-10, cut=True)
# assert x.size == x_.size