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-10-31 20:48:25 fv-az1024-670 trajan.readers.omb[2149] DEBUG read path to pandas
2024-10-31 20:48:25 fv-az1024-670 trajan.readers.omb[2149] 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-10-31 20:48:25 fv-az1024-670 trajan.readers.omb[2149] DEBUG start applying sliding_filter_nsigma
2024-10-31 20:48:25 fv-az1024-670 trajan.readers.omb[2149] DEBUG done applying sliding_filter_nsigma
2024-10-31 20:48:25 fv-az1024-670 trajan.readers.omb[2149] DEBUG start applying sliding_filter_nsigma
2024-10-31 20:48:25 fv-az1024-670 trajan.readers.omb[2149] DEBUG done applying sliding_filter_nsigma
2024-10-31 20:48:25 fv-az1024-670 trajan.readers.omb[2149] DEBUG start applying sliding_filter_nsigma
2024-10-31 20:48:25 fv-az1024-670 trajan.readers.omb[2149] DEBUG done applying sliding_filter_nsigma
2024-10-31 20:48:25 fv-az1024-670 trajan.accessor[2149] DEBUG Detecting time-dimension for "obs"..
2024-10-31 20:48:25 fv-az1024-670 trajan.accessor[2149] DEBUG Detected obs-dim: obs, detected time-dim: time.
2024-10-31 20:48:25 fv-az1024-670 trajan.accessor[2149] DEBUG Detected un-structured (2D) trajectory dataset
2024-10-31 20:48:25 fv-az1024-670 trajan.traj[2149] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-10-31 20:48:25 fv-az1024-670 trajan.traj[2149] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-10-31 20:48:25 fv-az1024-670 trajan.traj[2149] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
2024-10-31 20:48:25 fv-az1024-670 trajan.traj[2149] DEBUG No grid-mapping specified, checking if coordinates are lon/lat..
# plot the spectra in one command
plot_trajan_spectra(xr_data)
2024-10-31 20:48:25 fv-az1024-670 trajan.plot.spectra[2149] DEBUG tuple_date_start_end = None
2024-10-31 20:48:25 fv-az1024-670 trajan.plot.spectra[2149] DEBUG date_start_md = np.float64(19158.39047453704)
2024-10-31 20:48:25 fv-az1024-670 trajan.plot.spectra[2149] DEBUG date_end_md = np.float64(19161.514988425926)
2024-10-31 20:48:25 fv-az1024-670 trajan.plot.spectra[2149] DEBUG tuple_vrange_pcolor = None
2024-10-31 20:48:25 fv-az1024-670 trajan.plot.spectra[2149] DEBUG vmin_pcolor = -3.0
2024-10-31 20:48:25 fv-az1024-670 trajan.plot.spectra[2149] DEBUG vmax_pcolor = 1.0
2024-10-31 20:48:25 fv-az1024-670 trajan.plot.spectra[2149] DEBUG plt_show = True
2024-10-31 20:48:25 fv-az1024-670 trajan.plot.spectra[2149] DEBUG fignamesave = None
2024-10-31 20:48:25 fv-az1024-670 trajan.plot.spectra[2149] DEBUG crrt_instrument = 'drifter_1'
2024-10-31 20:48:25 fv-az1024-670 trajan.plot.spectra[2149] DEBUG crrt_instrument = 'drifter_2'
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG crrt_instrument = 'drifter_3'
2024-10-31 20:48:26 fv-az1024-670 matplotlib.colorbar[2149] DEBUG locator: <matplotlib.ticker.AutoLocator object at 0x7f6de9ac90d0>
# 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))
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG tuple_date_start_end = (datetime.datetime(2022, 6, 16, 12, 30), datetime.datetime(2022, 6, 17, 8, 45))
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG date_start_md = np.float64(19159.520833333332)
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG date_end_md = np.float64(19160.364583333332)
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG tuple_vrange_pcolor = (-2.0, 1.5)
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG vmin_pcolor = -2.0
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG vmax_pcolor = 1.5
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG plt_show = True
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG fignamesave = None
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG crrt_instrument = 'drifter_1'
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG crrt_instrument = 'drifter_2'
2024-10-31 20:48:26 fv-az1024-670 trajan.plot.spectra[2149] DEBUG crrt_instrument = 'drifter_3'
2024-10-31 20:48:26 fv-az1024-670 matplotlib.colorbar[2149] DEBUG locator: <matplotlib.ticker.AutoLocator object at 0x7f6de96af0d0>
Total running time of the script: (0 minutes 0.533 seconds)