Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Concatenating *.slf results with PYTHON

Concatenating *.slf results with PYTHON 9 years 5 months ago #17086

  • pprodano
  • pprodano's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 96
  • Thank you received: 55
Hello,

I am working on developing a library of all possible combinations of wave heights, periods, directions, and water levels for a coastal domain. For this, I have set up a small python script that writes and executes TOMAWAC for a large number of discrete combinations of above variables. In the end, I have something like 2000 results files in one directory, all numbered 0001_name.slf, 0002_name.slf, ... 2000_name.slf. Each result file has the same geometry, variable names, number of time steps, etc.

What I wish to do is take the last record of each result file (for every variable), and store it into one master *.slf file. I am envisioning this master *.slf file will be used by t2d-sis coupling to read appropriate wave results in morphological simulations.

The pseudo code for this concatenation would be something like:
open each result file
--> go to last time record
--> read results for all variables
--> add a time record to master file, and append results to master file
close each result file

Can someone help in getting me get started on this? My knowledge of PYTHON is limited to rudimentary reading and processing of *.slf result files. I guess I am after the names of methods (or functions) which can be used to accomplish the above.

Thank you in advance,

Pat
The administrator has disabled public write access.

Concatenating *.slf results with PYTHON 9 years 5 months ago #17089

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

If you go through the existing library in python you should find the way to extract the last time step with runSELAFIN.py chop and the way to merge result files into one with runSELAFIN.py merge.

Hopefully that will put you on the right track.

Sébastien.
The administrator has disabled public write access.

Concatenating *.slf results with PYTHON 9 years 5 months ago #17095

  • pprodano
  • pprodano's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 96
  • Thank you received: 55
Hello Sébastien.

Thank you for your reply. I ran
python runSELAFIN.py chop --from=24 --step=1 --stop=24 input.slf input_chopped.slf

and it worked as desired (it extracted the 24th time frame).

However, for the merge option, I can't seem to figure out the list of input options. I tried to merge in1.slf with in2.slf, with
python runSELAFIN.py merge in1.slf in2.slf out.slf

thinking that it would concatenate the two intput files, but it did not. How do I use the merge option to create out.slf that contains all the time frames from in1.slf and in2.slf?

Thank you in advance,

Pat
The administrator has disabled public write access.

Concatenating *.slf results with PYTHON 9 years 5 months ago #17100

  • sebourban
  • sebourban's Avatar
  • OFFLINE
  • Administrator
  • Principal Scientist
  • Posts: 814
  • Thank you received: 219
I see -- I think it may be that all your files have the same variables and the same time step.

One option could be to alter.py you variable names so they include some of the settings, and then do your merge.

Just a though.

Sébastien.

PS: can you tell me what is in your out.slf in your example ?
The administrator has disabled public write access.

Concatenating *.slf results with PYTHON 9 years 5 months ago #17105

  • pprodano
  • pprodano's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 96
  • Thank you received: 55
Hi Sébastien,

Yes, all of the files have the same variable names, and same time steps. The out.slf that gets created has results, but are not merged results.

As an alternate way to do this, I tried the following:
import os,sys
from os import path
import numpy as np
python27 = '/home/user/opentelemac/v7p0r1/scripts/python27/'
sys.path.append(path.join(path.dirname(sys.argv[0]),python27))
from parsers.parserSELAFIN import SELAFIN  

in1_file = "in1.slf"
in2_file = "in2.slf"

slf = SELAFIN(in1_file)
qlf = SELAFIN(in2_file)

# puts the content of in2.slf to in1.slf
qlf.putContent(in1_file)

But this simply copies the content of in2.slf to in1.slf. Is there a way to extract values from a file for a particular time frame (in my case index 24) with
z2 = qlf.getVALUES(24)

and then append the results from z2 to an existing slf object?

Thanks,

Pat
The administrator has disabled public write access.

Concatenating *.slf results with PYTHON 9 years 3 weeks ago #18781

  • special_20
  • special_20's Avatar
Hello pprodano,

I posted a solution to your problem in this topic.

Hope this will help
The administrator has disabled public write access.

Concatenating *.slf results with PYTHON 8 years 7 months ago #20740

  • amanj2013
  • amanj2013's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 211
  • Thank you received: 24
Hello dear,

Is it possible to share your python script and the way how to create multiple scenarios with python?

Kind Regards,

AMANJ
The administrator has disabled public write access.

Concatenating *.slf results with PYTHON 8 years 7 months ago #20773

  • special_20
  • special_20's Avatar
Hello, I already detailed in this topic how to modify the runSELAFIN.py to add the concatenate option. Nonetheless I add the runSELAFIN.py file that I modified on my own in attachment. The command to concatenate two files file1.slf and file2.slf in a third file out.slf is :

python runSELAFIN.py concatenate file1.slf file2 out.slf

Sorry, I don't understand what you mean by creating multiple scenarios with python.

Regards ;)

File Attachment:

File Name: runSELAFIN.py
File Size: 48 KB
The administrator has disabled public write access.

Concatenating *.slf results with PYTHON 8 years 7 months ago #20778

  • amanj2013
  • amanj2013's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 211
  • Thank you received: 24
Sorry dear,

My question was for PAT where he wrote a python script and through this you can automate of creating multiple scenarios say 100 scenarios. I want to know how to do this which will help with time saving and also creating batch file to run each scenarios in a series of run.

Cheers,

AMANJ
The administrator has disabled public write access.

Concatenating *.slf results with PYTHON 8 years 7 months ago #20781

  • special_20
  • special_20's Avatar
Hum, sorry, I believed you were talking about my own script. I didn't understand you were talking about the script of PAT.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: borisb

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