Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

 

 

In SOBEK 3.4 and previous versions, morphological results are written to the following file: *.dsproj_data/<flowmodel name>_output/work/morph-gr.his.

...

  1. Start DeltaShell and open your Flow model
  2. In the toolbox, open a new script
  3. Start your script by importing the necessary modules

    Code Block
    languagepy
    linenumberstrue
    import os
    from ModellerFunctions import dsget
  4. Next, use dsget to retrieve your Flow model location of the hisfile:

    Code Block
    languagepy
    linenumberstrue
    flow = dsget.GetFlow1DModel()
    print(dsget.GetMorHisFilePath(flow))
  5.  dsget has some functions to inspect this his file. 

    Code Block
    languagepy
    linenumberstrue
    # To see which output is available in the his file
    components = dsget.GetMorphologyComponents(flow)
    
    # To see the available times 
    timesteps = dsget.GetMorphologyTimeSteps(flow)
    
    # The number of timesteps:
    print('There are %i timesteps of morphological results'%len(timesteps))
  6. We might need to plot the difference in initial (timestep 0) bed level, and the bed level after the morphological simulation. You can retrieve the data for this plot in the following way:

    Code Block
    languagepy
    linenumberstrue
    data_initial = dsget.GetMorphologyResults(flow, component=0, timestep=0)
    data_last = dsget.GetMorphologyResults(flow, component=0, timestep=len(timesteps)-1)
  7. To export this data to csv file, we use standard Python methods

    Code Block
    languagepy
    linenumberstrue
    # Print in the same location as the *.dsproj file
    outputpath = os.path.join(dsget.GetProjectPath(), 'morph-gr.csv')
    
    with open(outputpath, 'w') as f:
        for i, forget in enumerate(data_initial):
            f.write('"%s", %s, %s\n'%(data_initial[i][0], data_initial[i][1], data_last[i][1]))
  8. The full code:

    Code Block
    languagepy
    linenumberstrue
    #region // Imports
    
    # Python standard libraries
    import os
    
    # SOBEK OpenEarth library
    from ModellerFunctions import dsget
    
    #endregion 
    
    #region // Retrieve data
    
    # get the Flow model and path to his file
    flow = dsget.GetFlow1DModel()
    print dsget.GetMorHisFilePath(flow)
    
    # To see which output is available in the his file:
    components = dsget.GetMorphologyComponents(flow)
    timesteps = dsget.GetMorphologyTimeSteps(flow)
    print('There are %i timesteps of morphological results'%len(timesteps))
    
    # Results for bed level (component 0) 
    data_initial = dsget.GetMorphologyResults(flow, component=0, timestep=0)
    data_last = dsget.GetMorphologyResults(flow, component=0, timestep=len(timesteps)-1)
    #endregion
    
    #region // print to csv file 
    
    # Print in the same location as the *.dsproj file
    outputpath = os.path.join(dsget.GetProjectPath(), 'morph-gr.csv')
    
    with open(outputpath, 'w') as f:
        for i, forget in enumerate(data_initial):
            f.write('"%s", %s, %s\n'%(data_initial[i][0], data_initial[i][1], data_last[i][1]))
    #endregion

...

Content by Label
showLabelsfalse
max5
spacesSobek
sortmodified
showSpacefalse
reversetrue
typepage
labelstutorial tut-modelling tut-scripting tut-morphology