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 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()
../../../_images/91b182f1bdae1773a39d2de4ec4e76859dc0735734056d50ef6a897178ac291f.png

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()
../../../_images/e075ee4cbd6135b0d00a8c39f179108cf6caa039b91011a6e75621a5473fd1f8.png

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()
../../../_images/c51a0905df24b49ff33948d304fbf395ae3bbee909d7ab156713f8c07d208226.png

This concludes the example.

<Page contents

>Page contents:

  • Gallery 7: Miscellaneous
    • Open TUFLOW FV Model Result
    • Hovmoller Plot
      • Using the Profile file
      • Using the Domain file
      • Using Different Shading Options
<Gallery 6: Particle Tracking Plots
© Copyright 2024 BMT. Created using Sphinx 8.2.3.

Styled using the Piccolo Theme