Welcome, Guest
Username: Password: Remember me

TOPIC: Run telemac2d.py from a python script.

Run telemac2d.py from a python script. 8 years 1 month ago #24095

  • chelobarros
  • chelobarros's Avatar
hi, i have been trying to run a simulation of telemac2d from within a python script, but whit the methods i have found it claims there is no such file telemac2d , i use the complete rout to the source files in V7 version, it changes error to cant find the systel file.

this is strange because every other linux terminal commands works fine. but particularly telemac files appear not to be in variable PATH from linux, but i can run a simulation just directly in the terminal by typing "telemac2d.py file.cas" and it works fine, because i already add the systel and telemac2d path to the variable path.

has anybody has experience whit this?

grettings,
chelo.
The administrator has disabled public write access.

Run telemac2d.py from a python script. 8 years 1 month ago #24097

  • yugi
  • yugi's Avatar
  • OFFLINE
  • openTELEMAC Guru
  • Posts: 851
  • Thank you received: 244
Hi,

You need to add $HOMETEL/scripts/python27 to the variable PYTHONPATH
Then you should be able to do
import telemac2d
There are 10 types of people in the world: those who understand binary, and those who don't.
The administrator has disabled public write access.

Run telemac2d.py from a python script. 8 years 1 month ago #24098

  • cyamin
  • cyamin's Avatar
  • OFFLINE
  • openTELEMAC Guru
  • Posts: 997
  • Thank you received: 234
Hello,
I am not sure what is exactly you are asking, but if I understood correctly you are trying to start a telemac2d computation from within a python script. I am sure there is a more 'pythonic' way to do this, but what I do is construct the command as a string and then call it with subprocess. Here is an non-working example to get the idea.
import subprocess
t2d_sis = r'telemac2d.py -c gfmsmpi_i7 --ncsize=4 t2d_sis.cas'
subprocess.check_call(t2d_sis, shell=True)

Of course paths etc, need to be sorted out first.

Regards,
Costas
The administrator has disabled public write access.

Run telemac2d.py from a python script. 8 years 1 month ago #24105

  • chelobarros
  • chelobarros's Avatar
hi, thanks everybody for taking the time to respond.
it appears there is several ways to do it.

I made mine work by looking in the run_code.py file to know where exactly I must change the variable name. I just made things easy for me and copied the systel file I use to the default value in run_code.py.
it worked.

also tried the add ptyhon variable and it worked too.

as cyamin said I am sure there is a better way to do this but mine worked like this,

import os
os.system('/home/chelobarros/v7p1r0/scripts/python27/telemac2d.py 00_malla_40m.cas')

I read that os.system is to be deprecated but I used it anyway , seems subprocces method is now preferred.

greetings,
chelo.
The administrator has disabled public write access.
Moderators: pham

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