Latest release 1.0.11 now available on PyPi and Conda-forge

[[ visible ? '▲ HIDE' : '▼ SHOW BANNER' ]]

|||

tfv 1.0.11 documentation

Quick search

  • API Reference
  • Examples Gallery
    • Tutorial 1. TUFLOW FV Post-Processing Using Xarray
    • Tutorial 2. Introductory Matplotlib Plot Composition
    • Tutorial 3: Working With Gridded Boundary Condition Data
    • Tutorial 4. Introduction to the Particle Tracking Module Tools
    • Gallery 1: Timeseries Plots
    • Gallery 2: Profile Plots
    • Gallery 3: Sheet Plots
    • Gallery 4: Curtain Plots
    • Gallery 5: Combined Plots
    • Gallery 6: Particle Tracking Plots
    • Gallery 7: Miscellaneous

Gallery 5: Combined Plots¶

Putting it all together: a sheet, curtain, profile and time series on the same figure.

This notebook is used in combination with the TUFLOW FV Python Toolbox (tfv) package.

from pathlib import Path # We'll also make use of the `pathlib` module to assist with managing file-paths, although this is entirely optional! 
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
import numpy as np
import seaborn as sns
import tfv.xarray
import xarray as xr  # We utilise xarray to do all the heavy lifting 

# A nice plot default
sns.set(style='white', font_scale=0.8)

Open TUFLOW FV Model Result¶

model_folder = Path(r'..\..\data')
model_file = 'HYD_002.nc'

fv = xr.open_dataset(model_folder / model_file, decode_times=False).tfv
# fv  # Uncomment if you'd like to review the dataset
# User input - select variables and location for plotting
polyline = np.loadtxt(model_folder / 'polyline.csv', skiprows=1, delimiter=',')
loc = 'P2'
time = '2011-05-02 12:00'
var = 'SAL'

locs = {
    'P1' : (159.0758, -31.3638),
    'P2' : (159.0845,  -31.3727),
    'P3' : (159.0906,  -31.3814),
    'P4' : (159.1001,  -31.3948),
    'P5' : (159.1154,  -31.4032),
    'P6' : (159.1266,  -31.4105),
    'P7' : (159.1202,  -31.4165),
    'P8' : (159.1178,  -31.4236),
}
# Extract the timeseries and profile data
ts = fv.get_timeseries(['SAL'],locs)
prof = fv.get_profile(locs[loc],variables=['SAL'])

Plot Multiple Ways¶

# Set Up Figure
cspec =  dict(cmap='ocean', clim=(0, 36))

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(12, 8), gridspec_kw={'width_ratios': [1, 3]}, constrained_layout=True)

fv.plot(var, time, ax=ax1, colorbar=False, **cspec)
ax1.plot(polyline[:, 0], polyline[:, 1], lw=1, color='black', ls='--')
ax1.plot(locs['P2'][0], locs['P2'][1], 'o', color='red')
ax1.set_aspect('equal')
ax1.set_title(f'Depth Avg. {var}')

# Plot curtain
fv.plot_curtain(polyline, var, time, ax=ax2, ec='none', **cspec)
ax2.set_title(f'{var} Curtain Profile')

# Plot profile
prof.sel(Time=time).plot.scatter(x='SAL',y='Z', ax=ax3, color='black', lw=1)
zfaces = prof['layerface_Z'].sel(Time=time)
ax3.set_yticks(zfaces)
ax3.grid(axis='y')

# Plot timeseries
ts[var].sel(Location=loc).plot(ax=ax4, color='black', lw=1)
ax4.grid()
ax4.set_ylabel('Depth averaged salinity [PSU]')

fig.suptitle('Salinity Four Ways - A Salty Tale', fontweight='bold', x=0.45, fontsize=16)
Text(0.45, 0.98, 'Salinity Four Ways - A Salty Tale')
../../../_images/c7b8848da54b4a4a150cbb69c1b6e77b1d5944737f10f81dec375cf567bbebfe.png

This concludes the examples on combined plotting.

<Page contents

>Page contents:

  • Gallery 5: Combined Plots
    • Open TUFLOW FV Model Result
    • Plot Multiple Ways
<Gallery 4: Curtain Plots
Gallery 6: Particle Tracking Plots>
© Copyright 2024 BMT. Created using Sphinx 8.2.3.

Styled using the Piccolo Theme