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

In this tutorial we will

Before starting this tutorial you need:

Step-by-step guide

Add the steps involved:

  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:

    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. 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

 

Related articles

Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.