Gallery 7: Miscellaneous¶
This page shows off a set of miscellaneous plots.
This notebook is used in combination with the TUFLOW FV Python Toolbox (tfv
) package.
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
import tfv.xarray
import xarray as xr
Open TUFLOW FV Model Result¶
model_folder = Path('../../data')
domain_file = 'HYD_002.nc'
profile_file = 'HYD_002_time_series.nc'
fv = xr.open_dataset(model_folder / domain_file, decode_times=False).tfv
ts = xr.open_dataset(model_folder / profile_file, decode_times=False).tfv
Hovmoller Plot¶
A hovmoller plot is a type of 2D Timeseries, which shows you time along the x-axis and a vertical variable along the y-axis. You can draw them from a profile timeseries result file (fastest) or from a domain result.
We’ll show both below.
# We'll borrow the locations from the timeseries file.
locations = ts.locations
locations
{'Point_1': [np.float64(159.07547357974093), np.float64(-31.363570800985343)],
'Point_2': [np.float64(159.08421845507237), np.float64(-31.37241113710583)],
'Point_3': [np.float64(159.0904215514381), np.float64(-31.381551067375685)],
'Point_4': [np.float64(159.1002274977631), np.float64(-31.394967859607366)],
'Point_5': [np.float64(159.1154660170632), np.float64(-31.40318039451822)],
'Point_6': [np.float64(159.12657031830057), np.float64(-31.41063523347031)],
'Point_7': [np.float64(159.1205401938322), np.float64(-31.416303583060728)],
'Point_8': [np.float64(159.11767817266238), np.float64(-31.42373017624952)],
'Point_9': [np.float64(159.12763707209098), np.float64(-31.440384244441056)]}
Using the Profile file¶
variable = 'SAL'
location = 'Point_4'
# We define the x-axis limits using a time slicer. You choose the start and end.
time_limits = slice('2011-05-01', '2011-05-07')
fig, ax = plt.subplots()
hov = ts.plot_hovmoller('Point_4', variable, ax=ax, time_limits=time_limits)
fig.autofmt_xdate()
fig.colorbar(hov, label='Salinity (PSU)')
plt.show()

Using the Domain file¶
variable = 'TEMP'
location = 'Point_2'
# We define the x-axis limits using a time slicer. You choose the start and end.
time_limits = slice('2011-05-01', '2011-05-07')
fig, ax = plt.subplots()
hov = fv.plot_hovmoller(locations[location], variable, ax=ax, time_limits=time_limits)
fig.autofmt_xdate()
fig.colorbar(hov, label='Temperature (degC)')
plt.show()

Using Different Shading Options¶
variable = 'TEMP'
location = 'Point_6'
clims = (10, 22)
clevels = np.arange(10, 22.5, 0.5) # For contour only!
# We define the x-axis limits using a time slicer. You choose the start and end.
time_limits = slice('2011-05-01', '2011-05-07')
fig, axes = plt.subplots(ncols=3, figsize=(10, 4), constrained_layout=True)
shading_options = ['contour', 'interp', 'patch']
for i, ax in enumerate(axes):
shading = shading_options[i]
ax.set_title(shading)
ax.set_xticklabels([]) # Hide the xlabels for neatness
if shading != 'contour':
hov = fv.plot_hovmoller(locations[location], variable, ax=ax, time_limits=time_limits, shading=shading, cmap='turbo', clim=clims)
else:
hov = fv.plot_hovmoller(locations[location], variable, ax=ax, time_limits=time_limits, shading=shading, cmap='turbo', levels=clevels)
fig.colorbar(hov, ax=axes, orientation='horizontal', aspect=40, label='Temperature (degC)')
fig.autofmt_xdate()
plt.show()

This concludes the example.