.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_gallery/plot_cdip.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_gallery_plot_cdip.py: Using real time CDIP data ========================= This example shows how to compute the directional wave spectrum from waverider wave buoys data obtained from CDIP dataset in real time. .. GENERATED FROM PYTHON SOURCE LINES 11-23 .. code-block:: Python # import the dependencies import numpy as np import xarray as xr from matplotlib import pyplot as plt import ewdm from ewdm.sources import CDIPDataSourceRealTime from ewdm.plots import plot_directional_spectrum .. GENERATED FROM PYTHON SOURCE LINES 24-27 Let's download 30-min time series from Ocean Station Papa Buoy - 166p1. In this case, the buoy captures the wave-induced hortizonal $x(t)$, $y(t)$, and vertical displacements $\eta(t)$. .. GENERATED FROM PYTHON SOURCE LINES 27-45 .. code-block:: Python cdip = CDIPDataSourceRealTime(166) dataset = cdip.read_dataset( time_start="2024-06-09T08:30", time_end="2024-06-09T09:00" ) print(dataset) # plot time series of the first 5 minutes fig, (ax1, ax2, ax3) = plt.subplots( 3,1, figsize=(6,6), sharex=True, sharey=True ) subset = dataset.sel(time=slice("2024-06-09T08:30", "2024-06-09T08:35")) subset["surface_elevation"].plot(ax=ax1) subset["eastward_displacement"].plot(ax=ax2) subset["northward_displacement"].plot(ax=ax3) _ = ax1.set(xlabel="", ylabel="$\\eta(t)$ [m]") _ = ax2.set(xlabel="", ylabel="$x(t)$ [m]") _ = ax3.set(xlabel="", ylabel="$y(t)$ [m]") .. image-sg:: /auto_gallery/images/sphx_glr_plot_cdip_001.png :alt: plot cdip :srcset: /auto_gallery/images/sphx_glr_plot_cdip_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Size: 46kB Dimensions: (time: 2304) Coordinates: * time (time) datetime64[ns] 18kB 2024-06-09T08:30:00 ..... Data variables: eastward_displacement (time) float32 9kB -1.49 -1.27 -0.53 ... 0.33 0.5 northward_displacement (time) float32 9kB 1.05 0.66 0.08 ... 0.05 0.42 0.77 surface_elevation (time) float32 9kB 0.03 -0.73 -1.41 ... 0.87 1.35 Attributes: (12/71) sampling_rate: 1.28 naming_authority: edu.ucsd.cdip keywords_vocabulary: Global Change Master Directory (GCMD) E... date_created: 2024-06-10T21:31:12Z date_issued: 2024-06-10T21:31:12Z date_modified: 2024-06-10T21:31:12Z ... ... platform_vocabulary: http://mmisw.org/ont/ioos/platform platform_name: OCEAN STATION PAPA BUOY - 166p1 DODS.strlen: 0 DODS.dimName: metaStationNameLength DODS_EXTRA.Unlimited_Dimension: xyzCount EXTRA_DIMENSION.metaBoundsCount: 2 .. GENERATED FROM PYTHON SOURCE LINES 46-51 Now, let's compute the directional spectra using the `ewdm.Triplet` class. The input parameters `omin`, `omax` and `nvoice` control the frequency resolution, it means that a frequency array ranging from 2^-5 to 2^0 with 16 subvisions per octave will be created in this case. The parameters `dd` and `kappa` control the directional resolution and smoothness, respectively. .. GENERATED FROM PYTHON SOURCE LINES 51-63 .. code-block:: Python spec = ewdm.Triplets(dataset) output = spec.compute( omin=-5, omax=0, nvoice=16, dd=5, kappa=36, use="displacements" ) print(output) # plot the results fig, ax = plt.subplots(figsize=(6,5)) plot_directional_spectrum( output.directional_spectrum, ax=ax, levels=None, colorbar=True, cbar_kw={"label": "$E(f,\\theta)\\,\\mathrm{[m^2 Hz^{-1} deg^{-1}]}$"} ) .. image-sg:: /auto_gallery/images/sphx_glr_plot_cdip_002.png :alt: plot cdip :srcset: /auto_gallery/images/sphx_glr_plot_cdip_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Size: 95kB Dimensions: (frequency: 81, direction: 72) Coordinates: * frequency (frequency) float64 648B 0.03125 0.03263 ... 1.0 * direction (direction) int64 576B -180 -175 -170 ... 170 175 Data variables: directional_spectrum (frequency, direction) float64 47kB 7.109e-06 .... directional_distribution (frequency, direction) float64 47kB 0.0011 ... ... frequency_spectrum (frequency) float64 648B 0.00646 ... 8.578e-06 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.203 seconds) .. _sphx_glr_download_auto_gallery_plot_cdip.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_cdip.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_cdip.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_cdip.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_