Note
Go to the end to download the full example code.
Plotting wave spectra data
from pathlib import Path
from trajan.readers.omb import read_omb_csv
from trajan.plot.spectra import plot_trajan_spectra
import coloredlogs
import datetime
# adjust the level of information printed
# coloredlogs.install(level='error')
coloredlogs.install(level='debug')
# 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)
2024-09-02 11:25:45 fv-az1272-597 trajan.readers.omb[3440] DEBUG read path to pandas
2024-09-02 11:25:45 fv-az1272-597 trajan.readers.omb[3440] 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-09-02 11:25:46 fv-az1272-597 trajan.readers.omb[3440] DEBUG start applying sliding_filter_nsigma
2024-09-02 11:25:46 fv-az1272-597 trajan.readers.omb[3440] DEBUG done applying sliding_filter_nsigma
2024-09-02 11:25:46 fv-az1272-597 trajan.readers.omb[3440] DEBUG start applying sliding_filter_nsigma
2024-09-02 11:25:46 fv-az1272-597 trajan.readers.omb[3440] DEBUG done applying sliding_filter_nsigma
2024-09-02 11:25:46 fv-az1272-597 trajan.readers.omb[3440] DEBUG start applying sliding_filter_nsigma
2024-09-02 11:25:46 fv-az1272-597 trajan.readers.omb[3440] DEBUG done applying sliding_filter_nsigma
2024-09-02 11:25:46 fv-az1272-597 trajan.trajectory_accessor[3440] DEBUG Detecting time-dimension for "obs"..
2024-09-02 11:25:46 fv-az1272-597 trajan.trajectory_accessor[3440] DEBUG Detected obs-dim: obs, detected time-dim: time.
2024-09-02 11:25:46 fv-az1272-597 trajan.trajectory_accessor[3440] DEBUG Detected un-structured (2D) trajectory dataset
2024-09-02 11:25:46 fv-az1272-597 trajan.traj[3440] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-09-02 11:25:46 fv-az1272-597 trajan.traj[3440] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-09-02 11:25:46 fv-az1272-597 trajan.traj[3440] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-09-02 11:25:46 fv-az1272-597 trajan.traj[3440] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
# plot the spectra in one command
plot_trajan_spectra(xr_data)
![example plot spectra](../_images/sphx_glr_example_plot_spectra_001.png)
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG tuple_date_start_end = None
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG date_start_md = np.float64(19158.39047453704)
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG date_end_md = np.float64(19161.514988425926)
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG tuple_vrange_pcolor = None
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG vmin_pcolor = -3.0
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG vmax_pcolor = 1.0
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG plt_show = True
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG fignamesave = None
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG crrt_instrument = 'drifter_1'
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG crrt_instrument = 'drifter_2'
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG crrt_instrument = 'drifter_3'
2024-09-02 11:25:46 fv-az1272-597 matplotlib.colorbar[3440] DEBUG locator: <matplotlib.ticker.AutoLocator object at 0x7f8096de4f70>
# plot the spectra specifying more options by hand; it is also possible to automatically
# save the figure by setting fignamesave="some_name.png"
time_start = datetime.datetime(2022, 6, 16, 12, 30, 0)
time_end = datetime.datetime(2022, 6, 17, 8, 45, 0)
plot_trajan_spectra(xr_data, (time_start, time_end), (-2.0, 1.5))
![example plot spectra](../_images/sphx_glr_example_plot_spectra_002.png)
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG tuple_date_start_end = (datetime.datetime(2022, 6, 16, 12, 30), datetime.datetime(2022, 6, 17, 8, 45))
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG date_start_md = np.float64(19159.520833333332)
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG date_end_md = np.float64(19160.364583333332)
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG tuple_vrange_pcolor = (-2.0, 1.5)
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG vmin_pcolor = -2.0
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG vmax_pcolor = 1.5
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG plt_show = True
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG fignamesave = None
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG crrt_instrument = 'drifter_1'
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG crrt_instrument = 'drifter_2'
2024-09-02 11:25:46 fv-az1272-597 trajan.plot.spectra[3440] DEBUG crrt_instrument = 'drifter_3'
2024-09-02 11:25:46 fv-az1272-597 matplotlib.colorbar[3440] DEBUG locator: <matplotlib.ticker.AutoLocator object at 0x7f809629a170>
Total running time of the script: (0 minutes 0.594 seconds)