Data Structures#
DIWASP uses three main data structures to manage input and output data:
InstrumentData - Contains the sensor layout, types, and measured data
SpectralMatrix - Contains the output directional spectrum
EstimationParameters - Contains configuration for the estimation method
InstrumentData#
The InstrumentData class contains all information about the instrument sensors and the measured data.
Fields#
Field |
Type |
Description |
|---|---|---|
|
ndarray |
Measured wave data matrix [n_samples x n_sensors] |
|
ndarray |
Sensor positions [3 x n_sensors] as (x, y, z) where z is elevation from seabed (m) |
|
list[SensorType] |
List of sensor types, one per column of data |
|
float |
Mean overall depth of measurement area (m) |
|
float |
Sampling frequency (Hz) - must be same for all sensors |
Sensor Types#
The following sensor types are supported:
Type |
Description |
|---|---|
|
Surface elevation |
|
Pressure |
|
X component velocity |
|
Y component velocity |
|
Z component velocity |
|
Vertical velocity of surface |
|
Vertical acceleration of surface |
|
X component surface slope |
|
Y component surface slope |
|
X component acceleration |
|
Y component acceleration |
|
Z component acceleration |
|
X displacement |
|
Y displacement |
Example: Pressure Gauge Array#
For three pressure gauges spread in a triangle on the sea floor:
from diwasp import InstrumentData, SensorType
import numpy as np
# Sensor data [n_samples x 3]
data = np.loadtxt('pressure_data.csv')
# Layout: x, y, z coordinates for each sensor
# Positions: [0,0], [5,5], [-5,5] with all sensors on seabed
layout = np.array([
[0.0, 5.0, -5.0], # x coordinates
[0.0, 5.0, 5.0], # y coordinates
[0.0, 0.0, 0.0] # z coordinates (seabed)
])
datatypes = [SensorType.PRES, SensorType.PRES, SensorType.PRES]
instrument = InstrumentData(
data=data,
layout=layout,
datatypes=datatypes,
depth=10.0,
fs=2.0
)
Example: PUV (Pressure + Velocity) Sensor#
For a directional current meter and pressure sensor mounted 0.5m above the seabed:
# All sensors at same location
layout = np.array([
[0.0, 0.0, 0.0], # x coordinates
[0.0, 0.0, 0.0], # y coordinates
[0.5, 0.5, 0.5] # z coordinates (0.5m above seabed)
])
datatypes = [SensorType.VELX, SensorType.VELY, SensorType.PRES]
instrument = InstrumentData(
data=data,
layout=layout,
datatypes=datatypes,
depth=10.0,
fs=2.0
)
Creating from xarray Dataset#
import xarray as xr
# Create dataset with sensor data
ds = xr.Dataset({
'pressure': (['time'], pressure_data, {'sensor_type': 'pres', 'x': 0, 'y': 0, 'z': 0.5}),
'vel_x': (['time'], velx_data, {'sensor_type': 'velx', 'x': 0, 'y': 0, 'z': 0.5}),
'vel_y': (['time'], vely_data, {'sensor_type': 'vely', 'x': 0, 'y': 0, 'z': 0.5}),
})
instrument = InstrumentData.from_xarray(ds, depth=10.0, fs=2.0)
SpectralMatrix#
The SpectralMatrix class contains the directional wave spectrum.
Fields#
Field |
Type |
Description |
|---|---|---|
|
ndarray |
Frequency bin centers (Hz) |
|
ndarray |
Direction bin centers (degrees) |
|
ndarray |
Spectral density matrix [n_freqs x n_dirs] in m^2/(Hz*degree) |
|
float |
Compass direction of x-axis (default 90 = East) |
|
str |
Frequency units: ‘hz’ or ‘rad/s’ |
|
str |
Direction units: ‘cart’ (Cartesian) or ‘naut’ (nautical) |
Direction Convention#
Directions are measured anticlockwise from the positive x-axis in Cartesian convention (dunit='cart'). The xaxisdir field defines the compass direction of the x-axis.
y
N ^
^ | Wave component
| | traveling at +30 deg
| +--------> x
With xaxisdir=90, the x-axis points East.
For nautical convention (dunit='naut'), directions are the compass bearing that waves are coming FROM.
Converting to xarray#
The spectrum can be converted to an xarray Dataset compatible with wavespectra:
ds = spectrum.to_xarray()
# Access the spectral density
efth = ds['efth'] # Energy density variable
Spectral Density Units#
The spectral density S is in units of m^2/(Hz*degree). To convert to component wave amplitudes:
a_ij = sqrt(2 * S_ij * df * ddir)
where df is the frequency bin width and ddir is the direction bin width.
EstimationParameters#
The EstimationParameters class configures the spectrum estimation.
Fields#
Field |
Type |
Default |
Description |
|---|---|---|---|
|
EstimationMethod |
IMLM |
Estimation algorithm |
|
int or None |
None |
FFT length (auto-calculated if None) |
|
int |
180 |
Directional resolution (bins for full circle) |
|
int |
100 |
Number of iterations for iterative methods |
|
bool |
True |
Apply spectral smoothing |
Example#
from diwasp import EstimationParameters, EstimationMethod
# Use BDM method with higher directional resolution
params = EstimationParameters(
method=EstimationMethod.BDM,
dres=360,
iter=150,
smooth=True
)
SpectralInfo#
The SpectralInfo class contains statistics computed from a directional spectrum.
Fields#
Field |
Type |
Description |
|---|---|---|
|
float |
Significant wave height (m) |
|
float |
Peak period (s) |
|
float |
Peak frequency (Hz) |
|
float |
Peak direction (deg) |
|
float |
Mean direction (deg) |
|
float |
Directional spread (deg) |