MIKE 21 SW can output the full wave spectrum, not just integrated parameters such as Hm0. Those files are dfsu files with up to two extra axes, frequency and direction, and they come in three shapes:
point — the spectrum at a single position
line — spectra along a line crossing the domain
area — spectra at every element of a mesh
The geometry tells you which one you have, and is_spectral distinguishes these files from ordinary dfsu output.
import numpy as npimport mikeioda = mikeio.read("../data/spectra/pt_spectra.dfsu")[0]da
<mikeio.DataArray>
name: Point 1: Energy density
dims: (time:31, direction:16, frequency:25)
time: 2017-10-27 00:00:00 - 2017-10-27 05:00:00 (31 records)
geometry: Point Spectrum Geometry(frequency:25, direction:16)
da.dims
('time', 'direction', 'frequency')
The frequency and direction axes are on the geometry:
Plotting a point spectrum gives a polar plot of the first time step:
da.plot();
plot.pcolormesh takes the same arguments and returns the matplotlib axes, so the plot can be adjusted with matplotlib — here the radial limit is capped and the spokes labelled with the actual direction values:
MIKE 21 SW can discretise directions over a sector rather than the full circle. Such files are read the same way, and the plot covers only the sector:
da = mikeio.read("../data/spectra/MIKE21SW_dir_sector_area_spectra.dfsu", time=0)["Energy density"]ax = da.isel(element=0).plot(vmin=0)ax.set_rmax(10);
Frequency and direction spectra
A file need not carry both axes. Frequency spectra have no directions, and directional spectra have no frequencies; n_frequencies and n_directions report which case you are in, one of them being zero.
da = mikeio.read("../data/spectra/pt_freq_spectra.dfsu")[0]da.geometry.n_frequencies, da.geometry.n_directions
(25, 0)
With no directions to plot around a circle, the plot becomes an ordinary spectrum against frequency:
da.sel(time="2017-10-27 02:00").plot();
The reverse case, a directional spectrum with no frequency axis:
da = mikeio.read("../data/spectra/line_dir_spectra.dfsu")[0]da.geometry.n_frequencies, da.geometry.n_directions