Commit bdc975f2 authored by Theophile Terraz's avatar Theophile Terraz
Browse files

work on plot multiple lines

No related merge requests found
Showing with 198 additions and 186 deletions
+198 -186
......@@ -815,8 +815,6 @@ class AdisTSwc(AdisTS):
# print("isma")
# ##print("iprofiles: ", iprofiles)
print("reading bin files is ok =======")
for r, reach in enumerate(reachs):
for i in range(is1[r]-1, is2[r]):
p_i = ip_to_ri(reach, i)
......@@ -831,24 +829,7 @@ class AdisTSwc(AdisTS):
reach.set(p_i, t_data, "pols", pol_view)
# ##print("pi_tmp: ", pi_tmp)
# ##print("pol view: ", pol_view)
# ##print("reach from i: ", reach_tmp)
# print("pol view: ", pol_view)
# print("results: ", results)
print("'''''''reading bin files is ok =======")
results.set("timestamps", set(timestamps_keys))
# print("set timestamps results meta data: ", set(timestamps_keys))
# ##print("debug profiles for draw:")
# ##print("------------------------")
# ##print(data_tmp["AAA-silt"][0.0]["C"][0])
# ##print(data_tmp["AAA-silt"][600.0]["C"][0])
# ##print(data_tmp["AAA-silt"][1205.7208829578194]["C"][0])
# ##print("========================")
print("****reading bin files is ok =======")
@timer
def results(self, study, repertory, qlog=None, name=None):
......
......@@ -37,7 +37,7 @@ logger = logging.getLogger()
class PlotAdis_dt(PamhyrPlot):
def __init__(self, canvas=None, trad=None, toolbar=None,
results=None, reach_id=0, profile_id=0,
pol_id=0, key="C", type_pol=7, parent=None):
pol_id=[0], key="C", type_pol=[7], parent=None):
super(PlotAdis_dt, self).__init__(
canvas=canvas,
trad=trad,
......@@ -57,18 +57,27 @@ class PlotAdis_dt(PamhyrPlot):
self._available_values_y = self._trad.get_dict("values_y_pol")
self.label = {}
self.label["C"] = _translate("Results", "Concentration")
self.label["M"] = _translate("Results", "Mass")
self.label_max = {}
self.label_min = {}
self.label["C"] = _translate("Results", "Concentration")
self.label_max["C"] = _translate("Results", "Max Concentration")
self.label_max["M"] = _translate("Results", "Max Mass")
if self._type_pol[pol_id[0]] == -1: # Total
self.label["M"] = _translate("Results", "Thickness")
self.label_max["M"] = _translate("Results", "Max Thickness")
self.label_min["M"] = _translate("Results", "Min Thickness")
self.label_y = self._available_values_y["unit_thickness"]
else:
self.label["M"] = _translate("Results", "Mass")
self.label_max["M"] = _translate("Results", "Max Mass")
self.label_min["M"] = _translate("Results", "Min Mass")
self.label_y = self._available_values_y["unit_"+self._key]
self.val_id = {}
self.val_id["C"] = 0
self.val_id["G"] = 1
self.val_id["M"] = 2
self.val_id["D"] = 3
self.label_y = self._available_values_y["unit_"+self._key]
self._lines = [None]*len(self._current_pol_id)
self._isometric_axis = False
......@@ -112,21 +121,23 @@ class PlotAdis_dt(PamhyrPlot):
self.ts.sort()
x = self.ts
if self.val_id[self._key] > 0 and self._type_pol == 1:
y = [0.0]*len(x)
else:
val_id = self.val_id[self._key]
y = list(map(lambda data_el:
data_el[self._current_pol_id][val_id],
profile.get_key("pols")
))
self._line, = self.canvas.axes.plot(
x, y,
label=self.label[self._key],
color=self.color_plot,
**self.plot_default_kargs
)
for i in range(len(self._current_pol_id)):
pol_id = self._current_pol_id[i]
if self.val_id[self._key] > 0 and self._type_pol[pol_id] == 1:
y = [0.0]*len(x)
else:
val_id = self.val_id[self._key]
y = list(map(lambda data_el:
data_el[pol_id][val_id],
profile.get_key("pols")
))
self._lines[i], = self.canvas.axes.plot(
x, y,
label=self.label[self._key],
color=self.color_plot,
**self.plot_default_kargs
)
def draw_current(self):
self._current, = self.canvas.axes.plot(
......@@ -151,7 +162,7 @@ class PlotAdis_dt(PamhyrPlot):
ts_y = list(map(lambda p:
p.get_ts_key(
ts, "pols"
)[self._current_pol_id][val_id],
)[self._current_pol_id[0]][val_id],
reach.profiles))
y.append(np.max(ts_y))
......@@ -201,7 +212,7 @@ class PlotAdis_dt(PamhyrPlot):
ts_y = list(map(lambda p:
p.get_ts_key(
ts, "pols"
)[self._current_pol_id][val_id],
)[self._current_pol_id[0]][val_id],
reach.profiles))
y.append(np.max(ts_y))
......@@ -212,15 +223,17 @@ class PlotAdis_dt(PamhyrPlot):
profile = reach.profile(self._current_profile_id)
x = self.ts
if self.val_id[self._key] > 0 and self._type_pol == 1:
y = [0.0]*len(x)
else:
y = list(map(lambda data_el:
data_el[self._current_pol_id][self.val_id[self._key]],
profile.get_key("pols")
))
self._line.set_data(x, y)
for i in range(len(self._current_pol_id)):
pol_id = self._current_pol_id[i]
if self.val_id[self._key] > 0 and self._type_pol[pol_id] == 1:
y = [0.0]*len(x)
else:
y = list(map(lambda data_el:
data_el[pol_id][self.val_id[self._key]],
profile.get_key("pols")
))
self._lines[i].set_data(x, y)
self._current.set_data(
[self._current_timestamp, self._current_timestamp],
......@@ -244,9 +257,14 @@ class PlotAdis_dt(PamhyrPlot):
def show_current(self):
self._current.set_visible(True)
def set_pollutant(self, pol_id, type_pol):
if pol_id != self._current_pol_id:
self._type_pol = type_pol
def set_pollutant(self, pol_id):
if len(pol_id) == len(self._current_pol_id):
self._current_pol_id = pol_id
self.update()
self.update_current()
else:
self._current_pol_id = pol_id
self._lines = [None]*len(self._current_pol_id)
self.draw()
self.update_current()
......@@ -21,6 +21,7 @@ import numpy as np
from functools import reduce
from datetime import datetime
from math import inf
from tools import timer, trace
from View.Tools.PamhyrPlot import PamhyrPlot
......@@ -37,7 +38,7 @@ logger = logging.getLogger()
class PlotAdis_dx(PamhyrPlot):
def __init__(self, canvas=None, trad=None, toolbar=None,
results=None, reach_id=0, profile_id=0,
pol_id=0, key="C", type_pol=7, parent=None):
pol_id=[0], key="C", type_pol=[7], parent=None):
super(PlotAdis_dx, self).__init__(
canvas=canvas,
trad=trad,
......@@ -62,7 +63,7 @@ class PlotAdis_dx(PamhyrPlot):
self.label["C"] = _translate("Results", "Concentration")
self.label_max["C"] = _translate("Results", "Max Concentration")
self.label_min["C"] = _translate("Results", "Min Concentration")
if self._type_pol == -1: # Total
if self._type_pol[pol_id[0]] == -1: # Total
self.label["M"] = _translate("Results", "Thickness")
self.label_max["M"] = _translate("Results", "Max Thickness")
self.label_min["M"] = _translate("Results", "Min Thickness")
......@@ -78,6 +79,8 @@ class PlotAdis_dx(PamhyrPlot):
self.val_id["M"] = 2
self.val_id["D"] = 3
self._lines = []
self._isometric_axis = False
@property
......@@ -104,14 +107,14 @@ class PlotAdis_dx(PamhyrPlot):
return
self.draw_min_and_max(reach)
self.draw_data(reach, profile)
self.draw_current(reach)
self.draw_data(reach)
self.draw_profiles_hs(reach)
self.draw_current(reach)
self.enable_legend()
self.idle()
self.update_current()
#self.update_current()
self._init = True
def draw_profiles_hs(self, reach):
......@@ -145,56 +148,72 @@ class PlotAdis_dx(PamhyrPlot):
fontsize=9, color=self.color_plot_previous,
)
def draw_data(self, reach, profile):
def draw_data(self, reach):
profile = reach.profile(self._current_profile_id)
x = reach.geometry.get_rk()
if self.val_id[self._key] > 0 and self._type_pol == 1:
y = [0.0]*len(x)
else:
y = list(map(lambda p:
p.get_ts_key(
self._current_timestamp, "pols"
)[self._current_pol_id][self.val_id[self._key]],
reach.profiles))
self._line, = self.canvas.axes.plot(
x, y,
label=self.label[self._key],
color=self.color_plot,
**self.plot_default_kargs
)
self.set_y_lim()
for i in range(len(self._current_pol_id)):
pol_id = self._current_pol_id[i]
if self.val_id[self._key] > 0 and self._type_pol[pol_id] == 1:
y = [0.0]*len(x)
else:
y = list(map(lambda p:
p.get_ts_key(
self._current_timestamp, "pols"
)[pol_id][self.val_id[self._key]],
reach.profiles))
self._lines.append(self.canvas.axes.plot(
x, y,
label=self.label[self._key],
color=self.color_plot,
**self.plot_default_kargs
)[0])
#self.set_y_lim()
def draw_current(self, reach):
rk = reach.geometry.get_rk()
rk = reach.geometry.get_rk()
self._current, = self.canvas.axes.plot(
[rk[self._current_profile_id], rk[self._current_profile_id]],
[self.y_max, self.y_min],
self.canvas.axes.get_ylim(),
#[self.y_max, self.y_min],
color="grey",
linestyle="dashed",
lw=1.
lw=1.,
)
def update_current(self):
self.hide_current()
self.canvas.axes.relim(visible_only=True)
self.canvas.axes.autoscale_view()
self.show_current()
reach = self.results.river.reach(self._current_reach_id)
rk = reach.geometry.get_rk()
self._current.set_data(
[rk[self._current_profile_id], rk[self._current_profile_id]],
self.canvas.axes.get_ylim()
)
def draw_min_and_max(self, reach):
profile = reach.profile(self._current_profile_id)
x = reach.geometry.get_rk()
if self.val_id[self._key] > 0 and self._type_pol == 1:
y = [0.0]*len(x)
else:
y = []
z = []
val_id = self.val_id[self._key]
for p in reach.profiles:
rk_y = list(map(lambda data_el:
data_el[self._current_pol_id][val_id],
p.get_key("pols")
))
y.append(np.max(rk_y))
z.append(np.min(rk_y))
y = [-inf]*reach.geometry.number_profiles
z = [inf]*reach.geometry.number_profiles
for pol_id in self._current_pol_id:
if self.val_id[self._key] > 0 and self._type_pol[pol_id] == 1:
for i in range(reach.geometry.number_profiles):
y[i] = max(0.0, y[i])
z[i] = min(0.0, z[i])
else:
val_id = self.val_id[self._key]
for i, p in enumerate(reach.profiles):
rk_y = list(map(lambda data_el:
data_el[pol_id][val_id],
p.get_key("pols")
))
y[i] = max(np.max(rk_y), y[i])
z[i] = min(np.min(rk_y), z[i])
self._line_max, = self.canvas.axes.plot(
x, y,
......@@ -206,7 +225,7 @@ class PlotAdis_dx(PamhyrPlot):
)
self._line_min, = self.canvas.axes.plot(
x, y,
x, z,
label=self.label_min[self._key],
color='g',
linestyle='dotted',
......@@ -234,7 +253,7 @@ class PlotAdis_dx(PamhyrPlot):
self.update_min_and_max()
self.update_data()
self.set_y_lim
#self.set_y_lim
self.update_idle()
def update_min_and_max(self):
......@@ -242,19 +261,22 @@ class PlotAdis_dx(PamhyrPlot):
profile = reach.profile(self._current_profile_id)
x = reach.geometry.get_rk()
if self.val_id[self._key] > 0 and self._type_pol == 1:
y = [0.0]*len(x)
else:
y = []
z = []
val_id = self.val_id[self._key]
for p in reach.profiles:
rk_y = list(map(lambda data_el:
data_el[self._current_pol_id][val_id],
p.get_key("pols")
))
y.append(np.max(rk_y))
z.append(np.min(rk_y))
y = [-inf]*reach.geometry.number_profiles
z = [inf]*reach.geometry.number_profiles
for pol_id in self._current_pol_id:
if self.val_id[self._key] > 0 and self._type_pol[pol_id] == 1:
for i in range(reach.geometry.number_profiles):
y[i] = max(0.0, y[i])
z[i] = min(0.0, z[i])
else:
val_id = self.val_id[self._key]
for i, p in enumerate(reach.profiles):
rk_y = list(map(lambda data_el:
data_el[pol_id][val_id],
p.get_key("pols")
))
y[i] = max(np.max(rk_y), y[i])
z[i] = min(np.min(rk_y), z[i])
self._line_max.set_data(x, y)
self._line_min.set_data(x, z)
......@@ -265,62 +287,57 @@ class PlotAdis_dx(PamhyrPlot):
x = reach.geometry.get_rk()
if self.val_id[self._key] > 0 and self._type_pol == 1:
y = [0.0]*len(x)
else:
y = list(map(
lambda p: p.get_ts_key(
self._current_timestamp, "pols"
)[self._current_pol_id][self.val_id[self._key]],
reach.profiles))
for i in range(len(self._current_pol_id)):
pol_id = self._current_pol_id[i]
if self.val_id[self._key] > 0 and self._type_pol[pol_id] == 1:
y = [0.0]*len(x)
else:
y = list(map(
lambda p: p.get_ts_key(
self._current_timestamp, "pols"
)[pol_id][self.val_id[self._key]],
reach.profiles))
self._line.set_data(x, y)
self._lines[i].set_data(x, y)
self.update_current()
self.hide_current()
self.canvas.axes.relim(visible_only=True)
self.canvas.axes.autoscale_view()
self.show_current()
def update_current(self):
reach = self.results.river.reach(self._current_reach_id)
rk = reach.geometry.get_rk()
cid = self._current_profile_id
self._current.set_data(
[rk[cid], rk[cid]],
[self.y_max, self.y_min]
)
self.canvas.figure.canvas.draw_idle()
def hide_current(self):
self._current.set_visible(False)
def show_current(self):
self._current.set_visible(True)
def set_pollutant(self, pol_id, type_pol):
if pol_id != self._current_pol_id:
self._type_pol = type_pol
def set_pollutant(self, pol_id):
for l in self._lines:
l.remove()
self._lines = []
reach = self.results.river.reach(self._current_reach_id)
self._current_pol_id = pol_id
self.update()
self.update_min_and_max()
self.draw_data(reach)
self.update_current()
#self.set_y_lim
self.update_idle()
def set_y_lim(self):
reach = self.results.river.reach(self._current_reach_id)
if self.val_id[self._key] > 0 and self._type_pol == 1:
y = [0.0]
else:
val_id = self.val_id[self._key]
y = list(
map(lambda p:
list(map(lambda data_el:
data_el[self._current_pol_id][val_id],
p.get_key("pols"))), reach.profiles))
self.y_max = np.max(y)
self.y_min = np.min(y)
y0 = []
for pol_id in self._current_pol_id:
if self.val_id[self._key] > 0 and self._type_pol[pol_id] == 1:
y = [0.0]
else:
val_id = self.val_id[self._key]
y = list(
map(lambda p:
list(map(lambda data_el:
data_el[pol_id][val_id],
p.get_key("pols"))), reach.profiles))
y0.append(y)
self.y_max = np.max([np.max(y) for y in y0])
self.y_min = np.min([np.min(y) for y in y0])
if self.y_max - self.y_min < 0.000001:
self.y_min = (self.y_max + self.y_min)/2 - 0.5
self.y_max = (self.y_max + self.y_min)/2 + 0.5
......
......@@ -101,7 +101,7 @@ class ResultsWindowAdisTS(PamhyrWindow):
self._hash_data.append(self._results)
self._additional_plot = {}
self._pol_id = 1
self._pol_id = [1]
self._reach_id = 0
self._profile_id = 0
......@@ -115,7 +115,7 @@ class ResultsWindowAdisTS(PamhyrWindow):
self.setup_connections()
self.update_table_selection_reach(self._reach_id)
self.update_table_selection_profile(self._profile_id)
self.update_table_selection_pol(self._pol_id-1)
self.update_table_selection_pol(self._pol_id)
except Exception as e:
logger_exception(e)
return
......@@ -190,7 +190,7 @@ class ResultsWindowAdisTS(PamhyrWindow):
profile_id=self._profile_id,
pol_id=self._pol_id,
key="C",
type_pol=self._type_pol[self._pol_id],
type_pol=self._type_pol,
trad=self._trad,
toolbar=self.toolbar_cdt
)
......@@ -216,7 +216,7 @@ class ResultsWindowAdisTS(PamhyrWindow):
profile_id=self._profile_id,
pol_id=self._pol_id,
key="C",
type_pol=self._type_pol[self._pol_id],
type_pol=self._type_pol,
trad=self._trad,
toolbar=self.toolbar_cdx
)
......@@ -242,7 +242,7 @@ class ResultsWindowAdisTS(PamhyrWindow):
profile_id=self._profile_id,
pol_id=self._pol_id,
key="M",
type_pol=self._type_pol[self._pol_id],
type_pol=self._type_pol,
trad=self._trad,
toolbar=self.toolbar_mdx
)
......@@ -269,15 +269,15 @@ class ResultsWindowAdisTS(PamhyrWindow):
profile_id=self._profile_id,
pol_id=self._pol_id,
key="M",
type_pol=self._type_pol[self._pol_id],
type_pol=self._type_pol,
trad=self._trad,
toolbar=self.toolbar_mdt
)
self.plot_mdt.draw()
if self._type_pol[self._pol_id] != 7:
self.find(QTabWidget, "tabWidget").setTabVisible(2, False)
#if self._type_pol[self._pol_id[0]] != 7:
#self.find(QTabWidget, "tabWidget").setTabVisible(2, False)
# Thickness
......@@ -299,9 +299,9 @@ class ResultsWindowAdisTS(PamhyrWindow):
results=self._results,
reach_id=self._reach_id,
profile_id=self._profile_id,
pol_id=0,
pol_id=[0],
key="M",
type_pol=self._type_pol[0],
type_pol=self._type_pol,
trad=self._trad,
toolbar=self.toolbar_tdx
)
......@@ -326,9 +326,9 @@ class ResultsWindowAdisTS(PamhyrWindow):
results=self._results,
reach_id=self._reach_id,
profile_id=self._profile_id,
pol_id=0,
pol_id=[0],
key="M",
type_pol=self._type_pol[0],
type_pol=self._type_pol,
trad=self._trad,
toolbar=self.toolbar_tdt
)
......@@ -466,7 +466,7 @@ class ResultsWindowAdisTS(PamhyrWindow):
for t in ["pollutants"]:
table = self.find(QTableView, f"tableView_{t}")
selectionModel = table.selectionModel()
index = table.model().index(ind, 0)
index = table.model().index(ind[0]- 1, 0)
selectionModel.select(
index,
......@@ -481,9 +481,9 @@ class ResultsWindowAdisTS(PamhyrWindow):
if reach_id is not None:
self.plot_cdt.set_reach(reach_id)
self.plot_cdx.set_reach(reach_id)
if self._type_pol[self._pol_id] != 1:
self.plot_mdx.set_reach(reach_id)
self.plot_mdt.set_reach(reach_id)
#if self._type_pol[self._pol_id[0]] != 1:
self.plot_mdx.set_reach(reach_id)
self.plot_mdt.set_reach(reach_id)
self.plot_tdt.set_reach(reach_id)
self.plot_tdx.set_reach(reach_id)
......@@ -493,37 +493,32 @@ class ResultsWindowAdisTS(PamhyrWindow):
if profile_id is not None:
self.plot_cdt.set_profile(profile_id)
self.plot_cdx.set_profile(profile_id)
if self._type_pol[self._pol_id] != 1:
self.plot_mdx.set_profile(profile_id)
self.plot_mdt.set_profile(profile_id)
#if self._type_pol[self._pol_id[0]] != 1:
self.plot_mdx.set_profile(profile_id)
self.plot_mdt.set_profile(profile_id)
self.plot_tdt.set_profile(profile_id)
self.plot_tdx.set_profile(profile_id)
self.update_table_selection_profile(profile_id)
if pol_id is not None:
self._pol_id = pol_id+1
self.plot_cdt.set_pollutant(self._pol_id,
self._type_pol[self._pol_id])
self.plot_cdx.set_pollutant(self._pol_id,
self._type_pol[self._pol_id])
if self._type_pol[self._pol_id] != 1:
self.find(QTabWidget, "tabWidget").setTabVisible(2, True)
self.plot_mdx.set_pollutant(self._pol_id,
self._type_pol[self._pol_id])
self.plot_mdt.set_pollutant(self._pol_id,
self._type_pol[self._pol_id])
else:
self.find(QTabWidget, "tabWidget").setTabVisible(2, False)
self.update_table_selection_pol(self._pol_id-1)
self._pol_id = [p+1 for p in pol_id] # remove total_sediment
self.plot_cdt.set_pollutant(self._pol_id)
self.plot_cdx.set_pollutant(self._pol_id)
#if self._type_pol[self._pol_id[0]] != 1:
#self.find(QTabWidget, "tabWidget").setTabVisible(2, True)
#self.plot_mdx.set_pollutant(self._pol_id)
#self.plot_mdt.set_pollutant(self._pol_id)
#else:
#self.find(QTabWidget, "tabWidget").setTabVisible(2, False)
#self.update_table_selection_pol(self._pol_id)
if timestamp is not None:
self.plot_cdt.set_timestamp(timestamp)
self.plot_cdx.set_timestamp(timestamp)
if self._type_pol[self._pol_id] != 1:
self.plot_mdx.set_timestamp(timestamp)
self.plot_mdt.set_timestamp(timestamp)
self.plot_mdx.set_timestamp(timestamp)
self.plot_mdt.set_timestamp(timestamp)
self.plot_tdt.set_timestamp(timestamp)
self.plot_tdx.set_timestamp(timestamp)
......@@ -555,10 +550,11 @@ class ResultsWindowAdisTS(PamhyrWindow):
def _set_current_pol(self):
table = self.find(QTableView, f"tableView_pollutants")
indexes = table.selectedIndexes()
rows = [i.row() for i in indexes]
if len(indexes) == 0:
return
self.update(pol_id=indexes[0].row())
self.update(pol_id=rows)
def _set_current_profile_raw_data(self):
table = self.find(QTableView, f"tableView_raw_data")
......
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