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 ourthe GitHubQGIS plugin repository, QGISon pluginthe TUFLOW support GitHub repository, or if you have QGIS and the TUFLOW plugin installed, you will already have it on your computer.
<ol>
 
GitHub<li>QGIS plugin repo: [https://githubplugins.comqgis.org/TUFLOW-Supportplugins/tuflow/QGIS-TUFLOW-Plugin https://githubplugins.comqgis.org/TUFLOW-Supportplugins/tuflow/QGIS-TUFLOW-Plugin]<br>
: If you select '''Download Latest''' and save the .zip file, the TUFLOW_results.py sits inside the .zip file.</li>
QGIS plugin repo: [https://plugins.qgis.org/plugins/tuflow/ https://plugins.qgis.org/plugins/tuflow/]<br>
<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 alreadywith the TUFLOW plugin installed via the plugin repository, the TUFLOW_results.py sits within: C:\Users\<User Name>\.qgis2\python\plugins\tuflow<br>
: 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 canwork bewith downloadedthe inTutorial Model module 4 results.py format alongThe withtutorial themodel examplecan resultsbe downloaded fromon the [https://www.tuflow.com/Tuflow%20Tutorial%20Models.aspx TUFLOW website (link required)].
==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.getTSgetTSData(chan_id,'1D','Q','L')
if found:
print ('found requested data')
# plot data
ax1.plot(res.times,results,color='b',label='Flow - '+chan_id)
else:
print (message)
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.getTSgetTSData(node_id,'1D','H','P')
if found:
print ('found requested data')
# plot data
ax1.plot(res.times,results,label='Level - '+node_id)
else:
print (message)
sys.exit()
 
Line 248 ⟶ 255:
 
#Get flow data
found, results, message = res.getTSgetTSData(chan_id,'1D','Q','L')
if found:
print ('found requested data')
ax1.plot(res.times,results,color='b',label='Flow - '+chan_id)
else:
print (message)
sys.exit()
 
#Get velocity data
found, results, message = res.getTSgetTSData(chan_id,'1D','V','L')
if found:
print ('found requested data')
ax2.plot(res.times,results,color='r',label='Velocity - '+chan_id)
else:
print (message)
sys.exit()
 
Line 289 ⟶ 296:
error, message = res.LP_getConnectivity(us_chan,ds_chan)
if error:
print (message)
sys.exit()
else:
print ('LP connectivity determined.')
 
print ('Get LP static data')
error, message = res.LP_getStaticData()
if error:
print (message)
sys.exit()
else:
print ('LP static data retrieved')
 
#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].