Python Library TUFLOW Results: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 144:
=Examples=
These examples can be downloaded in .py format along with the example results from the TUFLOW website (link required).
==Plot Flow in Channel==
<pre>
import os #operating system functions
Line 150 ⟶ 151:
import TUFLOW_results2016
 
# initialise the results class
res = TUFLOW_results2015.ResData()
 
# Load the data and terminate if error returned
error, message = res.Load(input_res)
if error:
Line 156 ⟶ 160:
sys.exit()
print('loaded')
 
#create a figure
fig = plt.figure() #create new figure
ax1 = fig.add_axes((0.10, 0.15, 0.85,0.75)) #add axis to figure
 
#Get flow data
chan_id = 'ds3' # this is the channel ID to use
found, results, message = res.getTS(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()
 
# manage plot
ax1.set_xlabel('Time (hours)')
ax1.set_ylabel('Flow (m3/s)')
ax1.set_title('Example time-series - single location')
ax1.grid()
ax1.legend()
plt.show()
</pre>
 
<br>
[[File:Python Results 2016 Q Example 01.png|600px]]
<br>
This will create a figure that looks like the above.
<br>
==Plot Multiple Water Levels==
In this example, it is assumed that the results data has been loaded as per the above.
<pre>
#create plot
fig = plt.figure() #create new figure
ax1 = fig.add_axes((0.10, 0.15, 0.85,0.75)) #add axis to figure
 
# list of nodes to plot
node_ids = ['FC01.14.1','FC01.15.1','FC01.16.1','FC01.17.1']
 
#Get water level data
for node_id in node_ids: #for each node in the list above
found, results, message = res.getTS(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()
 
# manage plot
ax1.set_xlabel('Time (hours)')
ax1.set_ylabel('Water Level (mAHD)')
ax1.set_title('Example time-series - multiple locations')
ax1.set_ybound((38.,44.)) #overwrite the y axis bounds
ax1.grid()
ax1.legend(loc='lower right')
plt.show()
</pre>
<br>
[[File:Python Results 2016 H Example 01.png|600px]]
This will create a figure that looks like the above.<br>
<br>
==Dual Axis (flow and velocity) Plot==
In this example it is assumed the results have been loaded as per example 1.
<pre>
# specify channel to plot
chan_id = 'ds3'
 
#create plot
fig = plt.figure() #create new figure
ax1 = fig.add_axes((0.10, 0.15, 0.80,0.75)) #add axis to figure
ax2 = ax1.twinx() #create new axis with same x properties
 
#Get flow data
found, results, message = res.getTS(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.getTS(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()
 
# manage plot
ax1.set_xlabel('Time (hours)')
ax1.set_ylabel('Flow (m3/s)')
ax2.set_ylabel('Velocity (m/s)')
ax1.set_title('Example time-series - twin axis')
ax1.grid()
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
ax1.legend(h1+h2, l1+l2, loc='upper left')
plt.show()
</pre>
<br>
[[File:Python Results 2016 QV Example 01.png|600px]]
<br>
This will create a figure that looks like the above.<br>
==Long Profile Peak Levels==
This also assumes that the data has been loaded as per example 1 above. The long profile data for all channels downstream of '''FC01.40''' will be plotted.
<pre>
us_chan = 'FC01.40' #upstream channel
ds_chan = None
 
#get connectivity between channels
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
fig = plt.figure() #create new figure
ax1 = fig.add_axes((0.10, 0.15, 0.85,0.80)) #add axis to figure
 
#plot data
# Max WL
ax1.plot(res.LP.dist_nodes, res.LP.Hmax,color='r',label = 'Max Water Level')
 
# Bed Level
ax1.plot(res.LP.dist_chan_inverts, res.LP.chan_inv,color='brown',linewidth = '3',label = 'Bed Level Level')
 
# manage plot
ax1.set_xlabel('Distance (m)')
ax1.set_ylabel('Level (mAHD)')
ax1.set_title('Example Long Profile - Peak Levels')
ax1.grid()
ax1.legend(loc='upper right')
plt.show()
</pre>
<br>
[[File:Python Results 2016 LP Example 01.png]]
<br>
This will create a figure that looks like the above.<br>
==Long Profile with additional data==
To be completed.
==Plotting Results from Multiple Simulations==
To be completed.
=Other Versions=
An older version that is compatible with results from the 2013 version of TUFLOW (this is limited to the 1D results for this version). This is currently undocumented, however, if you would like this please contact support@tuflow.com.