wawi 0.0.13__py3-none-any.whl → 0.0.17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wawi/__init__.py +1 -1
- wawi/fe.py +259 -12
- wawi/general.py +538 -70
- wawi/identification.py +33 -11
- wawi/io.py +208 -5
- wawi/modal.py +384 -6
- wawi/model/_model.py +1 -1
- wawi/plot.py +379 -99
- wawi/prob.py +28 -0
- wawi/random.py +218 -2
- wawi/signal.py +111 -3
- wawi/structural.py +317 -59
- wawi/time_domain.py +122 -1
- wawi/tools.py +23 -0
- wawi/wave.py +662 -121
- wawi/wind.py +776 -32
- wawi/wind_code.py +26 -0
- {wawi-0.0.13.dist-info → wawi-0.0.17.dist-info}/METADATA +42 -3
- wawi-0.0.17.dist-info/RECORD +38 -0
- {wawi-0.0.13.dist-info → wawi-0.0.17.dist-info}/WHEEL +1 -1
- wawi-0.0.13.dist-info/RECORD +0 -38
- {wawi-0.0.13.dist-info → wawi-0.0.17.dist-info}/licenses/LICENSE +0 -0
- {wawi-0.0.13.dist-info → wawi-0.0.17.dist-info}/top_level.txt +0 -0
wawi/random.py
CHANGED
@@ -1,32 +1,225 @@
|
|
1
1
|
import numpy as np
|
2
|
-
|
3
2
|
def zero_crossing_period(S, omega):
|
3
|
+
"""
|
4
|
+
Estimate the zero-crossing period from a spectrum.
|
5
|
+
|
6
|
+
Parameters
|
7
|
+
----------
|
8
|
+
S : array_like
|
9
|
+
Spectral density values.
|
10
|
+
omega : array_like
|
11
|
+
Angular frequency values.
|
12
|
+
|
13
|
+
Returns
|
14
|
+
-------
|
15
|
+
float
|
16
|
+
Estimated zero-crossing period.
|
17
|
+
|
18
|
+
Notes
|
19
|
+
-----
|
20
|
+
Docstring is generated using Github Copilot.
|
21
|
+
"""
|
4
22
|
return 2*np.pi*np.sqrt(np.trapz(S, x=omega)/np.trapz(omega**2*S, x=omega))
|
5
23
|
|
6
24
|
def stoch_mom(S, omega, n=0):
|
25
|
+
"""
|
26
|
+
Compute the n-th spectral moment.
|
27
|
+
|
28
|
+
Parameters
|
29
|
+
----------
|
30
|
+
S : array_like
|
31
|
+
Spectral density values.
|
32
|
+
omega : array_like
|
33
|
+
Angular frequency values.
|
34
|
+
n : int, optional
|
35
|
+
Order of the moment (default is 0).
|
36
|
+
|
37
|
+
Returns
|
38
|
+
-------
|
39
|
+
float
|
40
|
+
n-th spectral moment.
|
41
|
+
|
42
|
+
Notes
|
43
|
+
-----
|
44
|
+
Docstring is generated using Github Copilot.
|
45
|
+
"""
|
7
46
|
return np.trapz(S*omega**n, x=omega)
|
8
47
|
|
9
48
|
def m0(S, omega):
|
49
|
+
"""
|
50
|
+
Compute the zeroth spectral moment.
|
51
|
+
|
52
|
+
Parameters
|
53
|
+
----------
|
54
|
+
S : array_like
|
55
|
+
Spectral density values.
|
56
|
+
omega : array_like
|
57
|
+
Angular frequency values.
|
58
|
+
|
59
|
+
Returns
|
60
|
+
-------
|
61
|
+
float
|
62
|
+
Zeroth spectral moment.
|
63
|
+
|
64
|
+
Notes
|
65
|
+
-----
|
66
|
+
Docstring is generated using Github Copilot.
|
67
|
+
"""
|
10
68
|
return stoch_mom(S, omega, n=0)
|
11
69
|
|
12
70
|
def m2(S, omega):
|
71
|
+
"""
|
72
|
+
Compute the second spectral moment.
|
73
|
+
|
74
|
+
Parameters
|
75
|
+
----------
|
76
|
+
S : array_like
|
77
|
+
Spectral density values.
|
78
|
+
omega : array_like
|
79
|
+
Angular frequency values.
|
80
|
+
|
81
|
+
Returns
|
82
|
+
-------
|
83
|
+
float
|
84
|
+
Second spectral moment.
|
85
|
+
|
86
|
+
Notes
|
87
|
+
-----
|
88
|
+
Docstring is generated using Github Copilot.
|
89
|
+
"""
|
13
90
|
return stoch_mom(S, omega, n=2)
|
14
91
|
|
15
92
|
def v0_from_spectrum(S, omega):
|
93
|
+
"""
|
94
|
+
Estimate zero-crossing frequency from a spectrum.
|
95
|
+
|
96
|
+
Parameters
|
97
|
+
----------
|
98
|
+
S : array_like
|
99
|
+
Spectral density values.
|
100
|
+
omega : array_like
|
101
|
+
Angular frequency values.
|
102
|
+
|
103
|
+
Returns
|
104
|
+
-------
|
105
|
+
float
|
106
|
+
Estimated zero-crossing frequency.
|
107
|
+
|
108
|
+
Notes
|
109
|
+
-----
|
110
|
+
Docstring is generated using Github Copilot.
|
111
|
+
"""
|
16
112
|
return 1/(2*np.pi) * np.sqrt(m2(S, omega)/m0(S, omega))
|
17
113
|
|
18
|
-
def v0(m0,m2):
|
114
|
+
def v0(m0, m2):
|
115
|
+
"""
|
116
|
+
Calculate zero-crossing frequency from spectral moments.
|
117
|
+
|
118
|
+
Parameters
|
119
|
+
----------
|
120
|
+
m0 : float
|
121
|
+
Zeroth spectral moment.
|
122
|
+
m2 : float
|
123
|
+
Second spectral moment.
|
124
|
+
|
125
|
+
Returns
|
126
|
+
-------
|
127
|
+
float
|
128
|
+
Zero-crossing frequency.
|
129
|
+
|
130
|
+
Notes
|
131
|
+
-----
|
132
|
+
Docstring is generated using Github Copilot.
|
133
|
+
"""
|
19
134
|
return 1/(2*np.pi) * np.sqrt(m2/m0)
|
20
135
|
|
21
136
|
def peakfactor(T, v0):
|
137
|
+
"""
|
138
|
+
Calculate the peak factor for a given time period and zero-crossing frequency.
|
139
|
+
|
140
|
+
Parameters
|
141
|
+
----------
|
142
|
+
T : float
|
143
|
+
The time period over which the peak factor is calculated.
|
144
|
+
v0 : float
|
145
|
+
The frequency parameter.
|
146
|
+
|
147
|
+
Returns
|
148
|
+
-------
|
149
|
+
kp : float
|
150
|
+
The calculated peak factor.
|
151
|
+
|
152
|
+
Notes
|
153
|
+
-----
|
154
|
+
The peak factor is computed using the formula:
|
155
|
+
c = sqrt(2 * log(v0 * T))
|
156
|
+
kp = c + Euler-Mascheroni constant / c
|
157
|
+
where `np.euler_gamma` is the Euler-Mascheroni constant.
|
158
|
+
|
159
|
+
Docstring is generated using Github Copilot.
|
160
|
+
|
161
|
+
"""
|
162
|
+
|
22
163
|
c = np.sqrt(2*np.log(v0*T))
|
23
164
|
kp = c + np.euler_gamma/c
|
24
165
|
return kp
|
25
166
|
|
26
167
|
def expmax(T, v0, std):
|
168
|
+
"""
|
169
|
+
Calculate the expected maximum value based on temperature, initial value, and standard deviation.
|
170
|
+
|
171
|
+
Parameters
|
172
|
+
----------
|
173
|
+
T : float or array-like
|
174
|
+
Temperature or an array of temperature values.
|
175
|
+
v0 : float
|
176
|
+
Initial value parameter.
|
177
|
+
std : float
|
178
|
+
Standard deviation.
|
179
|
+
|
180
|
+
Returns
|
181
|
+
-------
|
182
|
+
float or array-like
|
183
|
+
The expected maximum value computed as peakfactor(T, v0) multiplied by std.
|
184
|
+
|
185
|
+
Notes
|
186
|
+
-----
|
187
|
+
This function relies on an external function `peakfactor` which should be defined elsewhere.
|
188
|
+
Docstring is generated using Github Copilot.
|
189
|
+
|
190
|
+
Examples
|
191
|
+
--------
|
192
|
+
>>> expmax(300, 1.0, 0.5)
|
193
|
+
1.23 # Example output, depends on peakfactor implementation
|
194
|
+
"""
|
195
|
+
|
27
196
|
return peakfactor(T,v0)*std
|
28
197
|
|
29
198
|
def expmax_from_spectrum(S, omega, T):
|
199
|
+
"""
|
200
|
+
Estimate the expected maximum value from a given spectrum.
|
201
|
+
|
202
|
+
Parameters
|
203
|
+
----------
|
204
|
+
S : array_like
|
205
|
+
Spectral density values.
|
206
|
+
omega : array_like
|
207
|
+
Angular frequency values corresponding to the spectrum.
|
208
|
+
T : float
|
209
|
+
Duration or time interval over which the expected maximum is calculated.
|
210
|
+
|
211
|
+
Returns
|
212
|
+
-------
|
213
|
+
float
|
214
|
+
The expected maximum value estimated from the spectrum.
|
215
|
+
|
216
|
+
Notes
|
217
|
+
-----
|
218
|
+
This function relies on auxiliary functions `m0`, `m2`, `v0`, and `expmax` to compute
|
219
|
+
spectral moments and the expected maximum.
|
220
|
+
|
221
|
+
Docstring is generated using Github Copilot.
|
222
|
+
"""
|
30
223
|
m0_val = m0(S, omega)
|
31
224
|
std = np.sqrt(m0_val)
|
32
225
|
|
@@ -35,4 +228,27 @@ def expmax_from_spectrum(S, omega, T):
|
|
35
228
|
return expmax(T, v0_val, std)
|
36
229
|
|
37
230
|
def peakfactor_from_spectrum(S, omega, T):
|
231
|
+
"""
|
232
|
+
Calculate the peak factor from a given spectrum.
|
233
|
+
|
234
|
+
Parameters
|
235
|
+
----------
|
236
|
+
S : array_like
|
237
|
+
Spectral density values.
|
238
|
+
omega : array_like
|
239
|
+
Angular frequency values corresponding to the spectrum.
|
240
|
+
T : float
|
241
|
+
Duration or period over which the peak factor is calculated.
|
242
|
+
|
243
|
+
Returns
|
244
|
+
-------
|
245
|
+
float
|
246
|
+
The calculated peak factor based on the input spectrum and period.
|
247
|
+
|
248
|
+
Notes
|
249
|
+
-----
|
250
|
+
This function uses the `peakfactor` and `v0` helper functions to compute the result.
|
251
|
+
Docstring is generated using Github Copilot.
|
252
|
+
"""
|
253
|
+
|
38
254
|
return peakfactor(T, v0(S, omega))
|
wawi/signal.py
CHANGED
@@ -3,6 +3,34 @@ import numpy as np
|
|
3
3
|
from scipy.optimize import curve_fit
|
4
4
|
|
5
5
|
def fit_jonswap(S, w, sigma=[0.07, 0.09], initial_values=None):
|
6
|
+
"""
|
7
|
+
Fit the JONSWAP spectrum to a given numeric array describing spectral density.
|
8
|
+
|
9
|
+
Parameters
|
10
|
+
----------
|
11
|
+
S : array_like
|
12
|
+
Spectral density values.
|
13
|
+
w : array_like
|
14
|
+
Angular frequency values corresponding to `S`.
|
15
|
+
sigma : list of float, optional
|
16
|
+
Sigma parameters for the JONSWAP spectrum. Default is [0.07, 0.09].
|
17
|
+
initial_values : dict, optional
|
18
|
+
Dictionary of initial values for the parameters 'Hs', 'Tp', and 'gamma'.
|
19
|
+
If not provided, default values are used.
|
20
|
+
|
21
|
+
Returns
|
22
|
+
-------
|
23
|
+
out : dict
|
24
|
+
Dictionary containing the fitted parameters:
|
25
|
+
- 'Hs': Significant wave height.
|
26
|
+
- 'Tp': Peak period.
|
27
|
+
- 'gamma': Peak enhancement factor.
|
28
|
+
- 'p0': Initial parameter values used for fitting.
|
29
|
+
|
30
|
+
Notes
|
31
|
+
-----
|
32
|
+
Docstring is generated by GitHub Copilot.
|
33
|
+
"""
|
6
34
|
if initial_values is None:
|
7
35
|
initial_values = {}
|
8
36
|
|
@@ -20,25 +48,105 @@ def fit_jonswap(S, w, sigma=[0.07, 0.09], initial_values=None):
|
|
20
48
|
out = dict(Hs=popt[0], Tp=popt[1], gamma=popt[2], p0=[p0['Hs'], p0['Tp'], p0['gamma']])
|
21
49
|
|
22
50
|
return out
|
23
|
-
|
51
|
+
|
24
52
|
def onesided_to_twosided(omega, S, axis=-1):
|
53
|
+
"""
|
54
|
+
Convert a one-sided spectrum to a two-sided spectrum.
|
55
|
+
|
56
|
+
Parameters
|
57
|
+
----------
|
58
|
+
omega : array_like
|
59
|
+
One-sided angular frequency array.
|
60
|
+
S : array_like
|
61
|
+
One-sided spectral density array.
|
62
|
+
axis : int, optional
|
63
|
+
Axis along which to concatenate. Default is -1.
|
64
|
+
|
65
|
+
Returns
|
66
|
+
-------
|
67
|
+
omega2 : ndarray
|
68
|
+
Two-sided angular frequency array.
|
69
|
+
S2 : ndarray
|
70
|
+
Two-sided spectral density array.
|
71
|
+
|
72
|
+
Notes
|
73
|
+
-----
|
74
|
+
Docstring is generated by GitHub Copilot.
|
75
|
+
"""
|
25
76
|
S2 = 0.5*np.concatenate([np.flip(S, axis=axis), S], axis=axis)
|
26
77
|
omega2 = np.hstack([np.flip(-omega), omega])
|
27
78
|
|
28
79
|
return omega2, S2
|
29
80
|
|
30
|
-
|
31
81
|
def twosided_to_onesided(omega, S):
|
82
|
+
"""
|
83
|
+
Convert a two-sided spectrum to a one-sided spectrum.
|
84
|
+
|
85
|
+
Parameters
|
86
|
+
----------
|
87
|
+
omega : array_like
|
88
|
+
Two-sided angular frequency array.
|
89
|
+
S : array_like
|
90
|
+
Two-sided spectral density array.
|
91
|
+
|
92
|
+
Returns
|
93
|
+
-------
|
94
|
+
omega1 : ndarray
|
95
|
+
One-sided angular frequency array.
|
96
|
+
S1 : ndarray
|
97
|
+
One-sided spectral density array.
|
98
|
+
|
99
|
+
Notes
|
100
|
+
-----
|
101
|
+
Docstring is generated by GitHub Copilot.
|
102
|
+
"""
|
32
103
|
n_samples = len(omega)
|
33
104
|
return omega[:n_samples//2], S[:,:,:n_samples//2]
|
34
105
|
|
35
|
-
|
36
106
|
def ramp_up(Nramp, Ntot):
|
107
|
+
"""
|
108
|
+
Create a ramp-up scaling array.
|
109
|
+
|
110
|
+
Parameters
|
111
|
+
----------
|
112
|
+
Nramp : int
|
113
|
+
Number of samples for ramp-up.
|
114
|
+
Ntot : int
|
115
|
+
Total number of samples.
|
116
|
+
|
117
|
+
Returns
|
118
|
+
-------
|
119
|
+
t_scale : ndarray
|
120
|
+
Array with ramp-up scaling applied.
|
121
|
+
|
122
|
+
Notes
|
123
|
+
-----
|
124
|
+
Docstring is generated by GitHub Copilot.
|
125
|
+
"""
|
37
126
|
t_scale = np.ones(Ntot)
|
38
127
|
t_scale[:Nramp] = np.linspace(0, 1, Nramp)
|
39
128
|
return t_scale
|
40
129
|
|
41
130
|
def ramp_up_t(t, t0):
|
131
|
+
"""
|
132
|
+
Create a ramp-up scaling array based on time threshold.
|
133
|
+
|
134
|
+
Parameters
|
135
|
+
----------
|
136
|
+
t : array_like
|
137
|
+
Time array.
|
138
|
+
t0 : float
|
139
|
+
Time threshold for ramp-up.
|
140
|
+
|
141
|
+
Returns
|
142
|
+
-------
|
143
|
+
t_scale : ndarray
|
144
|
+
Array with ramp-up scaling applied.
|
145
|
+
|
146
|
+
Notes
|
147
|
+
-----
|
148
|
+
Docstring is generated by GitHub Copilot.
|
149
|
+
"""
|
42
150
|
Nramp = np.sum(t<t0)
|
43
151
|
Ntot = len(t)
|
44
152
|
|