Demo for reading fou-file for example Tol
Contents
Demo for reading fou-file for example Tol#
The fou.nc file is read and variable is extracted. Next, the mesh data is converted to a raster and saved to a .tiff
1. Import modules#
import os
import sys
from pathlib import Path
currentdir = os.path.dirname(os.getcwd())
sys.path.append(currentdir + r"/HydroLogic_Inundation_toolbox")
sys.path.append(currentdir + r"/HydroLogic_Inundation_toolbox/Readers")
from flowmeshreader import load_meta_data, load_fou_data, mesh_to_tiff
from plotting import raster_plot_with_context
2. Set input and output paths#
# set paths
input_file_path = currentdir + r"/HydroLogic_Inundation_toolbox/Data/Tol/input/1PT10_fou.nc"
output_file_path = currentdir + r"/HydroLogic_Inundation_toolbox/Data/Tol/output/fou.tiff"
Path(currentdir + r"/HydroLogic_Inundation_toolbox/Data/Tol/output").mkdir(exist_ok=True)
3. Set output raster options#
# raster options
resolution = 10 # m
distance_tol = 36 # m
interpolation = r"nearest"
4. Read meta-data and set variable to read from fou.nc file#
TODO: change variable to other options from list, and update figures accordingly#
print(load_meta_data(input_file_path))
variable = r"Mesh2d_fourier002_max_depth"
['Mesh2d_flowelem_ba', 'Mesh2d_flowelem_bl', 'mesh1d_fourier001_mean', 'Mesh2d_fourier001_mean', 'mesh1d_fourier002_max', 'Mesh2d_fourier002_max', 'mesh1d_fourier002_max_depth', 'Mesh2d_fourier002_max_depth', 'mesh1d_fourier003_min', 'Mesh2d_fourier003_min', 'mesh1d_fourier003_min_depth', 'Mesh2d_fourier003_min_depth', 'mesh1d_fourier004_mean', 'Mesh2d_fourier004_mean', 'mesh1d_fourier005_max', 'Mesh2d_fourier005_max', 'mesh1d_fourier006_min', 'Mesh2d_fourier006_min']
5. Load fou-map data from NetCDF file#
# load mesh coordinates and data from netCDF
node_data = load_fou_data(input_file_path, variable)
6. Plot maximum water depth#
# convert to raster and save as tiff
_, _, grid_data = mesh_to_tiff(
node_data,
input_file_path,
output_file_path,
resolution,
distance_tol,
interpolation=interpolation,
)
fig, ax = raster_plot_with_context(
raster_path = output_file_path,
epsg = 28992,
clabel = "water depth (m)",
cmap = "Reds",
title = "Maximum water depth",
)