Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9ed367f
Added 1D and 2D wave spectrum
SChristineP Aug 5, 2025
dfb05c2
Updated code block
SChristineP Aug 5, 2025
a28737e
Added Diana spectrum
SChristineP Aug 5, 2025
83d8e5e
Merge branch 'MET-OM:main' into main
SChristineP Aug 5, 2025
0c11c51
Added wave spectra averaged by peak direction
SChristineP Aug 6, 2025
a8bea61
update spectra module
SChristineP Aug 6, 2025
3637188
Delete metocean_stats/__pycache__ directory
SChristineP Aug 6, 2025
93fed6b
Delete metocean_stats/plots/__pycache__ directory
SChristineP Aug 6, 2025
b90888b
Delete metocean_stats/stats/__pycache__ directory
SChristineP Aug 6, 2025
ba9898c
Delete metocean_stats/tables/__pycache__ directory
SChristineP Aug 6, 2025
d7d8ae2
Merge branch 'main' of https://github.com/SChristineP/metocean-stats
SChristineP Aug 6, 2025
6268512
Updated index. Added monthly mean wave spectra 2d
SChristineP Aug 7, 2025
915cede
Updated index
SChristineP Aug 7, 2025
670b615
Updated index
SChristineP Aug 7, 2025
4116bd6
Changed title of peak direction spectra
SChristineP Aug 7, 2025
de75e04
Updated Diana plot in index
SChristineP Aug 11, 2025
ca8c9d4
Diana plot modified
SChristineP Aug 11, 2025
b46bbca
Diana plot
SChristineP Aug 11, 2025
ced624e
Updated function names
SChristineP Aug 11, 2025
8c34397
Scripts for spectra functions
SChristineP Aug 11, 2025
40b94eb
Updated tables, environment, dir, figures, synthetic_dataset and index.
SChristineP Aug 13, 2025
bb6f1c4
Minor change spectra table
SChristineP Aug 13, 2025
74833c2
Updated index
SChristineP Aug 13, 2025
b2760ba
Updated code block
SChristineP Aug 13, 2025
f0d2b3a
Updated code block
SChristineP Aug 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed docs/files/Spectrum_plot.png
Binary file not shown.
Binary file added docs/files/wave_spectra_2d_direction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/files/wave_spectra_2d_monthly_mean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/files/wave_spectrum_1d_month.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/files/wave_spectrum_1d_months.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/files/wave_spectrum_2d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/files/wave_spectrum_diana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 96 additions & 10 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1576,22 +1576,108 @@ CCA profiles Table
:header-rows: 1
:file: files/table_cca_profiles.csv

Directional Wave Energy Spectrum Plot

Wave Spectrum Plots
-----------------------------------------

Monthly Mean 1D Wave Spectrum

.. code-block:: python

plots.plot_spectra_1d(
data,
var = 'SPEC',
period = None,
month = None,
method = 'mean',
output_file = 'wave_spectrum_1d_months.png'
)

.. image:: files/wave_spectrum_1d_months.png
:width: 500

1D Spectrum Mean for a Specific Month Across Several Years

.. code-block:: python

plots.plot_spectra_1d(
data,
var = 'SPEC',
period = None,
month = 1,
method = 'mean',
output_file = 'wave_spectrum_1d_month.png'
)

.. image:: files/wave_spectrum_1d_month.png
:width: 500

2D Wave Spectrum at Time of Maximum Hm0 in Selected Period

.. code-block:: python

plots.plot_spectrum_2d(
data,
var = 'SPEC',
period = ('2021-01-01T00', '2024-12-31T23'),
month = None,
method = 'hm0_max',
plot_type = 'pcolormesh',
output_file = 'wave_spectrum_2d.png'
)

.. image:: files/wave_spectrum_2d.png
:width: 500

Diana Wave Spectrum with Swell and Windsea Partitions, Averaged Over Times with Hm0 ≥ 99th Percentile

.. code-block:: python

plots.plot_diana_spectrum(
data,
var = 'SPEC',
period = ('2022-01-01T00', '2022-07-31T23'),
month = None,
method = 'top_1_percent_mean',
partition=True,
plot_type = 'pcolormesh'
freq_mask=True,
output_file = 'wave_spectrum_diana.png'
)

.. image:: files/wave_spectrum_diana.png
:width: 500

2D Monthly Mean Wave Spectra

.. code-block:: python

plots.plot_spectra_2d(
data,
var = 'SPEC',
method = 'mean',
plot_type = 'contour',
cbar = 'multiple',
output_file = 'wave_spectra_2d_monthly_mean.png'
)

.. image:: files/wave_spectra_2d_monthly_mean.png
:width: 500

Directional Wave Spectra Averaged by Peak Wave Direction in 30° Sectors

.. code-block:: python

plots.plot_spectrum(
spectrum,
frequencies,
directions,
spec_unit='m**2 s',
radius='frequency',
log_radius=False,
output_file='Spectrum_plot.png')
plots.plot_spectra_2d(
data,
var = 'SPEC',
method = 'direction'
plot_type = 'contour',
cbar = 'single',
output_file = 'wave_spectra_2d_direction.png'
)

.. image:: files/Spectrum_plot.png
.. image:: files/wave_spectra_2d_direction.png
:width: 500

Tidal Levels Table
Expand Down
4 changes: 3 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ dependencies:
- netcdf4
- pydap
- setuptools
- virocon
- metpy
- virocon

Binary file removed metocean_stats/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions metocean_stats/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
from .extreme import *
from .general import *
from .verification import *
from .spectra import *
Binary file not shown.
Binary file removed metocean_stats/plots/__pycache__/dir.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
79 changes: 0 additions & 79 deletions metocean_stats/plots/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,82 +138,3 @@ def monthly_var_rose(data,
return fig


def plot_spectrum_2d(ds, var='SPEC', radius='frequency', log_radius=False, plot_type='contourf', dir_letters=False, output_file='Spectrum_plot.png'):
'''
This function plots a directional wave spectrum

Parameters
----------
ds : xarray dataset
Should contain variable var with two (frequencies, directions).
var : string
Name of the spectrum variable
radius : string
Should be 'period'/'frequency' to plot the periods/frequencies in the radial direction
log_radius : Boolean
True to get the radial axis on a logarithmic scale
plot_type : string
Can be 'pcolormesh' or 'contourf'
dir_letters : Boolean
Displays the directions as letters instead of degrees if True'
output_file : string
Name of the figure file (xxx.pdf or xxx.png)

Returns
-------
Figure matplotlib

Authors
-------
Function written by clio-met
'''
spectrum=ds[var]
dims=list(spectrum.dims)
# Get the coordinates
frequencies=spectrum.coords[dims[0]].to_numpy()
directions=spectrum.coords[dims[1]].to_numpy()
# The last direction should be the same as the first
if directions[0]!=directions[-1]:
if directions[0]<360:
dirc=np.concatenate([directions,directions[0:1]+360])
else:
dirc=np.concatenate([directions,directions[0:1]])
spec=np.concatenate([spectrum[:,:],spectrum[:,0:1]],axis=1)

# Color map with 10 colors
cmap = mpl.cm.hot_r(np.linspace(0,1,10))
cmap = mpl.colors.ListedColormap(cmap)

fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
ax.set_theta_zero_location('N')
ax.set_theta_direction(-1)
if radius=='period':
rad_data=1/frequencies
elif radius=='frequency':
rad_data=frequencies

if plot_type=='pcolormesh':
c=ax.pcolormesh(np.radians(dirc), rad_data, spec, cmap='hot_r', shading='auto')
elif plot_type=='contourf':
c=ax.contourf(np.radians(dirc), rad_data, spec, cmap=cmap)
else:
print('plot_type should pcolormesh or contourf')
sys.exit()

ax.grid(True)
if log_radius==True:
ax.set_rscale('log')
#ax.set_rlim(0,10)
if dir_letters==True:
ticks_loc = ax.get_xticks().tolist()
ax.xaxis.set_major_locator(mticker.FixedLocator(ticks_loc))
ax.set_xticklabels(['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'])
plt.colorbar(c, label='['+spectrum.units+']', pad=0.1)
plt.tight_layout()
if output_file is not None:
plt.savefig(output_file, dpi=200, bbox_inches='tight')
plt.close()

return fig


Loading
Loading