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

In this tutorial we will

  • use DeltaShell scripting to read this HIS file
  • export results to csv file

Before starting this tutorial you need:

  • to have successfully finished a morphological simulation with SOBEK
  • to have followed or understand this tutorial

Step-by-step guide

  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

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

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

    # 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. Note: instead of the timestep keyword, you can use the location keyword to extract a timeseries for one location

    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

    # 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. Finally, click 'Run script' or select all and hit Ctrl+Enter. The csv file should be next to your *.dsproj file.

 

The full code:

#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