Welcome, Guest
Username: Password: Remember me

TOPIC: How to read result files of telemac with computer languege?

How to read result files of telemac with computer languege? 2 years 6 months ago #40389

Hello:
Recently,I'm handling the result files of telemac-2D with bluekenue. But that can't meet my needs. I want to draw different forms of plots. So I want to read the result files with python or other computer languege.
Further, if the results in a certain moment can be converted to raster data that will be perfect.
Thanks for you help.
Best wishes.
Song
The administrator has disabled public write access.

How to read result files of telemac with computer languege? 2 years 6 months ago #40393

  • Lux
  • Lux's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 96
  • Thank you received: 39
Hello Song,

Your question should be posted in the "scripts" section of the forum.
Several modules exist in Python to read/write Selafin files and do some plots :
  • postel: included in the Telemac official source Python3 code. It is the new and recommended solution but you need to compile Telemac with Hermes (which is not easy on Windows)
  • pyteltools: parser with different scripts, a converter from Selafin to raster exists (see command line script ./cli/slf_to_raster.py)
  • pputils: a lot of command line scripts

There are also some R and Matlab scripts, although I did not try to use.

Hope it helps,
Luc
The administrator has disabled public write access.
The following user(s) said Thank You: SongTianxu

How to read result files of telemac with computer languege? 2 years 6 months ago #40398

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

For getting Telemac results into Python for further processing or plotting I still use the following really very old but efficient solution. No need to use other Python libraries than the ones provided by Telemac and no need to compile Telemac with Hermes.
For the interpolation to raster etc. or plotting you will find a lot of examples in the internet.

______________________________________________________
import sys
from os import path
sys.path.append(path.join( path.dirname(sys.argv[0]), r'C:\Opentelemac\v8p3r1\scripts\python3'))
from data_manip.formats.selafin import Selafin

import numpy as np

slf = Selafin('res.slf')

def Get_Values(var_name, frames):
var_names=[item.rstrip() for item in slf.varnames]
z_var = []

for i in frames:
z_var.append(slf.get_variables_at(i, [var_names.index(var_name)]))
z_var = np.squeeze(z_var, axis=None) # remove one-dimensional entries

return z_var

times = slf.tags["times"]

print (times)
print (len(slf.meshx))
print (len(slf.ikle3))

frames = range(0,len(times))

# e.g. get the water depths for all frames
depths = Get_Values('WATER DEPTH', frames)

print (depths.shape)

Maybe it helps,
Clemens
________________________________________________
The administrator has disabled public write access.
The following user(s) said Thank You: R.Wei, SongTianxu

How to read result files of telemac with computer languege? 2 years 6 months ago #40423

Hello Clemens
I'm sorry to reply so late.
I have tried some ways to read result files, the method you sharing is easy and work well. Thanks for you help.
But there is a bug in the script.The program throws such an error:
"AttributeError: 'numpy.ndarray' object has no attribute 'append'"
in this line:
"z_var.append(slf.get_variables_at(i, [var_names.index(var_name)]))".
Further, I want to learn more about "Selafin". Are there any more typical examples or tutorials?
Thank you again.
ps:For everyone to learn this script easier, share the precautions.
1.You must install the new version of telemac.(I use v8p2r0)
2.You must install the numpy and scipy as the third party Library.
The administrator has disabled public write access.

How to read result files of telemac with computer languege? 2 years 6 months ago #40448

  • pham
  • pham's Avatar
  • OFFLINE
  • Administrator
  • Posts: 1559
  • Thank you received: 602
Hello Song,

You have a description of the SELAFIN or SERAFIN format in appendix C of the TELEMAC-2D or TELEMAC-3D user manual.

Hope this helps,

Chi-Tuan
The administrator has disabled public write access.

How to read result files of telemac with computer languege? 2 years 6 months ago #40424

Hello Luc:
I'm sorry to reply so late. I tried these way to get it. But it's a little difficult for me(I am a complete beginner). Thank you for your kind help.

Song
The administrator has disabled public write access.

How to read result files of telemac with computer languege? 2 years 6 months ago #40450

  • NZrigat
  • NZrigat's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 65
  • Thank you received: 16
Hi Song,

You can extract time series for multiple points in the domain using Blue Kenue quite easily, but I would still prefer using the python scripts that come with TELEMAC (There's also the PPUTILS toolkit). If you want something that is very user friendly, then I suggest using the QGIS plug-in post-telemac.

Hope this helps,

Cheers,
Nayef
The administrator has disabled public write access.
Moderators: pham

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