{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Directional Wave Spectrum from NDBC Buoys\n", "\n", "Some NDBC buoys measure the full directional wave spectrum. \n", "A directional wave spectrum $S(f,\\theta)$ contains the sea elevation information over all different directions. \n", "This can be used, for instance, to (1) reconstruct a sea surface elevation time-history over some area (as opposed to at just one point), or (2) to calculate the effect of wave loads on a non-axissymetric structure. \n", "It is constructed from the omnidirectional spectrum $S(f)$ and a spread function $D(f, \\theta)$ as\n", "\n", "$$\n", "S(f, \\theta) = S(f)D(f, \\theta).\n", "$$ \n", "\n", "NDBC stores this information in 5 parameters, each stored in a different file. One parameter (`swden`) is simply the omnidirectional spectrum, while the other 4 (`swdir`, `swdir2`, `swr1`, `swr2`) are used to reconstruct the spread function. For more information on the the parameters and reconstruction see the *Spectral Wave Data* section in [this NDBC site](https://www.ndbc.noaa.gov/measdes.shtml).\n", "\n", "In this example we will: \n", "* check if a specific buoy has directional information and request that data\n", "* reconstruct and plot the directional wave spectrum $S(f, \\theta)$\n", "* take a deeper look at the omnidirectional spectrum $S(f)$ and spread function $D(f, \\theta)$ separately\n", "* calculate and plot the energy spectrum\n", "\n", "We use functions from both the `wave.io.ndbc` and `wave.graphics` submodules. We start by importing `numpy` and MHKiT's `wave` module. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from mhkit import wave" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Request Data\n", "First, we will check if the buoy we're interested in–42012—has directional data. To do this we use the `wave.io.ndbc.available_data` function with any one of the 4 parameters used for the spread function. \n", "We can see that this buoy does have directional data for the years 2009-2021." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | id | \n", "year | \n", "filename | \n", "
---|---|---|---|
312 | \n", "42012 | \n", "2009 | \n", "42012d2009.txt.gz | \n", "
313 | \n", "42012 | \n", "2010 | \n", "42012d2010.txt.gz | \n", "
314 | \n", "42012 | \n", "2011 | \n", "42012d2011.txt.gz | \n", "
315 | \n", "42012 | \n", "2012 | \n", "42012d2012.txt.gz | \n", "
316 | \n", "42012 | \n", "2013 | \n", "42012d2013.txt.gz | \n", "
317 | \n", "42012 | \n", "2014 | \n", "42012d2014.txt.gz | \n", "
318 | \n", "42012 | \n", "2015 | \n", "42012d2015.txt.gz | \n", "
319 | \n", "42012 | \n", "2016 | \n", "42012d2016.txt.gz | \n", "
320 | \n", "42012 | \n", "2017 | \n", "42012d2017.txt.gz | \n", "
321 | \n", "42012 | \n", "2018 | \n", "42012d2018.txt.gz | \n", "
322 | \n", "42012 | \n", "2019 | \n", "42012d2019.txt.gz | \n", "
323 | \n", "42012 | \n", "2020 | \n", "42012d2020.txt.gz | \n", "
324 | \n", "42012 | \n", "2021 | \n", "42012d2021.txt.gz | \n", "
<xarray.Dataset>\n", "Dimensions: (date: 8572, frequency: 47)\n", "Coordinates:\n", " * date (date) datetime64[ns] 2021-01-01T00:40:00 ... 2021-12-31T23:40:00\n", " * frequency (frequency) float64 0.02 0.0325 0.0375 ... 0.445 0.465 0.485\n", "Data variables:\n", " swden (date, frequency) float64 0.0 0.0 0.0 0.0 ... 0.01 0.01 0.02 0.0\n", " swdir (date, frequency) float64 194.0 13.0 6.0 ... 173.0 167.0 159.0\n", " swdir2 (date, frequency) float64 191.0 11.0 9.0 ... 178.0 169.0 106.0\n", " swr1 (date, frequency) float64 0.16 0.26 0.21 0.41 ... 0.76 0.87 0.63\n", " swr2 (date, frequency) float64 0.99 0.93 0.9 0.84 ... 0.28 0.67 0.1
<xarray.DataArray (frequency: 47, direction: 180)>\n", "array([[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,\n", " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n", " [0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,\n", " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n", " [0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,\n", " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n", " ...,\n", " [2.21512935e-04, 3.00007246e-04, 3.89537948e-04, ...,\n", " 4.78972678e-05, 9.59294370e-05, 1.53638415e-04],\n", " [5.05171904e-04, 5.68137407e-04, 6.34119449e-04, ...,\n", " 3.34637188e-04, 3.88407564e-04, 4.45255232e-04],\n", " [2.26590428e-04, 2.84552135e-04, 3.45964024e-04, ...,\n", " 7.35307830e-05, 1.21080223e-04, 1.72097824e-04]])\n", "Coordinates:\n", " * frequency (frequency) float64 0.02 0.0325 0.0375 ... 0.445 0.465 0.485\n", " * direction (direction) float64 0.0 2.0 4.0 6.0 ... 352.0 354.0 356.0 358.0\n", "Attributes:\n", " units: m^2/Hz/deg\n", " long_name: Elevation variance spectrum\n", " standard_name: spectrum\n", " description: *Elevation variance (m^2)* spectrum (/Hz/deg).