/
test_uv.py
56 lines (42 loc) · 1.27 KB
/
test_uv.py
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
52
53
54
55
56
"""
Full example test.
"""
import pytest
import numpy as np
from pandas import date_range
from matplotlib.dates import date2num
from utide import solve
from utide import reconstruct
from utide.utilities import Bunch
@pytest.fixture
def fake_tide(t, M2amp, M2phase):
"""
Generate a minimally realistic-looking fake semidiurnal tide.
t is time in hours
phases are in radians
Modified from:
http://currents.soest.hawaii.edu/ocn760_4/_static/plotting.html
"""
return M2amp * np.sin(2 * np.pi * t / 12.42 - M2phase)
@pytest.fixture
def make_data():
N = 500
np.random.seed(1234)
t = date_range(start='2016-03-29', periods=N, freq='H')
# Signal + some noise.
u = fake_tide(np.arange(N), M2amp=2, M2phase=0) + np.random.randn(N)
v = fake_tide(np.arange(N), M2amp=1, M2phase=np.pi) + np.random.randn(N)
time = date2num(t.to_pydatetime())
return time, u, v
def test_solve():
time, u, v = make_data()
coef = solve(time, u, v,
lat=-42.5,
nodal=False,
trend=False,
method='ols',
conf_int='linear',
Rayleigh_min=0.95,)
assert isinstance(coef, Bunch)
tide = reconstruct(time, coef)
assert isinstance(tide, Bunch)