wavespectra

An open source project for working with ocean wave spectral data.
https://github.com/wavespectra/wavespectra

Category: Hydrosphere
Sub Category: Waves and Currents

Keywords

coastal-engineering data-analysis ocean ocean-sciences ocean-waves oceanography python spectra statistics wave wave-modelling wave-spectra xarray

Keywords from Contributors

mesh vtk

Last synced: 2 days ago
JSON representation

Repository metadata

Library for ocean wave spectra

README.rst

          ===========
wavespectra
===========

.. image:: https://deepwiki.com/badge.svg
   :target: https://deepwiki.com/wavespectra/wavespectra
   :alt: Ask DeepWiki

.. image:: https://zenodo.org/badge/205463939.svg
   :target: https://zenodo.org/badge/latestdoi/205463939
   :alt: DOI

.. image:: https://img.shields.io/github/actions/workflow/status/wavespectra/wavespectra/testing.yml?branch=main
   :target: https://github.com/wavespectra/wavespectra/actions
   :alt: Build Status

.. image:: https://coveralls.io/repos/github/wavespectra/wavespectra/badge.svg?branch=main
   :target: https://coveralls.io/github/wavespectra/wavespectra?branch=main
   :alt: Coverage

.. image:: https://readthedocs.org/projects/wavespectra/badge/?version=latest
   :target: https://wavespectra.readthedocs.io/en/latest/
   :alt: Documentation

.. image:: https://img.shields.io/pypi/v/wavespectra.svg
   :target: https://pypi.org/project/wavespectra/
   :alt: PyPI

.. image:: https://img.shields.io/pypi/dm/wavespectra
   :target: https://pypistats.org/packages/wavespectra
   :alt: Downloads

.. image:: https://anaconda.org/conda-forge/wavespectra/badges/version.svg
   :target: https://anaconda.org/conda-forge/wavespectra
   :alt: Conda

.. image:: https://img.shields.io/pypi/pyversions/wavespectra
   :target: https://pypi.org/project/wavespectra/
   :alt: Python

**Python library for ocean wave spectral data analysis and processing**

Wavespectra is a powerful, open-source Python library built on top of `xarray`_ for working with ocean wave spectral data. It provides comprehensive tools for reading, analysing, manipulating, and visualising wave spectra from various sources including numerical models and buoy observations.

.. _xarray: https://xarray.pydata.org/

Key Features
============

- **Unified Data Model**: Built on xarray with standardised conventions for wave spectral data
- **Extensive I/O Support**: Read/write 15+ formats including WW3, SWAN, ERA5, NDBC, and more
- **Rich Analysis Tools**: 60+ methods for wave parameter calculation and spectral transformations
- **Spectral Partitioning**: Separate wind sea and swell using multiple algorithms (PTM1-PTM5, HP01, wave age)
- **Spectral Construction**: Create synthetic spectra using parametric forms (JONSWAP, TMA, Gaussian, Pierson-Moskowitz)
- **Flexible Visualisation**: Polar spectral plots with matplotlib integration
- **High Performance**: Leverages dask for efficient processing of large datasets
- **Extensible**: Plugin architecture for custom readers and analysis methods

Quick Start
===========

Installation
------------

Install from PyPI:

.. code-block:: console

   # Basic installation
   $ pip install wavespectra

   # Full installation with all optional dependencies
   $ pip install wavespectra[extra]

Or from conda-forge:

.. code-block:: console

   $ conda install -c conda-forge wavespectra

Basic Usage
-----------

.. code-block:: python

   import xarray as xr
   from wavespectra import read_swan

   # Read wave spectra from various formats
   dset = read_swan("spectra.spec")  # SWAN format
   # dset = xr.open_dataset("era5.nc", engine="era5")  # ERA5 reanalysis
   # dset = xr.open_dataset("ww3.nc", engine="ww3")    # WAVEWATCH III

   # Calculate wave parameters
   hs = dset.spec.hs()          # Significant wave height
   tp = dset.spec.tp()          # Peak period
   dm = dset.spec.dm()          # Mean direction
   dspr = dset.spec.dspr()      # Directional spreading

   # Multiple parameters at once
   stats = dset.spec.stats(["hs", "tp", "dm", "dspr"])

   # Spectral transformations
   spectrum_1d = dset.spec.oned()                    # Convert to 1D
   subset = dset.spec.split(fmin=0.05, fmax=0.5)     # Frequency subset
   rotated = dset.spec.rotate(angle=15)              # Rotate directions
   interpolated = dset.spec.interp(freq=new_freq)    # Interpolate

   # Visualisation
   dset.spec.plot(kind="contourf", figsize=(8, 6))   # Polar plot

Working with Different Data Sources
-----------------------------------

.. code-block:: python

   # Numerical model outputs
   ww3_data = xr.open_dataset("ww3_output.nc", engine="ww3")
   swan_data = read_swan("swan_output.swn")
   era5_data = xr.open_dataset("era5_waves.nc", engine="era5")

   # Buoy observations
   ndbc_data = xr.open_dataset("ndbc_data.nc", engine="ndbc")
   triaxys_data = xr.open_dataset("triaxys.nc", engine="triaxys")

   # All use the same analysis interface
   for dataset in [ww3_data, swan_data, era5_data]:
       hs = dataset.spec.hs()
       tp = dataset.spec.tp()

Advanced Analysis
-----------------

Spectral Partitioning
~~~~~~~~~~~~~~~~~~~~~

Separate spectra into wind sea and swell components using various methods:

.. code-block:: python

   # PTM1: Watershed partitioning with wind sea identification
   partitions = dset.spec.partition.ptm1(
       wspd=dset.wspd, wdir=dset.wdir, dpt=dset.dpt, swells=2
   )
   
   # PTM3: Simple ordering by wave height (no wind/depth needed)
   partitions = dset.spec.partition.ptm3(parts=3)
   
   # PTM4: Wave age criterion to separate wind sea from swell
   partitions = dset.spec.partition.ptm4(
       wspd=dset.wspd, wdir=dset.wdir, dpt=dset.dpt, agefac=1.7
   )
   
   # PTM1_TRACK: Track partitions from unique wave systems over time
   # Useful for following the evolution of individual swell events
   partitions = dset.spec.partition.ptm1_track(
       wspd=dset.wspd, wdir=dset.wdir, dpt=dset.dpt, swells=2
   )

Spectral Construction
~~~~~~~~~~~~~~~~~~~~~

Create synthetic spectra from parametric forms:

.. code-block:: python

   import numpy as np

   from wavespectra.construct.frequency import jonswap, tma, gaussian
   from wavespectra.construct.direction import cartwright
   from wavespectra.construct import construct_partition
   
   # Create JONSWAP spectrum for developing seas
   freq = np.arange(0.03, 0.4, 0.01)
   spectrum = jonswap(freq=freq, hs=2.5, fp=0.1, gamma=3.3)
   
   # Create TMA spectrum for finite depth
   spectrum_shallow = tma(freq=freq, hs=2.0, fp=0.1, dep=15)
   
   # Create 2D spectrum by combining frequency and directional components
   dir = np.arange(0, 360, 10)
   spectrum_2d = jonswap(freq=freq, hs=2.5, fp=0.1) * cartwright(dir=dir, dm=270, dspr=30)
   
   # Or use construct_partition for a complete 2D spectrum
   spectrum_2d = construct_partition(
       freq_name="jonswap",
       dir_name="cartwright",
       freq_kwargs={"freq": freq, "hs": 2.5, "fp": 0.1, "gamma": 3.3},
       dir_kwargs={"dir": dir, "dm": 270, "dspr": 30}
   )

Spectral Fitting
~~~~~~~~~~~~~~~~

.. code-block:: python

   # Fit parametric forms to existing spectra
   jonswap_params = dset.spec.fit_jonswap()          # Fit JONSWAP spectrum

Wave Physics
~~~~~~~~~~~~

.. code-block:: python

   # Calculate wave physics parameters
   celerity = dset.spec.celerity(depth=50)           # Wave speed
   wavelength = dset.spec.wavelen(depth=50)          # Wavelength
   stokes_drift = dset.spec.uss()                    # Stokes drift


Data Requirements
=================

Wavespectra expects xarray objects with specific coordinate and variable naming:

**Required coordinates:**

- ``freq``: Wave frequency in Hz
- ``dir``: Wave direction in degrees (for 2D spectra)

**Required variables:**

- ``efth``: Wave energy density in m²/Hz/degree (2D) or m²/Hz (1D)

**Optional variables:**

- ``wspd``: Wind speed in m/s
- ``wdir``: Wind direction in degrees
- ``dpt``: Water depth in metres

Supported Formats
=================

Input and Output Formats
------------------------

- **Wave Models**: WAVEWATCH III, SWAN, WWM, FUNWAVE, OrcaFlex
- **Reanalysis**: ERA5, ERA-Interim, ECMWF
- **Observations**: NDBC, TRIAXYS, Spotter, Datawell, Obscape, AWAC, Octopus
- **Generic**: NetCDF, Zarr, JSON

Documentation
=============

Full documentation is available at `wavespectra.readthedocs.io`_

- `Installation Guide`_
- `Quick Start Tutorial`_
- `Spectral Construction`_
- `API Reference`_
- `Example Gallery`_

.. _wavespectra.readthedocs.io: https://wavespectra.readthedocs.io/en/latest/
.. _Installation Guide: https://wavespectra.readthedocs.io/en/latest/install.html
.. _Quick Start Tutorial: https://wavespectra.readthedocs.io/en/latest/quickstart.html
.. _Spectral Construction: https://wavespectra.readthedocs.io/en/latest/construction.html
.. _API Reference: https://wavespectra.readthedocs.io/en/latest/api.html
.. _Example Gallery: https://wavespectra.readthedocs.io/en/latest/gallery.html

Development
===========

Contributing
------------

We welcome contributions! Please see our `Contributing Guide`_ for details.

.. _Contributing Guide: https://wavespectra.readthedocs.io/en/latest/contributing.html

Development Installation
------------------------

.. code-block:: console

   $ git clone https://github.com/wavespectra/wavespectra.git
   $ cd wavespectra
   $ pip install -e .[extra,test,docs]

Running Tests
-------------

.. code-block:: console

   $ pytest tests

Building Documentation
----------------------

.. code-block:: console

   $ make docs

Citation
========

If you use wavespectra in your research, please cite:

.. code-block:: bibtex

   @software{wavespectra,
     author = {Guedes, Rafael and Durrant, Tom and de Bruin, Ruben and Perez, Jorge and Iannucci, Matthew and Delaux, Sebastien and Harrington, John and others},
     title = {wavespectra: Python library for ocean wave spectral data},
     url = {https://github.com/wavespectra/wavespectra},
     doi = {10.5281/zenodo.15238968}
   }

Licence
=======

This project is licenced under the MIT Licence - see the `LICENSE`_ file for details.

.. _LICENSE: LICENSE.txt

Support
=======

- **Documentation**: `wavespectra.readthedocs.io`_
- **Issues**: `GitHub Issues`_
- **Discussions**: `GitHub Discussions`_

.. _GitHub Issues: https://github.com/wavespectra/wavespectra/issues
.. _GitHub Discussions: https://github.com/wavespectra/wavespectra/discussions

        

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 5 days ago

Total Commits: 1,608
Total Committers: 21
Avg Commits per committer: 76.571
Development Distribution Score (DDS): 0.105

Commits in past year: 79
Committers in past year: 2
Avg Commits per committer in past year: 39.5
Development Distribution Score (DDS) in past year: 0.013

Name Email Commits
Rafael Guedes r****s@o****e 1439
Tom Durrant t****t@g****m 34
Ruben de Bruin 3****n 29
metocean-jorge.perez j****z@m****z 24
d.johnson@metocean.co.nz d****n@m****z 18
Matthew Iannucci m****i@g****m 17
Sebastien Delaux s****x@o****e 11
John Harrington j****n@j****m 7
Ryan Coe r****e@s****v 6
Paul Branson p****n@c****u 6
Dave d****n@o****e 4
Henrique Rapizo h****o@m****z 2
dependabot[bot] 4****] 2
Ruben de Bruin r****n@h****m 2
Murex93 s****n@l****a 1
Spicer Bak 8****F 1
Vincent Gao g****0@g****m 1
cmichelenstrofer c****l@s****v 1
gregchalmers g****s@m****z 1
Color Code c****e@l****m 1
lubyant b****8@w****u 1

Committer domains:


Issue and Pull Request metadata

Last synced: about 20 hours ago

Total issues: 87
Total pull requests: 83
Average time to close issues: 9 months
Average time to close pull requests: about 2 months
Total issue authors: 39
Total pull request authors: 12
Average comments per issue: 2.64
Average comments per pull request: 1.61
Merged pull request: 73
Bot issues: 0
Bot pull requests: 2

Past year issues: 3
Past year pull requests: 13
Past year average time to close issues: about 1 month
Past year average time to close pull requests: about 10 hours
Past year issue authors: 3
Past year pull request authors: 1
Past year average comments per issue: 4.33
Past year average comments per pull request: 0.15
Past year merged pull request: 13
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/wavespectra/wavespectra

Top Issue Authors

  • rafa-guedes (28)
  • RubendeBruin (8)
  • Taddei-S (4)
  • ryancoe (4)
  • guin0x (4)
  • cmichelenstrofer (2)
  • salman451 (2)
  • tomdurrant (2)
  • DrakonianMight (2)
  • LWCAO (2)
  • JohnCHarrington (1)
  • mpiannucci (1)
  • dirkpir (1)
  • VincentWervingsdagen (1)
  • daniel-caichac-DHI (1)

Top Pull Request Authors

  • rafa-guedes (49)
  • RubendeBruin (14)
  • seboceanum (4)
  • JohnCHarrington (3)
  • tomdurrant (3)
  • lubyant (2)
  • dependabot[bot] (2)
  • Murex93 (2)
  • cmichelenstrofer (1)
  • mpiannucci (1)
  • ryancoe (1)
  • davemetocean (1)

Top Issue Labels

  • enhancement (11)
  • help wanted (5)
  • bug (5)
  • testing (2)
  • dependencies (2)
  • documentation (1)
  • question (1)

Top Pull Request Labels

  • dependencies (2)
  • enhancement (1)

Package metadata

proxy.golang.org: github.com/wavespectra/wavespectra

pypi.org: wavespectra

Library for ocean wave spectra

  • Homepage:
  • Documentation: https://wavespectra.readthedocs.io/en/latest/
  • Licenses: MIT License
  • Latest release: 4.5.0 (published about 2 months ago)
  • Last Synced: 2026-07-25T23:01:21.955Z (11 days ago)
  • Versions: 61
  • Dependent Packages: 2
  • Dependent Repositories: 5
  • Downloads: 3,806 Last month
  • Docker Downloads: 122
  • Rankings:
    • Docker downloads count: 2.607%
    • Dependent packages count: 4.781%
    • Dependent repos count: 6.609%
    • Average: 7.064%
    • Forks count: 8.381%
    • Stargazers count: 9.822%
    • Downloads: 10.181%
  • Maintainers (1)
conda-forge.org: wavespectra

Wavespectra is an open source project for working with ocean wave spectral data. The library is built on top of xarray, leveraging from xarray’s labelled multi-dimensional arrays and making dealing with wave spectra simple and fast..

  • Homepage: https://github.com/wavespectra/wavespectra
  • Licenses: MIT
  • Latest release: 3.12.1 (published almost 4 years ago)
  • Last Synced: 2026-04-01T13:29:40.111Z (4 months ago)
  • Versions: 5
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Downloads: 236,350 Total
  • Rankings:
    • Dependent repos count: 24.397%
    • Dependent packages count: 28.983%
    • Average: 34.584%
    • Forks count: 40.217%
    • Stargazers count: 44.738%

Dependencies

setup.py pypi
  • attrdict *
  • click *
  • cmocean *
  • dask *
  • hypothesis *
  • matplotlib *
  • numba *
  • numpy <=1.21
  • pandas *
  • python-dateutil *
  • pyyaml *
  • scipy *
  • sortedcontainers *
  • toolz *
  • xarray *
.github/workflows/python-publish.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • pypa/gh-action-pypi-publish v1.6.4 composite
pyproject.toml pypi
  • click *
  • cmocean *
  • dask *
  • matplotlib *
  • numba *
  • numpy *
  • pandas *
  • python-dateutil *
  • pyyaml *
  • scipy *
  • sortedcontainers *
  • toolz *
  • typing_extensions *
  • xarray *
Dockerfile docker
  • ubuntu 22.04 build
.github/workflows/testing.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite

Score: 20.070281733068036