Welcome, Guest
Username: Password: Remember me

TOPIC: read and write selafin files in Python

read and write selafin files in Python 2 years 11 months ago #38596

  • nitesh
  • nitesh's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 73
  • Thank you received: 1
Hi,

Couldn't add the other files in the above post.
Please use this link to access the files:

drive.google.com/drive/folders/1utKzmP3f...7UG0E4vk?usp=sharing
The administrator has disabled public write access.

read and write selafin files in Python 2 years 11 months ago #38597

  • taoan
  • taoan's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 52
  • Thank you received: 9
Hello Nitesh,

I adjusted this python script based on yours.
I checked the new output selafin on bluekenue and it looks ok

Hope this helps

Regards,

Taoan


File Attachment:

File Name: rain_telemac.py
File Size: 2 KB
The administrator has disabled public write access.
The following user(s) said Thank You: nitesh

read and write selafin files in Python 2 years 11 months ago #38598

  • nitesh
  • nitesh's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 73
  • Thank you received: 1
Thank you so much Taoan!
This is exactly what I needed!
The administrator has disabled public write access.

read and write selafin files in Python 2 years 6 months ago #39237

  • Aldir007
  • Aldir007's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
hi taoan
I tried your script only for the reading part. I changed the path to the pputils-master directory but I get an error on importing the module. i tried using:
set PYTHONPATH=%PYTHONPATH%;C:\opentelemac-mascaret\v8p0r0\scripts\python27\pputils-master
but its not working either
any idea what should I do?
The administrator has disabled public write access.

read and write selafin files in Python 2 years 6 months ago #39265

  • taoan
  • taoan's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 52
  • Thank you received: 9
Hello,

import errors are related with path location for the module
is it your first experience with python?

My suggestion is to change for something like this line:

sys.path.append(path.join( path.dirname(sys.argv[0]),'C:\opentelemac-mascaret\\v8p0r0\\scripts\\python27\\pputils-master'))# put your pputils adress here

On windows double \\ is necessary.

Can you post your script file for checking?

With best regards,

Taoan
The administrator has disabled public write access.
The following user(s) said Thank You: Aldir007

read and write selafin files in Python 2 years 3 months ago #39761

  • Yunhao Song
  • Yunhao Song's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 118
  • Thank you received: 9
Hello Taoan,

Thanks for sharing the python script, based on which I created the binary file for the time and space varying variable ZSD (Secchi depth). While checking the output Selafin file with BlueKenue I found the variable name remained unchanged, it seems line 50:
vnames.append('RAINI')
didn't work in my case. Could you please have a look at it?

Best regards,
Yunhao
The administrator has disabled public write access.

read and write selafin files in Python 2 years 3 months ago #39762

  • Yunhao Song
  • Yunhao Song's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 118
  • Thank you received: 9
Hello again,

I slightly modified your python script by placing 'slf2.writeHeader()' after line 50 'vnames.append' and problem solved!

Cheers,
Yunhao
The administrator has disabled public write access.

read and write selafin files in Python 10 months 4 weeks ago #42809

  • Renault
  • Renault's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 100
  • Thank you received: 26
Hi all,

I thought I'd contribute a similar version of the read-write script above. My goal was to merge values from two different files, namely copying BOTTOM from a "bathymetry" file to a "previous computation" file (from GAIA) so that sediment information would be preserved, but a new bottom would be applied. I also take the opportunity to reset CUMUL BED EVOL to 0 over the whole domain. If necessary, it would be possible to also use data from the first time step of the "previous computation" file and apply it to the last time step, but I didn't need to do that in this case.

The output file contains the last time step of the "previous computation" file, with the modified variables. This, of course, assumes that the two files have the same number of points. I also modified the script to be slightly more in keeping with Python best practices; as well, I use it from the command line with the following syntax:
python3 merge_slf.py -p "previous-computation.slf" -b "bathymetry.slf" -o "output.slf"
As in the other script, you will have to modify the path to your pputils install. There is probably a way to add pputils to $PYTHONPATH and have it work automatically, but I couldn't be bothered to figure that out :silly:

I hope this can be useful to someone else, even if only as a starting point to your own scripting. Maybe someday, it will be easy to read/write the selafin format without external libraries :whistle:
Attachments:
The administrator has disabled public write access.
Moderators: borisb

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