mirror of https://gitlab.com/pamhyr/pamhyr2
163 lines
4.6 KiB
Python
163 lines
4.6 KiB
Python
# PlotCAdisTS.py -- Pamhyr
|
|
# Copyright (C) 2023-2024 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 -*-
|
|
|
|
import logging
|
|
|
|
from functools import reduce
|
|
from datetime import datetime
|
|
|
|
from tools import timer, trace
|
|
from View.Tools.PamhyrPlot import PamhyrPlot
|
|
|
|
from PyQt5.QtCore import (
|
|
QCoreApplication
|
|
)
|
|
|
|
_translate = QCoreApplication.translate
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
|
class PlotC(PamhyrPlot):
|
|
def __init__(self, canvas=None, trad=None, toolbar=None,
|
|
results=None, reach_id=0, profile_id=0, pol_id=0,
|
|
parent=None):
|
|
super(PlotC, self).__init__(
|
|
canvas=canvas,
|
|
trad=trad,
|
|
data=results,
|
|
toolbar=toolbar,
|
|
parent=parent
|
|
)
|
|
|
|
self._mode = "time"
|
|
|
|
self._current_timestamp = max(results.get("timestamps"))
|
|
self._current_reach_id = reach_id
|
|
self._current_profile_id = profile_id
|
|
self._current_pol_id = pol_id
|
|
|
|
self.label_x = _translate("Results", "Time (s)")
|
|
self.label_y = _translate("Results", "Discharge (m³/s)")
|
|
|
|
self.label_discharge = _translate("Results", "Cross-section discharge")
|
|
self.label_discharge_max = _translate("Results", "Max discharge")
|
|
self.label_timestamp = _translate("Results", "Current timestamp")
|
|
|
|
self._isometric_axis = False
|
|
|
|
self._auto_relim_update = False
|
|
self._autoscale_update = False
|
|
|
|
@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.init_axes()
|
|
|
|
if self.results is None:
|
|
return
|
|
|
|
reach = self.results.river.reach(self._current_reach_id)
|
|
profile = reach.profile(self._current_profile_id)
|
|
pollutant = self._current_pol_id
|
|
|
|
if reach.geometry.number_profiles == 0:
|
|
self._init = False
|
|
return
|
|
|
|
self.draw_data(reach, profile, pollutant)
|
|
|
|
self.set_ticks_time_formater()
|
|
|
|
self.enable_legend()
|
|
|
|
self.idle()
|
|
self._init = True
|
|
|
|
def draw_data(self, reach, profile, pollutant):
|
|
self.ts = list(self.results.get("timestamps"))
|
|
self.ts.sort()
|
|
|
|
x = self.ts
|
|
#y = profile.get_key("Q")
|
|
#First 0 for pol and second 0 for phys var
|
|
y = list(map(lambda data_el: data_el[pollutant][0], profile.get_key("pols")))
|
|
|
|
###print("************//////////////////")
|
|
###print("profile: ", self._current_profile_id)
|
|
###print("reach: ", self._current_reach_id)
|
|
###print("pollutant: ", pollutant)
|
|
|
|
###print("*****************draw data: ", len(x),len(y))
|
|
###print("x: ", x)
|
|
###print("y: ", y)
|
|
###print("reach: ", reach)
|
|
###print("profile: ", profile)
|
|
###print("pollutant: ", pollutant)
|
|
|
|
self._line, = self.canvas.axes.plot(
|
|
x, y,
|
|
label=self.label_discharge,
|
|
color=self.color_plot,
|
|
**self.plot_default_kargs
|
|
)
|
|
|
|
def set_reach(self, reach_id):
|
|
self._current_reach_id = reach_id
|
|
self._current_profile_id = 0
|
|
self.draw()
|
|
|
|
def set_profile(self, profile_id):
|
|
self._current_profile_id = profile_id
|
|
self.update()
|
|
|
|
def set_pollutant(self, pol_id):
|
|
self._current_pol_id = pol_id
|
|
self.update()
|
|
|
|
def set_timestamp(self, timestamp):
|
|
self._current_timestamp = timestamp
|
|
self.update()
|
|
|
|
def update(self):
|
|
if not self._init:
|
|
self.draw()
|
|
|
|
self.update_data()
|
|
|
|
self.update_idle()
|
|
|
|
def update_data(self):
|
|
reach = self.results.river.reach(self._current_reach_id)
|
|
profile = reach.profile(self._current_profile_id)
|
|
pollutant = self._current_pol_id
|
|
|
|
x = self.ts
|
|
#y = profile.get_key("Q")
|
|
y = list(map(lambda data_el: data_el[pollutant][0], profile.get_key("pols")))
|
|
|
|
self._line.set_data(x, y)
|