An error occurred while loading the file. Please try again.
-
Theophile Terraz authoredeb26eba1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# PlotAC.py -- Pamhyr
# Copyright (C) 2023 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
from tools import timer
from View.Tools.PamhyrPlot import PamhyrPlot
from matplotlib import pyplot as plt
from PyQt5.QtCore import (
QCoreApplication
)
_translate = QCoreApplication.translate
class PlotAC(PamhyrPlot):
def __init__(self, canvas=None, trad=None, toolbar=None,
results=None, reach_id=0, profile_id=0,
parent=None):
super(PlotAC, self).__init__(
canvas=canvas,
trad=trad,
data=results,
toolbar=toolbar,
parent=parent
)
self._current_timestamp = max(results.get("timestamps"))
self._current_reach_id = reach_id
self._current_profile_id = profile_id
@property
def results(self):
return self.data
@results.setter
def results(self, results):
self.data = results
self._current_timestamp = max(results.get("timestamps"))
@timer
def draw(self, highlight=None):
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
if self.results is None:
return
self.canvas.axes.set_xlabel(
_translate("MainWindow_reach", "X (m)"),
color='black', fontsize=11
)
self.canvas.axes.set_ylabel(
_translate("MainWindow_reach", "Elevation (m)"),
color='black', fontsize=11
)
reach = self.results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id)
x = profile.geometry.get_station()
z = profile.geometry.z()
self.canvas.axes.set_xlim(
left=min(x), right=max(x)
)
self.line_kp, = self.canvas.axes.plot(
x, z,
linestyle="solid",
lw=1.8,
color='grey',
)
kp = reach.geometry.get_kp()
# Water elevation
water_z = profile.get_ts_key(self._current_timestamp, "Z")
self.water, = self.canvas.axes.plot(
[min(x), max(x)], [water_z, water_z],
lw=1., color='b',
)
self.collection = self.canvas.axes.fill_between(
x, z, water_z,
where=z <= water_z,
color='skyblue', alpha=0.7, interpolate=True
)
self.liste_chemins = self.collection.get_paths()
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
if self.toolbar is not None:
self.toolbar.update()
def set_reach(self, reach_id):
self._current_reach_id = reach_id
self._current_profile_id = 0
self.update()
def set_profile(self, profile_id):
self._current_profile_id = profile_id
self.update()
def set_timestamp(self, timestamp):
self._current_timestamp = timestamp
self.update_poly()
def update(self):
reach = self.results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id)
x = profile.geometry.get_station()
z = profile.geometry.z()
self.line_kp.set_data(x, z)
self.canvas.axes.set_xlim(
left=min(x), right=max(x)
)
kp = reach.geometry.get_kp()
# Water elevation
water_z = profile.get_ts_key(self._current_timestamp, "Z")
self.water.set_data([min(x), max(x)], [water_z, water_z])
self.collection.remove()
self.collection = self.canvas.axes.fill_between(
x, z, water_z,
where=z <= water_z,
color='skyblue', alpha=0.7, interpolate=True
)
self.canvas.figure.canvas.draw_idle()
def update_poly(self):
reach = self.results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id)
x = profile.geometry.get_station()
z = profile.geometry.z()
# Water elevation
water_z = profile.get_ts_key(self._current_timestamp, "Z")
self.water.set_data([min(x), max(x)], [water_z, water_z])
self.collection.remove()
self.collection = self.canvas.axes.fill_between(
x, z, water_z,
where=z <= water_z,
color='skyblue', alpha=0.7, interpolate=True
)
self.canvas.figure.canvas.draw_idle()