Commit 02197181 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Results: CustomPlot: Implement plot with time on y axes.

Showing with 177 additions and 83 deletions
+177 -83
...@@ -68,109 +68,184 @@ class CustomPlot(PamhyrPlot): ...@@ -68,109 +68,184 @@ class CustomPlot(PamhyrPlot):
) )
) )
@timer self._axes = {}
def draw(self):
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
if self.data is None: def _draw_kp(self):
return results = self.data
reach = results.river.reach(self._reach)
kp = reach.geometry.get_kp()
z_min = reach.geometry.get_z_min()
self.canvas.axes.set_xlabel( self.canvas.axes.set_xlim(
self._trad[self._x], left=min(kp), right=max(kp)
color='green', fontsize=12
) )
self.canvas.axes.set_ylabel( meter_axes = self.canvas.axes
self._trad[self._y_axes[0]], m3S_axes = self.canvas.axes
color='green', fontsize=12 if "0-meter" in self._y_axes and "1-m3s" in self._y_axes:
) m3s_axes = self._axes["1-m3s"]
self._axes = {} if "elevation" in self._y:
for axes in self._y_axes[1:]: meter_axes.set_ylim(
ax_new = self.canvas.axes.twinx() bottom=min(0, min(z_min)),
ax_new.set_ylabel( top=max(z_min) + 1
self._trad[axes],
color='green', fontsize=12
) )
self._axes[axes] = ax_new
if self._x == "kp": meter_axes.plot(
results = self.data kp, z_min,
reach = results.river.reach(self._reach) color='grey', lw=1.
kp = reach.geometry.get_kp() )
z_min = reach.geometry.get_z_min()
self.canvas.axes.set_xlim( if "water_elevation" in self._y:
left=min(kp), right=max(kp) # Water elevation
water_z = list(
map(
lambda p: p.get_ts_key(self._timestamp, "Z"),
reach.profiles
)
)
meter_axes.set_ylim(
bottom=min(0, min(z_min)),
top=max(water_z) + 1
) )
meter_axes = self.canvas.axes meter_axes.plot(
m3S_axes = self.canvas.axes kp, water_z, lw=1.,
if "0-meter" in self._y_axes and "1-m3s" in self._y_axes: color='b',
m3s_axes = self._axes["1-m3s"] )
if "elevation" in self._y: if "elevation" in self._y:
meter_axes.set_ylim( meter_axes.fill_between(
bottom=min(0, min(z_min)), kp, z_min, water_z,
top=max(z_min) + 1 color='blue', alpha=0.5, interpolate=True
) )
meter_axes.plot( if "discharge" in self._y:
kp, z_min, q = list(
color='grey', lw=1. map(
lambda p: p.get_ts_key(self._timestamp, "Q"),
reach.profiles
) )
)
if "water_elevation" in self._y: m3s_axes.set_ylim(
# Water elevation bottom=min(0, min(q)),
water_z = list( top=max(q) + 1
map( )
lambda p: p.get_ts_key(self._timestamp, "Z"),
reach.profiles
)
)
meter_axes.set_ylim( m3s_axes.plot(
bottom=min(0, min(z_min)), kp, q, lw=1.,
top=max(water_z) + 1 color='r',
) )
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)
)
meter_axes.plot( x = ts
kp, water_z, lw=1., if "elevation" in self._y:
color='b', # Z min is constant in time
z_min = profile.geometry.z_min()
ts_z_min = list(
map(
lambda ts: z_min,
ts
) )
)
if "elevation" in self._y: meter_axes.plot(
meter_axes.fill_between( ts, ts_z_min,
kp, z_min, water_z, color='grey', lw=1.
color='blue', alpha=0.5, interpolate=True )
)
if "water_elevation" in self._y:
# Water elevation
z = profile.get_key("Z")
if "discharge" in self._y: meter_axes.set_ylim(
q = list( 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( map(
lambda p: p.get_ts_key(self._timestamp, "Q"), lambda ts: z_min,
reach.profiles ts
) )
) )
m3s_axes.set_ylim( meter_axes.fill_between(
bottom=min(0, min(q)), ts, ts_z_min, z,
top=max(q) + 1 color='blue', alpha=0.5, interpolate=True
) )
m3s_axes.plot( if "discharge" in self._y:
kp, q, lw=1., q = profile.get_key("Q")
color='r',
) 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": elif self._x == "time":
if "elevation" in self._y: self._draw_time()
logging.info("TODO: time/elevation")
if "water_elevation" in self._y:
logging.info("TODO: time/water_elevation")
if "discharge" in self._y:
logging.info("TODO: time/discharge")
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): ...@@ -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): ...@@ -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): ...@@ -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): ...@@ -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()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment