Welcome, Guest
Username: Password: Remember me

TOPIC: Write Selafin file (with mesh) from scratch using Python

Write Selafin file (with mesh) from scratch using Python 9 months 3 weeks ago #44310

  • simonwp
  • simonwp's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Hi all,

I have a fair bit of experience running hydro and wave models but new to the TELEMAC world.

A similar topic was raised in the past, but it's almost 5-7 years old now so there are probably resources answering my questions out there but wasnt able to quite pinpoinnt so far.

www.opentelemac.org/index.php/community-...afin-files-in-python
www.opentelemac.co.uk/index.php/assistan...-scratch-with-python

I have an unstructured mesh in a 2dm format, that I would like to convert to a selafin file (+ potentially <.cli>) so that I can use it in my simulations (I'd be using ARTEMIS).

I have come across this useful suite of tools that were referenced in earlier posts PPUTILS (now available here: codeberg.org/pprodano/pputils), which should be able to do the job, but keen to hear if there are any workflow recommendations from more experienced users ?

@cyamin
@pprodano

Many thanks !
The administrator has disabled public write access.

Write Selafin file (with mesh) from scratch using Python 9 months 3 weeks ago #44312

  • Lux
  • Lux's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 96
  • Thank you received: 39
Hi!

There are several Python modules to read/write Selafin files. But I do not know if all can build a file from scratch.

If you want ot use PyTelTools, here is snippet to write a 2D Selafin file:
from scipy.spatial import Delaunay
import numpy as np

from pyteltools.slf import Serafin


nb_nodes_2d = 100
x = np.random.rand(nb_nodes_2d)
y = np.random.rand(nb_nodes_2d)
nodes = np.column_stack((x, y))
ikle = Delaunay(np.vstack((x, y)).T).simplices + 1  # IKLE tables are 1-indexed

with Serafin.Write("r2d.slf", "en", overwrite=True) as resout:
    header = Serafin.SerafinHeader("My title")
    header.from_triangulation(nodes, ikle)
    header.add_variable_from_ID("H")  # Water depth
    header.add_variable_str("MYVAR", "MYVAR", "My/Unit")  # Custom variable
    resout.write_header(header)

    for time in [0.0, 3600.0]:
        values = np.random.rand(header.nb_var, nb_nodes_2d)
        resout.write_entire_frame(header, time, values)

If you are facing some issue (in particular performance to build ipobo array for fine mesh), let me know, there are some in progress work.

Writing a 3D Selafin file would need some more methods, but it is still possible with PyTelTools.

If you wan to try xarray-selafin (it uses PyTelTools to parse Selafin), here is also a snippet to do it.

Best Regards,
Luc
The administrator has disabled public write access.
The following user(s) said Thank You: SongTianxu, simonwp

Write Selafin file (with mesh) from scratch using Python 7 months 4 hours ago #44827

Hello Lux!
The bluekenue can't meet my needs.So,i want to generate the mesh with python. Is there have more example about writing 2D Selafin file with Pyteltools? Especially about the complex mesh generation.
Thank you so much.
Song
The administrator has disabled public write access.

Write Selafin file (with mesh) from scratch using Python 7 months 4 hours ago #44828

  • sebourban
  • sebourban's Avatar
  • OFFLINE
  • Administrator
  • Principal Scientist
  • Posts: 814
  • Thank you received: 219
Hello,

You can have a look at the pyposeidon framework (github.com/ec-jrc/pyPoseidon), in particular the seamesh component (git.immc.ucl.ac.be/jlambrechts/seamsh), where everything is done in python.

Hope this helps,
Sébastien.
The administrator has disabled public write access.
The following user(s) said Thank You: zhanghaijia

Write Selafin file (with mesh) from scratch using Python 9 months 3 weeks ago #44314

  • nicogodet
  • nicogodet's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 166
  • Thank you received: 40
Luc, is it possible to generate the .cli file with your method ?
The administrator has disabled public write access.

Write Selafin file (with mesh) from scratch using Python 9 months 3 weeks ago #44315

  • Lux
  • Lux's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 96
  • Thank you received: 39
No, boundary file is not supported yet in PyTelTools.

(It can be created/written with BlueKenue easily).
The administrator has disabled public write access.

Write Selafin file (with mesh) from scratch using Python 9 months 3 weeks ago #44317

  • Serrer
  • Serrer's Avatar
  • OFFLINE
  • Moderator
  • Posts: 727
  • Thank you received: 307
Hi Simon,

You can use Blue Kenue to import/visualize a 2dm file and then create the cli and slf files.

Martin
The administrator has disabled public write access.

Write Selafin file (with mesh) from scratch using Python 9 months 3 weeks ago #44321

  • simonwp
  • simonwp's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Thank you all for the help - I should be good to go !
The administrator has disabled public write access.
Moderators: borisb

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