Welcome, Guest
Username: Password: Remember me

TOPIC: Tutorial: make a video of time dependent water levels along a polyline

Tutorial: make a video of time dependent water levels along a polyline 7 years 1 week ago #28173

  • konsonaut
  • konsonaut's Avatar
  • OFFLINE
  • openTELEMAC Guru
  • Posts: 413
  • Thank you received: 144
Hi,

a typical postprocessing task is the visualization of time dependent water levels e.g. along the river axis.
Such visualizations are not beautiful only but they help to analyze the results or to check the simulation settings.

This post is intented to be a short tutorial how to interpolate the time dependent water levels along a polyline from a Telemac-2D result file and to produce a nice video. We will not go into details about the basics of Python, Matplotlib and Numpy scripting but on how to produce the video inside the Python framework. Such scripts are very cool since, once the setup has been done, it can be quickly used for other cases, too.

What you need:
Software:
- Python 2.7.x with site-packages Matplotlib and Numpy
- FFmpeg, open source video and audio converter, www.ffmpeg.org
- Python scripts, which are usually equipped within an openTelemac installation: ..\vXX\scripts\python27

Data:
- Telemac-2D result file
- Polyline with x and y coordinates, e.g. generated with Blue Kenue

Let's say we have a Telemac-2D result file of a simulated river. The flood propagation on an initially dry bed caused by a sudden release of water from a reservoir was simulated. Now we want to analyze the time dependent water levels along the red polyline, as shown e.g. in the following figure B)



In the end we will produce a video like this.

Here you will find the Python script

File Attachment:

File Name: python_telemac2D_interp_line.py
File Size: 7 KB



Some preliminary remarks:
- some Python skills are assumed and hence, the script will not be explained line by line
- the script seems really long but it is equipped with a lot of comments
- most of the lines deal with formatting the layout of the figure / video
- it is advisable to write the defined functions explained below in a separate file and import them
- copy the code below to an empty text file and open it with a Python editor

From line 5 to line 13
Python modules and site-packages are imported. In line 7 we add the Python scripts directory of the Telemac Python scripts in order to import the selafin parser in line 13.

From line 17 to line 23
Telemac result file and the polyline are imported. E.g. here the polyline consisting of x an y coordinates was generated with Blue Kenue and saved as i2s file.

From line 41 to line 49
The function "Get_polyline_distances" calculates the stationing (distances) and the transposed input polyline (poly_new)

From line 52 to line 61
The function "Get_Values" gets the time dependent results of a specific variable and puts them in an array

From line 64 to line 81
The function "Interpolate_1D_profiles" interpolates the time dependent results of a specific variable on the polyline

Line 86: now we calculate with the above defined function "Get_polyline_distances" the distances and the transposed polyline of our input polyline

From line 89 to line 102
First, here we can choose which time steps (frames) we want to extract and visualize. Second, in this example we interpolate the Bottom and the Free Surface to the polyline

From line 105 to line 148
Here we specify the layout options of the figure / video

Lines 150 to 181 finally deal with the production of the video:
In line 156 we specify the path to the installed ffmpeg executable
In line 160 we specify the amazingly good libx264 codec and a constant rate factor of 18 for the video quality. One can set this video quality factor to the default value of 23.
From line 168 to 171 we specify e.g. the line colors, line widths etc.
In line 176 we put the interpolated free surface values in a loop.

My work is done!

This tutorial is based on the blog post www.flowbeat.flussbuero.at/2017/11/15/po...results-with-python/ with some more videos.

All kind of comments are appreciated!

Cheers,
konsonaut
The administrator has disabled public write access.
The following user(s) said Thank You: c.coulet, sebourban, cyamin, ClaireBeraud, Lux
Moderators: borisb

The open TELEMAC-MASCARET template for Joomla!2.5, the HTML 4 version.