Gallery 7: Miscellaneous¶
This notebook shows an example Hovmoller Plot.
This notebook is used in combination with the TUFLOW FV Python Toolbox (tfv) package. To follow along on your own computer, please download the demonstration notebooks from the TUFLOW Downloads Page. Look for the TUFLOW FV Python Toolbox download. Installation instructions are provided on our TUFLOW FV Python Toolbox Wiki Page.
To view miscellaneous figures you need to have additionally PyQT5 installed in your working Python environment.
If using conda: conda install -c conda-forge pyqt. You will need to close this notebook, install with your environment activated (for example tfv-workspace) and then restart jupyter-lab.
In pip: pip install PyQT5.
Please note that the plots will be displayed in a separate window, not inline in the notebook.
from tfv.timeseries import FvTimeSeries
from tfv.extractor import FvExtractor
from tfv.visual import *
from tfv.viewer import Viewer, ColourBar
from pathlib import Path
Hovmoller Plot¶
# Result file folder and name
model_folder = Path(r'..\..\data')
model_file = 'HYD_002.nc'
ts_file = 'HYD_002_time_series.nc'
# Variable to plot
variable = 'SAL'
location = 'Point_4'
# Axes settings
y_label = 'Water Surface Elevation [mAHD]'
x_label = 'Date [dd/mm/yyyy]'
date_fmt = '%d/%m/%Y'
x_limit = [pd.Timestamp(2011, 5, 1), pd.Timestamp(2011, 5, 7)]
y_limit = [-6, 0.5]
c_limit = [0, 38]
# ----------------------------------------------------- Script ---------------------------------------------------------
# Prepare extractor object
xtr = FvExtractor(model_folder / model_file)
ts = FvTimeSeries(model_folder / ts_file)
# Prepare viewer object, figure & axes
viewer = Viewer(size=(220, 220), units='mm')
axes = viewer.figure.subplots(3, 3)
gs = axes[0, 0].get_gridspec()
for ax in axes.flatten():
viewer.figure.delaxes(ax)
ax_ts = viewer.figure.add_subplot(gs[0, :-1])
ax_hm = viewer.figure.add_subplot(gs[1:, :-1])
ax_pr = viewer.figure.add_subplot(gs[1:, -1])
viewer.figure.subplots_adjust(bottom=0.25, top=0.95, wspace=0.35, hspace=0.35)
# Plot profile visual
time_series = SeriesGlider(ax_ts, ts, variable, location, 'sigma', (0, 1), viewer=viewer)
hov_mol = HovmollerGlider(ax_hm, ts, variable, location, viewer=viewer, edgecolor='face', clim=c_limit)
profile = ProfileCell(ax_pr, xtr, variable, ts.locations[location], viewer=viewer)
# Set axes limits
ax_ts.set_xlim(x_limit)
ax_hm.set_xlim(x_limit)
ax_pr.set_xlim(c_limit)
# Set axes limits
ax_ts.set_ylim(c_limit)
ax_hm.set_ylim(y_limit)
ax_pr.set_ylim(y_limit)
# Format axes
fmt = DateFormatter(date_fmt)
ax_ts.xaxis.set_major_formatter(fmt)
for tick in ax_ts.get_xticklabels():
tick.set_rotation(20)
ax_hm.xaxis.set_major_formatter(fmt)
for tick in ax_hm.get_xticklabels():
tick.set_rotation(20)
viewer.figure.autofmt_xdate()
col_bar = ColourBar(hov_mol.patch, location='bottom', label='Salinity [PSU]', offset=-0.10)
bbox = list(col_bar.ax.get_position().bounds); bbox[2] = 3/4
col_bar.ax.set_position(bbox)
# Add labels
ax_ts.set_ylabel('Depth Averaged Salinity [PSU]')
ax_hm.set_ylabel('Elevation [m MSL]')
ax_pr.set_ylabel('Elevation [m MSL]')
ax_pr.set_xlabel('Salinity [PSU]')
# Show the figure
plt.show(block=True)
# The plot will open in a seperate PyQT5 Window.
# Once you've reviwed the results please close the figure window.
# You will then need interrupt the notebook kernel by clicking the stop button prior to moving on and running the next example.
This concludes the example on Hovmoller plotting.