The Muk3D Python API provides a convenient function for getting information about deposition runs (the same information that is written to the output window) and then incorporating that data in your script, perhaps to pass results back to Excel, or use as starting points for further loops within the script.
The function can be accessed with the following import statement:
from muk3d.ooze import get_deposition_result
The function get_deposition_result
takes the result object returned from calling a single or multi-stream deposition run in a script, and turns it into an object that can be queried to get information about deposition results. An example of how its used for single-stream deposition is shown below.
1 2 3 4 5 6 7 8 |
cmd = get_command('Single stream no pond, auto flow path fixed elevation')
result = cmd({ 'base': u'grid+dam.mgrid',
....
....
})
dep_result = get_deposition_result(result)
dep_volume = dep_result.get_property('total volume')
|
In line 2, where the single stream deposition model is executed, a result variable is created with the output data from the deposition run. This value is not able to be queried directly by the user in a script, and so the get_deposition_result function takes this and turns the result into something that can be easily queried. This is done in line 7 and the dep_result is an instance of an class called DepositionResult. You can look at the Muk3D API to get details about the methods that this class offers.
In line 8 the deposition volume is returned using the method .get_property. This method will return an element of the deposition result,accessed by name. The name corresponds to the names printed in the deposition results shown in the output widow.
If you have run a multi-stream deposition, this approach will only return the result from the first line. If you look at the API reference for DepositionResult, you can see that the get_property method has 1 mandatory and 1 optional argument. The name argument is the deposition property name (e.g. total volume) and the pipeline_index is optional, zero by default.
1 |
def get_property(self, name, pipeline_index=0)
|
For multi-stream deposition, we can access the different deposition lines by changing the pipeline_index. Note that the first pipeline is always 0, the second will be 1, and so on.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# muk3d macro
# muk3d version: v2019.5.3
# architecture: 64-bit
# Recorded on: 2020-03-26 12:36:19.190000
# Recorded by: carlo
from muk3d.ooze import get_deposition_result
# running command Multi stream fixed pond elevation
# Parameters from dialog
cmd = get_command('Multi stream fixed pond elevation')
result = cmd({ 'base': u'Dam1/grid+dam.mgrid',
'deposition model': 'Multi stream fixed pond elevation',
'maxChange': 2.0,
...
|
In the above script, the number of pipelines is confirmed in line 21, the elevation of each discharge line is shown in lines 22 and 23. The pond volume is printed in line 25. Whether you're using single-stream or multi-stream models, accessing the pond properties is exactly the same.