Post-processing with NetCDF#

During a hydraulic study, we want to visualize simulations results directly over the study area. This tutorial presents a method for visualizing Watlab simulation results using a NetCDF file (.nc file). This format allows temporal animation and efficient spatial data handling. NetCDF files can be visualized in QGIS.

To generate a .nc file, Watlab provides a function: watlab.utils.generate_netcdf_file_from_picture.

Function generating the NetCDF file#

  • node_file → path to the "node.txt" file located in the model’s Input folder

  • cells_file → path to the "cells.txt" file located in the model’s Input folder

  • friction_values → path to the "friction_values.txt" file located in the model’s Input folder

  • pic_path_template → template path to the result files located in the model’s Output folder

  • output_file → path and name of the NetCDF file to be created

  • max_time → total simulation duration (in seconds)

  • time_step → interval between time steps (in seconds)

  • EPSG_CODE → coordinate reference system (Lambert 72 = 31370)

  • initial_time → simulation start time (usually 0)

from watlab.utils import generate_netcdf_file_from_picture

generate_netcdf_file_from_picture(
    nodes_file = "Input/nodes.txt",
    cells_file = "Input/cells.txt",
    manning_values = "Input/friction_values.txt",
    pic_path_template = "Output/pic_{:d}_00.txt",
    output_file = "Andenne_100_50_70Q.nc",
    max_time = 86400,
    time_step = 360,
    EPSG_CODE = "31370",
    initial_time = 0
)

Visualizing the NetCDF File in QGIS#

  1. Add the NetCDF file as a mesh layer

    In QGIS, go to:
    LayerAdd LayerAdd Mesh Layer...
    Select the .nc file generated earlier.

Add mesh layer

  1. Configure the layer properties
    Open the properties of the newly added layer.
    • Source:

      • Make sure the CRS is correctly set to Lambert 72 (EPSG:31370).

      • Choose the variable you want to visualize from the available dataset.

      • If you check “Treat as static dataset”, you can select a specific time step to display.

    • Symbology:

      • Adjust the rendering to suit your needs (e.g. color ramp).

      • To display the mesh structure, enable “Native mesh rendering”.

    • Temporal:

      • Activate the Temporal Controller Panel to animate the results.

      • You can adjust the time units and time range according to your simulation settings in the layer’s temporal properties.

Properties Mesh Layer

💡 To activate Temporal Controller Panel, right-click anywhere in the toolbar area at the top of the QGIS window. A list of available panels will appear.

Temporal Controller Panel

Example of NedCDF files vizualization in QGIS#

The image below shows a typical result obtained by loading a NetCDF file into QGIS. Using the Temporal Controller Panel, you can navigate through different time steps of the simulation and observe how hydraulic variables evolve over time.

Exemple NedCDF

Elevation profile#

After navigating through the time using the NetCDF file, you can extract the water surface elevation and compare it to your DEM at a specific time step. To represent water surface elevation relative to terrain, you need to use the pic_XX_XX.txt file generated by Watlab in the folder Output.

1. Import the result file into QGIS#

Go to : LayerAdd LayerAdd Delimited Text Layer...

Add text layer

Parameters: - File name: Click the three dots to browse to your Output folder and select the pic_XX_XX.txt file corresponding to the desired time step. - File format: Choose “Custom delimiter” and select Tab. - Sample Data: Make sure the columns are correctly detected (e.g., x, y, zb, h, etc.). - Geometry definition:
- Type: Point
- X field: x
- Y field: y
- Coordinate reference system: Lambert 72 (EPSG:31370)

Once the layer is added, you should see a cloud of points representing the model mesh, one point per cell.

2. Add the Water surface elevation to the attribute table#

To represent water surface elevation relative to terrain, you need to combine the water depth h with the terrain elevation zb from the model. You have to add a new column h_zb to the attribute table of your result file.

  1. Open the attribute table of the pic_XX_XX.txt layer (right-click on the layer → Open Attribute Table).

  2. Open the Field Calculator:

    • Create a new field

    • Name: h_zb

    • Output field type: Decimal (double)

    • Expression:

      "h" + "zb"
      
  3. Apply the calculation.

Attribute table

3. Interpolate the water surface elevation#

To visualize the results as a continuous surface, interpolate the point data into a raster.

Open the Processing Toolbox:
Processing ToolboxTIN Interpolation

Parameters: - Vector layer: Select the pic layer imported earlier. - Interpolation attribute: Choose h_zb. Click the + to add it. - Interpolation method: Linear - Extent: Use the extent of the pic layer - Pixel size: Set according to the desired resolution

Give the TIF file a clear name to identify the time step and variable. In the layer properties, adjust the symbology for optimal readability.

💡 To produce high-quality visual outputs, QGIS also allows you to design map layouts with legends, titles, and scale bars using ``Project`` → ``New Print Layout``. This is ideal for exporting clean figures for reports or presentations.

4. Terrain profile#

To generate a terrain profile, you can use the Profile Tool plugin. This allows you to draw a temporary line directly on the map or use a predefined shapefile if you want to consistently apply the same cross-section across different datasets.

Once the raster is generated, you can compare the interpolated water level with your DEM to produce elevation profiles at a specific time step.

Terrain Profile

The picture below illustrates a typical elevation profile:

  • Red curve: Digital Elevation Model (DEM), representing the terrain.

  • Blue curve: Water surface elevation (h + zb), showing the simulated water level.

💡 You can export the data (right-click → Export) and create beautiful plots using Python libraries such as Matplotlib or Seaborn.

Elevation profile