Skip to content

Commit ad230c7

Browse files
committed
Refactor BDM method to match MATLAB implementation with surface-elevation scaling and Newton-Raphson optimization
- Change default nfft from 2048 to 256 samples - Add surface-elevation-equivalent spectra computation (Step 9) using maximum transfer function to correct for depth attenuation - Scale directional distribution using first sensor's surface-equivalent spectrum instead of averaged auto-spectra - Remove automatic statistics computation and info return from dirspec function - Fix statistics
1 parent 65a900f commit ad230c7

31 files changed

Lines changed: 5149 additions & 923 deletions

build/lib/diwasp/__init__.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
"""DIWASP - DIrectional WAve SPectrum analysis.
2+
3+
A Python package for estimating directional wave spectra from multi-sensor
4+
measurements. This is a port of the original DIWASP Matlab toolbox developed
5+
by David Johnson at the Coastal Oceanography Group, UWA, Perth.
6+
7+
Main Functions
8+
--------------
9+
diwasp : High-level wrapper for analysis of DataFrame/Dataset over multiple windows
10+
dirspec : Estimate directional spectrum from sensor data (single window)
11+
12+
Data Structures
13+
---------------
14+
InstrumentData : Sensor measurements and configuration
15+
SpectralMatrix : 2D directional wave spectrum
16+
EstimationParameters : Analysis configuration
17+
SpectralInfo : Computed spectral statistics
18+
19+
Sensor Types
20+
------------
21+
SensorType : Enum of supported sensor types (ELEV, PRES, VELX, VELY, etc.)
22+
23+
Estimation Methods
24+
------------------
25+
EstimationMethod : Enum of estimation algorithms (DFTM, EMLM, IMLM, EMEP, BDM)
26+
27+
Spectrum Utilities
28+
------------------
29+
makespec : Generate synthetic directional spectra
30+
interpspec : Interpolate spectra to new grids
31+
make_wave_data : Generate synthetic sensor data
32+
33+
Example (High-level API)
34+
------------------------
35+
>>> import pandas as pd
36+
>>> from diwasp import diwasp
37+
>>>
38+
>>> # Load sensor data with datetime index
39+
>>> df = pd.read_csv('wave_data.csv', index_col='time', parse_dates=True)
40+
>>>
41+
>>> # Run analysis over multiple windows
42+
>>> result = diwasp(
43+
... df,
44+
... sensor_mapping={'pressure': 'pres', 'u': 'velx', 'v': 'vely'},
45+
... window_length=1800, # 30 minutes
46+
... window_overlap=900, # 15 minutes
47+
... depth=20.0,
48+
... z=0.5, # sensors 0.5m above seabed
49+
... )
50+
>>>
51+
>>> print(f"Hsig: {result.hsig.values}")
52+
53+
Example (Low-level API)
54+
-----------------------
55+
>>> from diwasp import dirspec, InstrumentData, SensorType
56+
>>> import numpy as np
57+
>>>
58+
>>> # Define sensor configuration manually
59+
>>> instrument = InstrumentData(
60+
... data=data,
61+
... layout=np.array([[0, 10, 0], [0, 0, 10], [10, 10, 10]]).T,
62+
... datatypes=[SensorType.PRES, SensorType.VELX, SensorType.VELY],
63+
... depth=20.0,
64+
... fs=2.0
65+
... )
66+
>>>
67+
>>> # Estimate spectrum for single window
68+
>>> spectrum, info = dirspec(instrument)
69+
>>> print(f"Hsig: {info.hsig:.2f} m")
70+
71+
References
72+
----------
73+
Main reference:
74+
Hashimoto, N. (1997) "Analysis of the directional wave spectrum from
75+
field data" in Advances in Coastal Engineering Vol. 3, World Scientific.
76+
77+
Original DIWASP:
78+
Johnson, D. (2002) DIWASP, a directional wave spectra toolbox for MATLAB:
79+
User Manual. Research Report WP-1601-DJ (V1.1), Centre for Water Research,
80+
University of Western Australia.
81+
"""
82+
83+
__version__ = "0.1.0"
84+
85+
# High-level wrapper
86+
from .wrapper import diwasp
87+
88+
# Core driver functions
89+
from .core import dirspec
90+
91+
# Data structures
92+
from .types import (
93+
EstimationMethod,
94+
EstimationParameters,
95+
InstrumentData,
96+
SensorType,
97+
SpectralInfo,
98+
SpectralMatrix,
99+
)
100+
101+
# Spectrum utilities
102+
from .spectrum import interpspec, make_wave_data, makespec
103+
104+
# Utility functions
105+
from .utils import (
106+
directional_spread,
107+
hsig,
108+
mean_direction,
109+
peak_direction,
110+
peak_frequency,
111+
wavenumber,
112+
)
113+
114+
__all__ = [
115+
# High-level wrapper
116+
"diwasp",
117+
# Core functions
118+
"dirspec",
119+
# Data structures
120+
"InstrumentData",
121+
"SpectralMatrix",
122+
"EstimationParameters",
123+
"SpectralInfo",
124+
# Enums
125+
"SensorType",
126+
"EstimationMethod",
127+
# Spectrum utilities
128+
"makespec",
129+
"interpspec",
130+
"make_wave_data",
131+
# Utility functions
132+
"wavenumber",
133+
"hsig",
134+
"peak_frequency",
135+
"peak_direction",
136+
"mean_direction",
137+
"directional_spread",
138+
]

0 commit comments

Comments
 (0)