PyTuflow: Difference between revisions
Content deleted Content added
Ellis Symons (talk | contribs) |
Ellis Symons (talk | contribs) No edit summary |
||
Line 58:
|''tuple'' Adverse Energy Level Gradient Locations ( ''list'' x data, ''list'' y data )
|-
|rowspan='3'|<b>[[#getLongProfileData|getLongProfileData]] (</b> ''float'' Timestep, ''str'' Result Type, ''str'' Channel ID, [optional] ''str'' 2nd Channel ID <b>)</b>
|rowspan='3'|Returns long profile data from a given channel to another channel. If no second channel is specified will continue until no further channels downstream
|''bool'' Error
Line 500:
ax.plot(x, y, label=label, marker='o', linestyle='None')
# add legend to plot
lines, labs = ax.get_legend_handles_labels()
ax.legend(lines, labs)
# show plot
fig.show()
else:
# did not load correctly, print error message to console
print(message)
</pre>
==getLongProfileData==
<b>getLongProfileData (</b> Timestep, Result Type, Channel ID, [optional] 2nd Channel ID <b>)</b><br>
Returns long profile data from a given channel to another channel. If no second channel is specified will continue until no further channels downstream<br>
;Parameters:
: '''Timestep:''' ''float'' or ''str''
:: Output timestep to plot. Can be a value e.g. 1.5 or string e.g. 'max'
: '''Result Type:''' ''str''
:: Result type e.g. 'H'
: '''Channel ID:''' ''str''
:: Starting channel for long profile e.g. 'Chan_A'
: '''2nd Channel ID:''' ''str''
:: Optional downstream channel ID to stop the long profile at e.g. 'Chan_D'
;Returns:
: '''Error:''' ''bool''
:: Returns False on success, True when an error occurred
: '''Message:''' ''str''
:: Accompanying error message if an error occurred
: '''Data:''' ''tuple''
:: ''list'' x data points, ''list'' y data points e.g. ([0, 1, 2], [10, 20, 30])
'''Example'''
<pre>
import matplotlib.pyplot as plt # plotting library
import pytuflow as tu
# Initialise result class
res = tu.ResData()
# load .tpc result file
path = r'C:\TUFLOW\results\M04_5m_001.tpc'
err, message = res.load(path)
# check results were loaded successfully before continuing
if not err:
# initialise plot
fig, ax = plt.subplots()
# get long profiles and add to plot
chan = 'Chan_A'
timestep = '1.0'
result_types = ['Bed Level', 'H'] # get both water level and bed level
for rt in result_types:
err_lp, mess_lp, data = res.getLongProfileData(timestep, rt, chan)
# check for error before plotting
if not err_lp:
x, y = data
ax.plot(x, y, label=rt)
else:
# error occurred getting long profile data, print error message to console
print(mess_lp)
# add legend to plot
lines, labs = ax.get_legend_handles_labels()
| |||