| name | wave-theory-4-time-series-generation |
| description | Sub-skill of wave-theory: 4. Time Series Generation (+1). |
| version | 1.0.0 |
| category | engineering |
| type | reference |
| scripts_exempt | true |
4. Time Series Generation (+1)
4. Time Series Generation
Generate Irregular Wave Time Series:
def generate_irregular_wave_time_series(
S: np.ndarray,
frequencies: np.ndarray,
duration: float,
dt: float,
random_seed: int = None
) -> tuple[np.ndarray, np.ndarray]:
"""
Generate irregular wave elevation time series from spectrum.
Args:
S: Wave spectrum (m²/Hz)
frequencies: Frequency array (Hz)
duration: Duration (s)
dt: Time step (s)
random_seed: Random seed for reproducibility
Returns:
(time, elevation) arrays
"""
if random_seed is not None:
np.random.seed(random_seed)
time = np.arange(0, duration, dt)
eta = np.zeros_like(time)
df = frequencies[1] - frequencies[0]
for i, f in enumerate(frequencies):
if S[i] > 0:
amplitude = np.sqrt(2 * S[i] * df)
phase = np.random.uniform(0, 2*np.pi)
omega = 2 * np.pi * f
eta += amplitude * np.cos(omega * time + phase)
return time, eta
t, elevation = generate_irregular_wave_time_series(
S, freq,
duration=3600,
dt=0.1,
random_seed=42
)
Hs_timeseries = 4 * np.std(elevation)
print(f"Time Series Statistics:")
print(f" Target Hs: {params['Hs']:.2f} m")
print(f" Generated Hs: {Hs_timeseries:.2f} m")
print(f" Duration: {len(t) * 0.1 / 3600:.2f} hours")
5. Wave Scatter Diagrams
Create Wave Scatter Diagram:
def create_wave_scatter_diagram(
Hs_bins: np.ndarray,
Tp_bins: np.ndarray,
location_data: dict
) -> np.ndarray:
"""
Create wave scatter diagram (probability table).
Args:
Hs_bins: Hs bin edges (m)
Tp_bins: Tp bin edges (s)
location_data: Historical wave data or hindcast
Returns:
Probability matrix (sum = 1.0)
"""
n_Hs = len(Hs_bins) - 1
n_Tp = len(Tp_bins) - 1
scatter = np.zeros((n_Hs, n_Tp))
for i in range(n_Hs):
Hs_mid = (Hs_bins[i] + Hs_bins[i+1]) / 2
Tp_expected = 3.6 * np.sqrt(Hs_mid)
from scipy.stats import weibull_min
p_Hs = weibull_min.pdf(Hs_mid, c=2, scale=2.5)
from scipy.stats import norm
for j in range(n_Tp):
Tp_mid = (Tp_bins[j] + Tp_bins[j+1]) / 2
p_Tp_given_Hs = norm.pdf(Tp_mid, loc=Tp_expected, scale=1.5)
scatter[i, j] = p_Hs * p_Tp_given_Hs
scatter /= scatter.sum()
return scatter
Hs_bins = np.array([, , , , , , , , , , ])
Tp_bins = np.array([, , , , , , , ])
scatter = create_wave_scatter_diagram(Hs_bins, Tp_bins, {})
annual_hours = scatter *
()
()
()