.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/example_plot_spectra_accessors.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_gallery_example_plot_spectra_accessors.py: Plotting wave spectra data, using the accessor syntax ============================================================================= .. GENERATED FROM PYTHON SOURCE LINES 7-18 .. code-block:: Python from pathlib import Path from trajan.readers.omb import read_omb_csv import coloredlogs import datetime import matplotlib.pyplot as plt # adjust the level of information printed # coloredlogs.install(level='error') coloredlogs.install(level='debug') .. GENERATED FROM PYTHON SOURCE LINES 19-24 .. code-block:: Python # load the data from an example file with several buoys and a bit of wave spectra data path_to_test_data = Path.cwd().parent / "tests" / "test_data" / "csv" / "omb3.csv" xr_data = read_omb_csv(path_to_test_data) .. rst-class:: sphx-glr-script-out .. code-block:: none 2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG reading /home/runner/work/trajan/trajan/tests/test_data/csv/omb3.csv.. 2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG omb_dataframe at index 94 is: Date Time (UTC) 16/Jun/2022 18:27:19 Device drifter_2 Direction MO Payload NaN Approx Lat/Lng 74.36745,3.3274 Payload (Text) NaN Length (Bytes) 0 Credits 1 Name: 94, dtype: object this is empty (Length (Bytes) is 0), drop 2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG start applying sliding_filter_nsigma 2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG done applying sliding_filter_nsigma 2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG start applying sliding_filter_nsigma 2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG done applying sliding_filter_nsigma 2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG start applying sliding_filter_nsigma 2024-12-16 16:27:17 fv-az1766-447 trajan.readers.omb[2121] DEBUG done applying sliding_filter_nsigma 2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detecting trajectory dimension 2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detecting time-variable for "obs".. 2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detected obs-dim: obs, detected time-variable: time. 2024-12-16 16:27:17 fv-az1766-447 trajan.accessor[2121] DEBUG Detected un-structured (2D) trajectory dataset 2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat.. 2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat.. 2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat.. 2024-12-16 16:27:17 fv-az1766-447 trajan.traj[2121] DEBUG No grid-mapping specified, checking if coordinates are lon/lat.. .. GENERATED FROM PYTHON SOURCE LINES 25-35 .. code-block:: Python # if no axis is provided, an axis will be generated automatically # by default, we "decorate", i.e. label axis etc xr_data.isel(trajectory=0).processed_elevation_energy_spectrum.wave.plot( xr_data.isel(trajectory=0).time_waves_imu.squeeze(), ) plt.show() .. image-sg:: /gallery/images/sphx_glr_example_plot_spectra_accessors_001.png :alt: example plot spectra accessors :srcset: /gallery/images/sphx_glr_example_plot_spectra_accessors_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 2024-12-16 16:27:17 fv-az1766-447 trajan.waves[2121] DEBUG Setting up new plot object. 2024-12-16 16:27:17 fv-az1766-447 matplotlib.colorbar[2121] DEBUG locator: .. GENERATED FROM PYTHON SOURCE LINES 36-63 .. code-block:: Python # it is also possible to provide an axis on which to plot # in this case, this will likely be part of a larger figure, and the user will likely want to put the # labels etc themselves; remember to switch off decoration # a plot with 3 lines, 2 columns fig, ax = plt.subplots(3, 2) ax_out, pclr = xr_data.isel(trajectory=0).processed_elevation_energy_spectrum.wave.plot( xr_data.isel(trajectory=0).time_waves_imu.squeeze(), # plot on the second line, first column ax=ax[1, 0], decorate=False, ) # the user can make the plot to their liking ax[1, 0].set_xticks(ax[1, 0].get_xticks(), ax[1, 0].get_xticklabels(), rotation=45, ha='right') ax[1,0].set_ylim([0.05, 0.25]) ax[1,0].set_ylabel("f [Hz]") plt.tight_layout() cbar = plt.colorbar(pclr, ax=ax, orientation='vertical', shrink=0.8) cbar.set_label('log$_{10}$(S) [m$^2$/Hz]') plt.show() .. image-sg:: /gallery/images/sphx_glr_example_plot_spectra_accessors_002.png :alt: example plot spectra accessors :srcset: /gallery/images/sphx_glr_example_plot_spectra_accessors_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 2024-12-16 16:27:17 fv-az1766-447 trajan.waves[2121] DEBUG Setting up new plot object. /home/runner/work/trajan/trajan/examples/example_plot_spectra_accessors.py:58: MatplotlibDeprecationWarning: Getting the array from a PolyQuadMesh will return the full array in the future (uncompressed). To get this behavior now set the PolyQuadMesh with a 2D array .set_array(data2d). cbar = plt.colorbar(pclr, ax=ax, orientation='vertical', shrink=0.8) 2024-12-16 16:27:18 fv-az1766-447 matplotlib.colorbar[2121] DEBUG locator: .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.629 seconds) .. _sphx_glr_download_gallery_example_plot_spectra_accessors.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_plot_spectra_accessors.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_plot_spectra_accessors.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_plot_spectra_accessors.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_