mirror of https://gitlab.com/pamhyr/pamhyr2
Results: CustomPlot: Implement plot with time on y axes.
parent
04c8f1ae5f
commit
021971816a
|
|
@ -68,34 +68,9 @@ class CustomPlot(PamhyrPlot):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@timer
|
|
||||||
def draw(self):
|
|
||||||
self.canvas.axes.cla()
|
|
||||||
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
|
||||||
|
|
||||||
if self.data is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
self.canvas.axes.set_xlabel(
|
|
||||||
self._trad[self._x],
|
|
||||||
color='green', fontsize=12
|
|
||||||
)
|
|
||||||
|
|
||||||
self.canvas.axes.set_ylabel(
|
|
||||||
self._trad[self._y_axes[0]],
|
|
||||||
color='green', fontsize=12
|
|
||||||
)
|
|
||||||
|
|
||||||
self._axes = {}
|
self._axes = {}
|
||||||
for axes in self._y_axes[1:]:
|
|
||||||
ax_new = self.canvas.axes.twinx()
|
|
||||||
ax_new.set_ylabel(
|
|
||||||
self._trad[axes],
|
|
||||||
color='green', fontsize=12
|
|
||||||
)
|
|
||||||
self._axes[axes] = ax_new
|
|
||||||
|
|
||||||
if self._x == "kp":
|
def _draw_kp(self):
|
||||||
results = self.data
|
results = self.data
|
||||||
reach = results.river.reach(self._reach)
|
reach = results.river.reach(self._reach)
|
||||||
kp = reach.geometry.get_kp()
|
kp = reach.geometry.get_kp()
|
||||||
|
|
@ -164,13 +139,113 @@ class CustomPlot(PamhyrPlot):
|
||||||
color='r',
|
color='r',
|
||||||
)
|
)
|
||||||
|
|
||||||
elif self._x == "time":
|
def _draw_time(self):
|
||||||
|
results = self.data
|
||||||
|
reach = results.river.reach(self._reach)
|
||||||
|
profile = reach.profile(self._profile)
|
||||||
|
|
||||||
|
meter_axes = self.canvas.axes
|
||||||
|
m3S_axes = self.canvas.axes
|
||||||
|
if "0-meter" in self._y_axes and "1-m3s" in self._y_axes:
|
||||||
|
m3s_axes = self._axes["1-m3s"]
|
||||||
|
|
||||||
|
ts = list(results.get("timestamps"))
|
||||||
|
ts.sort()
|
||||||
|
|
||||||
|
self.canvas.axes.set_xlim(
|
||||||
|
left=min(ts), right=max(ts)
|
||||||
|
)
|
||||||
|
|
||||||
|
x = ts
|
||||||
if "elevation" in self._y:
|
if "elevation" in self._y:
|
||||||
logging.info("TODO: time/elevation")
|
# Z min is constant in time
|
||||||
|
z_min = profile.geometry.z_min()
|
||||||
|
ts_z_min = list(
|
||||||
|
map(
|
||||||
|
lambda ts: z_min,
|
||||||
|
ts
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
meter_axes.plot(
|
||||||
|
ts, ts_z_min,
|
||||||
|
color='grey', lw=1.
|
||||||
|
)
|
||||||
|
|
||||||
if "water_elevation" in self._y:
|
if "water_elevation" in self._y:
|
||||||
logging.info("TODO: time/water_elevation")
|
# Water elevation
|
||||||
|
z = profile.get_key("Z")
|
||||||
|
|
||||||
|
meter_axes.set_ylim(
|
||||||
|
bottom=min(0, min(z)),
|
||||||
|
top=max(z) + 1
|
||||||
|
)
|
||||||
|
|
||||||
|
meter_axes.plot(
|
||||||
|
ts, z, lw=1.,
|
||||||
|
color='b',
|
||||||
|
)
|
||||||
|
|
||||||
|
if "elevation" in self._y:
|
||||||
|
z_min = profile.geometry.z_min()
|
||||||
|
ts_z_min = list(
|
||||||
|
map(
|
||||||
|
lambda ts: z_min,
|
||||||
|
ts
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
meter_axes.fill_between(
|
||||||
|
ts, ts_z_min, z,
|
||||||
|
color='blue', alpha=0.5, interpolate=True
|
||||||
|
)
|
||||||
|
|
||||||
if "discharge" in self._y:
|
if "discharge" in self._y:
|
||||||
logging.info("TODO: time/discharge")
|
q = profile.get_key("Q")
|
||||||
|
|
||||||
|
m3s_axes.set_ylim(
|
||||||
|
bottom=min(0, min(q)),
|
||||||
|
top=max(q) + 1
|
||||||
|
)
|
||||||
|
|
||||||
|
m3s_axes.plot(
|
||||||
|
ts, q, lw=1.,
|
||||||
|
color='r',
|
||||||
|
)
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def draw(self):
|
||||||
|
self.canvas.axes.cla()
|
||||||
|
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||||
|
|
||||||
|
if self.data is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.canvas.axes.set_xlabel(
|
||||||
|
self._trad[self._x],
|
||||||
|
color='green', fontsize=12
|
||||||
|
)
|
||||||
|
|
||||||
|
self.canvas.axes.set_ylabel(
|
||||||
|
self._trad[self._y_axes[0]],
|
||||||
|
color='green', fontsize=12
|
||||||
|
)
|
||||||
|
|
||||||
|
for axes in self._y_axes[1:]:
|
||||||
|
if axes in self._axes:
|
||||||
|
continue
|
||||||
|
|
||||||
|
ax_new = self.canvas.axes.twinx()
|
||||||
|
ax_new.set_ylabel(
|
||||||
|
self._trad[axes],
|
||||||
|
color='green', fontsize=12
|
||||||
|
)
|
||||||
|
self._axes[axes] = ax_new
|
||||||
|
|
||||||
|
if self._x == "kp":
|
||||||
|
self._draw_kp()
|
||||||
|
elif self._x == "time":
|
||||||
|
self._draw_time()
|
||||||
|
|
||||||
self.canvas.figure.tight_layout()
|
self.canvas.figure.tight_layout()
|
||||||
self.canvas.figure.canvas.draw_idle()
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
|
@ -178,7 +253,25 @@ class CustomPlot(PamhyrPlot):
|
||||||
self.toolbar.update()
|
self.toolbar.update()
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def update(self, reach, profile, timestamp):
|
def update(self):
|
||||||
if not self._init:
|
if not self._init:
|
||||||
self.draw()
|
self.draw()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def set_reach(self, reach_id):
|
||||||
|
self._reach = reach_id
|
||||||
|
self._profile = 0
|
||||||
|
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def set_profile(self, profile_id):
|
||||||
|
self._profile = profile_id
|
||||||
|
|
||||||
|
if self._x != "kp":
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def set_timestamp(self, timestamp):
|
||||||
|
self._timestamp = timestamp
|
||||||
|
|
||||||
|
if self._x != "time":
|
||||||
|
self.update()
|
||||||
|
|
|
||||||
|
|
@ -345,6 +345,9 @@ class ResultsWindow(PamhyrWindow):
|
||||||
self.plot_sed_reach.set_reach(reach_id)
|
self.plot_sed_reach.set_reach(reach_id)
|
||||||
self.plot_sed_profile.set_reach(reach_id)
|
self.plot_sed_profile.set_reach(reach_id)
|
||||||
|
|
||||||
|
for plot in self._additional_plot:
|
||||||
|
self._additional_plot[plot].set_reach(reach_id)
|
||||||
|
|
||||||
self.update_table_selection_reach(reach_id)
|
self.update_table_selection_reach(reach_id)
|
||||||
self.update_table_selection_profile(0)
|
self.update_table_selection_profile(0)
|
||||||
|
|
||||||
|
|
@ -358,7 +361,11 @@ class ResultsWindow(PamhyrWindow):
|
||||||
self.plot_sed_reach.set_profile(profile_id)
|
self.plot_sed_reach.set_profile(profile_id)
|
||||||
self.plot_sed_profile.set_profile(profile_id)
|
self.plot_sed_profile.set_profile(profile_id)
|
||||||
|
|
||||||
|
for plot in self._additional_plot:
|
||||||
|
self._additional_plot[plot].set_profile(profile_id)
|
||||||
|
|
||||||
self.update_table_selection_profile(profile_id)
|
self.update_table_selection_profile(profile_id)
|
||||||
|
|
||||||
if timestamp is not None:
|
if timestamp is not None:
|
||||||
self.plot_xy.set_timestamp(timestamp)
|
self.plot_xy.set_timestamp(timestamp)
|
||||||
self.plot_ac.set_timestamp(timestamp)
|
self.plot_ac.set_timestamp(timestamp)
|
||||||
|
|
@ -369,14 +376,8 @@ class ResultsWindow(PamhyrWindow):
|
||||||
self.plot_sed_reach.set_timestamp(timestamp)
|
self.plot_sed_reach.set_timestamp(timestamp)
|
||||||
self.plot_sed_profile.set_timestamp(timestamp)
|
self.plot_sed_profile.set_timestamp(timestamp)
|
||||||
|
|
||||||
self.plot_xy.draw()
|
for plot in self._additional_plot:
|
||||||
self.plot_ac.draw()
|
self._additional_plot[plot].set_timestamp(timestamp)
|
||||||
self.plot_kpc.draw()
|
|
||||||
self.plot_h.draw()
|
|
||||||
|
|
||||||
if self._study.river.has_sediment():
|
|
||||||
self.plot_sed_reach.draw()
|
|
||||||
self.plot_sed_profile.draw()
|
|
||||||
|
|
||||||
self.update_statusbar()
|
self.update_statusbar()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue