Example for reading map-file for example Tol
Contents
Example for reading map-file for example Tol#
The map.nc file is read and variable is extracted. Next, the mesh data for the final time-step 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_map_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_map.nc"
output_file_path = currentdir + r"/HydroLogic_Inundation_toolbox/Data/Tol/output/final_waterdepth.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 map.nc file#
print(load_meta_data(input_file_path))
variable = r"Mesh2d_waterdepth"
['Mesh2d_flowelem_ba', 'Mesh2d_flowelem_bl', 'Mesh2d_Numlimdt', 'Mesh2d_waterdepth', 'Mesh2d_s1', 'Mesh2d_s0', 'Mesh2d_ucx', 'Mesh2d_ucy', 'Mesh2d_ucmag', 'Mesh2d_taus', 'Mesh2d_czs']
5. Load map data from NetCDF file#
# load mesh coordinates and data from netCDF
map_data = load_map_data(input_file_path, variable)
6. Plot water depth at last time step#
# convert to raster and save as tiff
_, _, grid_data = mesh_to_tiff(
map_data[-1, :],
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 = "Water depth at last time step",
)
![_images/map_example_tol_12_0.png](_images/map_example_tol_12_0.png)