Python Library TUFLOW Results: Difference between revisions
Content deleted Content added
No edit summary |
|||
| (4 intermediate revisions by one other user not shown) | |||
Line 10:
To make this data easier to work with an open source python library has been created and made available. This allows the user to load results and then interact with these. This library does not have any plotting functionality directly, with the returns typically being arrays (e.g. time and flows) however, the examples below give some examples using common plotting libraries such as matplotlib.<br>
=Getting the TUFLOW results python library=
You can find the TUFLOW_results.py (previously TUFLOW_Results2016.py) on
<ol>
: If you select '''Download Latest''' and save the .zip file, the TUFLOW_results.py sits inside the .zip file.</li>
<li>GitHub: [https://github.com/TUFLOW-Support/QGIS-TUFLOW-Plugin QGIS plugin https://github.com/TUFLOW-Support/QGIS-TUFLOW-Plugin]<br>
If you have QGIS2 already: C:\Users\<User Name>\.qgis2\python\plugins\tuflow<br>▼
: If you select '''Clone or Download''' and then select '''Download Zip''' and save the .zip file, the TUFLOW_results.py sits inside the .zip file.</li>
<li>QGIS<br>
▲: If you have QGIS2
: If you have QGIS3 with the TUFLOW plugin installed via the plugin repository, the TUFLOW_results.py sits within: C:\Users\<User Name>\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\tuflow<br></li>
</ol>
The TUFLOW python library does not need to be installed in python (through pip or otherwise) like other common modules, the TUFLOW_results.py file just needs to be in the same location as your python project.
Note it shouldn’t matter if you’re using python 2 or python 3.
=Dependencies=
The TUFLOW results library calls a number of python modules, these are:
Line 154 ⟶ 159:
=Examples=
These examples
==Plot Flow in Channel==
<pre>
Line 161 ⟶ 166:
import matplotlib.pyplot as plt
import TUFLOW_results
input_res = r'C:\TUFLOW\Models\Tutorials\QGIS\Complete_Model\TUFLOW\results\M04\2d\plot\M04_5m_001.tpc'
# initialise the results class
Line 178 ⟶ 185:
#Get flow data
chan_id = 'ds3' # this is the channel ID to use
found, results, message = res.
if found:
print
# plot data
ax1.plot(res.times,results,color='b',label='Flow - '+chan_id)
else:
print
sys.exit()
Line 214 ⟶ 221:
#Get water level data
for node_id in node_ids: #for each node in the list above
found, results, message = res.
if found:
print
# plot data
ax1.plot(res.times,results,label='Level - '+node_id)
else:
print
sys.exit()
Line 248 ⟶ 255:
#Get flow data
found, results, message = res.
if found:
print
ax1.plot(res.times,results,color='b',label='Flow - '+chan_id)
else:
print
sys.exit()
#Get velocity data
found, results, message = res.
if found:
print
ax2.plot(res.times,results,color='r',label='Velocity - '+chan_id)
else:
print
sys.exit()
Line 289 ⟶ 296:
error, message = res.LP_getConnectivity(us_chan,ds_chan)
if error:
print
sys.exit()
else:
print
print
error, message = res.LP_getStaticData()
if error:
print
sys.exit()
else:
print
#create plot
Line 327 ⟶ 334:
=Other Versions=
An older version of the library that is compatible with results from the 2013 version of TUFLOW (this is limited to the 1D results) is also available. This is currently undocumented, however, if you would like this please contact [mailto:support@tuflow.com support@tuflow.com].
| |||