In SOBEK 3.4 and previous versions, morphological results are written to the following file: *.dsproj_data/<flowmodel name>_output/work/morph-gr.his.
...
- Start DeltaShell and open your Flow model
- In the toolbox, open a new script
Start your script by importing the necessary modules
Code Block language py linenumbers true import os from ModellerFunctions import dsget
Next, use dsget to retrieve your Flow model location of the hisfile:
Code Block language py linenumbers true flow = dsget.GetFlow1DModel() print(dsget.GetMorHisFilePath(flow))
dsget has some functions to inspect this his file.
Code Block language py linenumbers true # 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))
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 language py linenumbers true data_initial = dsget.GetMorphologyResults(flow, component=0, timestep=0) data_last = dsget.GetMorphologyResults(flow, component=0, timestep=len(timesteps)-1)
To export this data to csv file, we use standard Python methods
Code Block language py linenumbers true # 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]))
The full code:
Code Block language py linenumbers true #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
Content by Label | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|