This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
regressionModels.py
101 lines (78 loc) · 2.38 KB
/
regressionModels.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
Empirical sea level models
"""
import numpy as np
T = np.array([8.85 / 1, 18.61]) # Period of multi-year astronomical cycles
omega = (2 * np.pi) / T
def model1(t, a, b):
"""
A simple linear trend. Used only during research
"""
return b * t + a
def model2(t, a, b, c):
"""
An accelerating signal. Used only during research
"""
return c * t**2 + b * t + a
def model3a(t, a, b, Ac, As):
"""
Linear model with only the 8.85 year tidal component.
Not published; research only
"""
return (
model1(t, a, b)
+ Ac * np.cos(omega[0] * t)
+ As * np.sin(omega[0] * t)
)
def model3b(t, a, b, Ac, As):
"""
Linear model with only the nodal cycle included. Not published; research only
"""
return (
model1(t, a, b)
+ Ac * np.cos(omega[1] * t)
+ As * np.sin(omega[1] * t)
)
def harmonic(t, Ac1, As1, Ac2, As2):
"""
Harmonic part of long term patterns
"""
res = (
Ac1 * np.cos(omega[0] * t)
+ As1 * np.sin(omega[0] * t)
+ Ac2 * np.cos(omega[1] * t)
+ As2 * np.sin(omega[1] * t)
)
return res
def linear_fnc(t, a, b):
"""
Linear part of the regression models
"""
return a + b * t
def reducedModel(t, a, b, Ac1, As1, Ac2, As2):
"""
The reduced model described in the paper, using a sine/cosine combination for
the harmonic components instead of an amplitude/phase formulation.
"""
return linear_fnc(t, a, b) + harmonic(t, Ac1, As1, Ac2, As2)
def jerked_fnc(t, p0, p1, p2, p3, t0):
"""
Model with trend, acceleration and jerk starting at time t0
"""
fac = (np.sign(t - t0) + 1) / 2
linear = linear_fnc(t, p0, p1)
jerky = fac * (((1/2) * p2 * (t - t0)**2) + ((1/6) * p3 * (t - t0)**3))
return linear + jerky
def fullModel(t, p0, p1, p2, p3, Ac0, As0, Ac1, As1, t0):
"""
The full model described in Voortman (2022), using a sine/cosine formula for the
harmonic components instead of amplitude and phase angle.
The model fully complies with contemporary insights in the effects of anthropogenic climate change
on sea levels.
"""
jerky = jerked_fnc(t, p0, p1, p2, p3, t0)
oscillate = (
Ac0 * np.cos(omega[0] * t) + As0 * np.sin(omega[0] * t)
+ Ac1 * np.cos(omega[1] * t) + As1 * np.sin(omega[1] * t)
)
return jerky + oscillate