PyTuflow: Difference between revisions
Content deleted Content added
Ellis Symons (talk | contribs) |
Ellis Symons (talk | contribs) No edit summary |
||
Line 72:
|''list'' y values
|-
|rowspan='1'|<b>[[#getPipes|getPipes]] ()</b>
|rowspan='1'|Returns any pipe or culvert data in the current profile. Note getLongProfileData method must be called prior to calling this method
|''list'' pipes [ ''list'' pipe vertexes [ ''tuple'' vertex ( x point, y point ) ] ]
Line 628:
comb_labs = labs + labs2
ax.legend(comb_lines, comb_labs)
# show plot
fig.show()
else:
# did not load correctly, print error message to console
print(message)
</pre>
==getPipes==
<b>getPipes ()</b><br>
Returns any pipe or culvert data in the current profile. Note getLongProfileData method must be called prior to calling this method<br>
;Parameters:
: -
;Returns:
: '''Pipe list:''' ''list''
:: Vertex list: ''list''
::: Vertex coords: ''tuple''
::: e.g. [[(0, 0), (0, 1), (1, 1), (1, 0)], [(1, 1), (1, 2), (2, 2), (2, 1)]]
'''Example'''
<pre>
import matplotlib.pyplot as plt # plotting library
from matplotlib.patches import Polygon # will add pipes and culverts as polygon
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)
# get pipes and culverts and add to plot
pipes = res.getPipes()
for pipe in pipes: # loop through all pipes
polygon = Polygon(pipe, facecolor='0.9', edgecolor='0.5', label='Culverts and Pipes')
ax.add_patch(polygon)
# add legend to plot
lines, labs = ax.get_legend_handles_labels()
# filter duplicate legend items (if there is more than one pipe or culvert)
unique_lines = []
unique_labels = []
for i, label in enumerate(labels):
if label not in unique_labels:
unique_labels.append(label)
unique_lines.append(lines[i])
ax.legend(unique_lines, unique_labels)
# show plot
| |||