Welcome, Guest
Username: Password: Remember me

TOPIC: How to concatenate two slf files

How to concatenate two slf files 9 years 3 weeks ago #18764

  • special_20
  • special_20's Avatar
Hello all,

I would like to concatenate two slf files into one slf in order to visualise the results with BlueKenue.

The first file, results_1.slf, ranges from time t to time t+1 and the second file, results_2.slf, ranges from time t+1 to time t+2. Both results_1.slf and results_2.slf have the same variables U,V,S,H,MAXZ and I would like to create a third file, results.slf, that ranges from time t to time t+2 and that I could visualise in BlueKenue...

Is there a way to do this and if so can you tell me how to ?
The administrator has disabled public write access.

How to concatenate two slf files 9 years 3 weeks ago #18777

  • riadh
  • riadh's Avatar
Hello

please have a look on the following post , it may help

with my best regards
Riadh
The administrator has disabled public write access.

How to concatenate two slf files 9 years 3 weeks ago #18779

  • special_20
  • special_20's Avatar
Hello Riadh, I'm sorry but the post you suggested didn't help :(

Nonetheless I studied the runSELAFIN.py routine and I added a class concSELAFIN in the secondary classes :

class concSELAFIN(SELAFIN): 

   def __init__(self,f):
      SELAFIN.__init__(self,f)

   def putContent(self,self1,fileName):
      np3o = self.NPOIN3
      # ~~> Filing
      self.fole  = open(fileName,'wb')
      self1.fole = self.fole
      self.appendHeaderSLF()
      varx = np.zeros((self.NVAR,self.NPOIN3),np.float32)

      for t in range(len(self.tags['times'])+len(self1.tags['times'])):
          if t < len(self.tags['times']):
             self.appendCoreTimeSLF(t)
             vars = self.getVALUES(t)
             for iv in range(self.NVAR):
                varx[iv][0:np3o] = vars[iv][0:np3o]
             self.appendCoreVarsSLF(varx)
          elif t > len(self.tags['times']):
             self1.appendCoreTimeSLF(t-len(self1.tags['times']))
             vars = self1.getVALUES(t-len(self1.tags['times']))
             for iv in range(self1.NVAR):
                varx[iv][0:np3o] = vars[iv][0:np3o]
             self1.appendCoreVarsSLF(varx)
      self.fole.close()

and in the main call I added the case concatenate :

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Case of CONCATENATE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   elif codeName == 'concatenate':

      if not options.freplace:
         if len(args) != 4:
            print '\nThe code "concatenate" (without --replace) here requires 3 file names\n'
            sys.exit()
         slfFiles = [args[1:3]]
         outFile = args[3]
      else:
         if len(args) != 3:
            print '\nThe code "concatenate" (with --replace) here requires 2 file name at a time\n'
            sys.exit()
         slfFile = args[1]
         outFile = "concatenate-tmp.slf"

      slfFile  = path.realpath(slfFiles[0][0])
      slf1File = path.realpath(slfFiles[0][1])
      if not path.exists(slfFile):
         print '\nCould not find the file named: ',slfFile
         sys.exit()
      print '\n\nConcatening ' + path.basename(slfFile) + ' within ' + path.dirname(slfFile) + '\n\
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n'
      slf  = concSELAFIN( slfFile )
      slf1 = concSELAFIN( slf1File )
      slf.putContent( slf1,outFile )

      if options.freplace: moveFile(outFile,slfFile)

And then the command to concatenate two slf files is :

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

out.slf is the resulting slf file.

Hope this will help other people B)
The administrator has disabled public write access.

How to concatenate two slf files 9 years 3 weeks ago #18780

  • riadh
  • riadh's Avatar
This looks nice !
We will add it to the script (in there is no redundance)
Thank you!
Riadh
The administrator has disabled public write access.

How to concatenate two slf files 8 years 7 months ago #20756

  • cyamin
  • cyamin's Avatar
  • OFFLINE
  • openTELEMAC Guru
  • Posts: 997
  • Thank you received: 234
Hello all,

I suppose the concatenate functionality has yet to be added to the current version. I tried to add it to the current trunk version but I got the following error:
Traceback (most recent call last):
  File "\\atlas\Company\DataDisk\NET\PROGRAM_FILES\opentelemac\trunk\scripts\python27\runSELAFIN.py", line 1071, in <module>
    main()
  File "\\atlas\Company\DataDisk\NET\PROGRAM_FILES\opentelemac\trunk\scripts\python27\runSELAFIN.py", line 1054, in main
    slf.putContent( slf1,outFile )
  File "\\atlas\Company\DataDisk\NET\PROGRAM_FILES\opentelemac\trunk\scripts\python27\runSELAFIN.py", line 511, in putContent
    self.appendHeaderSLF()
  File "\\atlas\Company\DataDisk\NET\PROGRAM_FILES\opentelemac\trunk\scripts\python27\parsers\parserSELAFIN.py", line 623, in appendHeaderSLF
    f = self.fole['hook']
TypeError: 'file' object has no attribute '__getitem__'
I guess the python scripts have been modified but I cannot figure out how the these scripts work. Can anyone provide some assistance?

Any help would be appreciated.

Regards,
Costas

PS. I'd love to see some basic documentation/examples of the python scripts.
The administrator has disabled public write access.

How to concatenate two slf files 7 years 8 months ago #25436

  • tivincent
  • tivincent's Avatar
Hello,

I have modified my runSELAFIN.py in order to add the proposed "concatenate" functionality (version v7p2)

However I have the same mistake as cyamin.

thanks for any help !
Vincent
The administrator has disabled public write access.

How to concatenate two slf files 7 years 8 months ago #25443

  • special_20
  • special_20's Avatar
Hello all,

The concatenate functionnality was edited with python scripts of Telemac v6p3 and Python v2.7.5. I checked the trunk for v7p2, here are the modifications for the concSELAFIN class that I propose following what is done in the scripts python of v7p2 (this comes with no guarantee) :
class concSELAFIN(SELAFIN): 

   def __init__(self,f):
      SELAFIN.__init__(self,f)

   def putContent(self,self1,fileName):
      np3o = self.NPOIN3
      # ~~> Filing
      self.fole.update = ({ 'hook': open(fileName,'wb') })
      self.file['name'] = fileName
      self1.fole = self.fole
      self.appendHeaderSLF()
      varx = np.zeros((self.NVAR,self.NPOIN3),np.float32)

      for t in range(len(self.tags['times'])+len(self1.tags['times'])):
          if t < len(self.tags['times']):
             self.appendCoreTimeSLF(t)
             vars = self.getVALUES(t)
             for iv in range(self.NVAR):
                varx[iv][0:np3o]
      self.fole['hook'].close()

Can you please tell me if it works ?

Cyamin I am sorry I just saw your message, I do not remember having seen it at the time you posted it.
The administrator has disabled public write access.

How to concatenate two slf files 7 years 8 months ago #25456

  • special_20
  • special_20's Avatar
Hello all,

I made some tests and corrections this morning. Here are the corrections for the concSELAFIN class :
class concSELAFIN(SELAFIN):

   def __init__(self,f):
      SELAFIN.__init__(self,f)

   def putContent(self,self1,fileName):
      np3o = self.NPOIN3
      # ~~> Filing
      self.fole.update({ 'name': fileName })
      self.fole.update({ 'hook': open(fileName,'wb') })
      self1.fole = self.fole
      self.appendHeaderSLF()
      varx = np.zeros((self.NVAR,self.NPOIN3),np.float32)

      for t in range(len(self.tags['times'])+len(self1.tags['times'])):
          if t < len(self.tags['times']):
             self.appendCoreTimeSLF(t)
             vars = self.getVALUES(t)
             for iv in range(self.NVAR):
                varx[iv][0:np3o] = vars[iv][0:np3o]
             self.appendCoreVarsSLF(varx)
          elif t >= len(self.tags['times']):
             self1.appendCoreTimeSLF(t-len(self.tags['times']))
             vars = self1.getVALUES(t-len(self.tags['times']))
             for iv in range(self1.NVAR):
                varx[iv][0:np3o] = vars[iv][0:np3o]
             self1.appendCoreVarsSLF(varx)
      self.fole['hook'].close()

I provide one example with two slf (see attachment). If I do a scan of telemac_Resultats_120.slf, here is what I get :

Interpreting command line options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Scanning telemac_Resultats_120.slf within /fake/path/scripts/python27
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This file appears to be coded in "big endian"
     and the floats are assumed to be SINGLE PRECISION

TITLE        :    <Garonne - permanent \xc3\xa0 3800 m3/s                                  SERAFIN >
DATE / TIME  :  1 - 1 - 1900   0 : 0 : 0
VARIABLES    :
   - VITESSE U       M/S             
   - VITESSE V       M/S             
   - HAUTEUR D'EAU   M               
   - SURFACE LIBRE   M               
NUMBERs      :
   - NPLAN* =  0 
   - NPTFR* =  0 
   - IFACE* =  0
   - NELEM3 =  34659 
   - NPOIN3 =  17989 
   - NDP3   =  3 
   - NPLAN  =  1
MESH         : / min: [  0.0 ; -10.0 ]  / max: [  3000.0 ; 1000.0 ]
ARRAYs       :
   - IKLE  : / min: [  1 ]  / max: [  17989 ] [[    1   103   102]
 [    1   102     2]
 [    2   102   105]
 ..., 
 [17984 17988 17989]
 [17984 17989 13782]
 [17984 13782 13781]]
   - IPOBO : / min: [  0 ]  / max: [  17989 ] [    1     2     3 ..., 17987 17988 17989]
NUMBER OF TIMES :  2
FIRST TIME STEP :  0.0
LAST TIME STEP  :  120.0
TIME STEP       :  120.0


My work is done

And now if I do a scan of telemac_Resultats_240.slf, here is what I get:

Interpreting command line options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Scanning telemac_Resultats_240.slf within /fake/path/scripts/python27
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This file appears to be coded in "big endian"
     and the floats are assumed to be SINGLE PRECISION

TITLE        :    <Garonne - permanent \xc3\xa0 3800 m3/s                                  SERAFIN >
DATE / TIME  :  1 - 1 - 1900   0 : 0 : 0
VARIABLES    :
   - VITESSE U       M/S             
   - VITESSE V       M/S             
   - HAUTEUR D'EAU   M               
   - SURFACE LIBRE   M               
NUMBERs      :
   - NPLAN* =  0 
   - NPTFR* =  0 
   - IFACE* =  0
   - NELEM3 =  34659 
   - NPOIN3 =  17989 
   - NDP3   =  3 
   - NPLAN  =  1
MESH         : / min: [  0.0 ; -10.0 ]  / max: [  3000.0 ; 1000.0 ]
ARRAYs       :
   - IKLE  : / min: [  1 ]  / max: [  17989 ] [[    1   103   102]
 [    1   102     2]
 [    2   102   105]
 ..., 
 [17984 17988 17989]
 [17984 17989 13782]
 [17984 13782 13781]]
   - IPOBO : / min: [  0 ]  / max: [  17989 ] [    1     2     3 ..., 17987 17988 17989]
NUMBER OF TIMES :  1
FIRST TIME STEP :  240.0
LAST TIME STEP  :  240.0
ONLY ONE TIME FRAME


My work is done

Now if I concatenate telemac_Resultats_120.slf and telemac_Resultats_240.slf in telemac_Resultats_240_conc.slf and I do a scan of telemac_Resultats_240_conc.slf, here is what I get :

Interpreting command line options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Scanning telemac_Resultats_240_conc.slf within /fake/path/scripts/python27
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This file appears to be coded in "big endian"
     and the floats are assumed to be SINGLE PRECISION

TITLE        :    <Garonne - permanent \xc3\xa0 3800 m3/s                                  SERAFIN >
DATE / TIME  :  1 - 1 - 1900   0 : 0 : 0
VARIABLES    :
   - VITESSE U       M/S             
   - VITESSE V       M/S             
   - HAUTEUR D'EAU   M               
   - SURFACE LIBRE   M               
NUMBERs      :
   - NPLAN* =  0 
   - NPTFR* =  0 
   - IFACE* =  0
   - NELEM3 =  34659 
   - NPOIN3 =  17989 
   - NDP3   =  3 
   - NPLAN  =  1
MESH         : / min: [  0.0 ; -10.0 ]  / max: [  3000.0 ; 1000.0 ]
ARRAYs       :
   - IKLE  : / min: [  1 ]  / max: [  17989 ] [[    1   103   102]
 [    1   102     2]
 [    2   102   105]
 ..., 
 [17984 17988 17989]
 [17984 17989 13782]
 [17984 13782 13781]]
   - IPOBO : / min: [  0 ]  / max: [  17989 ] [    1     2     3 ..., 17987 17988 17989]
NUMBER OF TIMES :  3
FIRST TIME STEP :  0.0
LAST TIME STEP  :  240.0
TIME STEP       :  120.0


My work is done

Be aware that when you use the --replace option with concatenate it concatenates telemac_Resultats_120.slf and telemac_Resultats_240.slf in telemac_Resultats_120.slf

Regards.
Attachments:
The administrator has disabled public write access.
Moderators: Serrer, a.barton

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