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

Pamhyr: Change time edition and plot display (exp BC).

Showing with 62 additions and 72 deletions
+62 -72
......@@ -4,7 +4,7 @@ PyQt5-sip==12.12.2
PyQtWebEngine==5.15.6
QScintilla>=2.14.1
pyqtgraph>=0.12.1
matplotlib>=3.4.1
matplotlib>=3.7.1
numpy>=1.24.2
colorama>=0.4.3
pyinstaller>=5.11.0
......
......@@ -4,7 +4,7 @@ PyQt5-sip==12.12.2
#PyQtWebEngine==5.15.6
QScintilla>=2.14.1
pyqtgraph>=0.12.1
matplotlib>=3.4.1
matplotlib>=3.7.1
numpy>=1.24.2
colorama>=0.4.3
pyinstaller>=5.11.0
......
......@@ -47,99 +47,59 @@ class Plot(PamhyrPlot):
)
self._table_headers = self._trad.get_dict("table_headers")
header = self.data.header
self.label_x = self._table_headers[header[0]]
self.label_y = self._table_headers[header[1]]
self._mode = mode
self._isometric_axis = False
def custom_ticks(self):
if self.data.header[0] != "time":
return
t0 = datetime.fromtimestamp(0)
nb = len(self.data.data)
mod = int(nb / 5)
mod = mod if mod > 0 else nb
fx = list(
map(
lambda x: x[1],
filter(
lambda x: x[0] % mod == 0,
enumerate(self.data.data)
)
)
)
xx = list(map(lambda v: v[0], fx))
if self._mode == "time":
xt = list(
map(
lambda v: str(
datetime.fromtimestamp(v[0]) - t0
).split(",")[0]
.replace("days", _translate("BoundaryCondition", "days"))
.replace("day", _translate("BoundaryCondition", "day")),
fx
)
)
else:
xt = list(
map(
lambda v: str(datetime.fromtimestamp(v[0]).date()),
fx
)
)
self.canvas.axes.set_xticks(ticks=xx, labels=xt, rotation=45)
self.set_ticks_time_formater()
@timer
def draw(self):
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
self.init_axes()
if len(self.data) == 0:
self._init = False
return
self.draw_data()
self.custom_ticks()
self.idle()
self._init = True
def draw_data(self):
# Plot data
x = list(map(lambda v: v[0], self.data.data))
y = list(map(lambda v: v[1], self.data.data))
self._line, = self.canvas.axes.plot(
x, y,
color='r', lw=1.,
markersize=5, marker='+',
picker=30,
color=self.color_plot,
**self.plot_default_kargs
)
self.custom_ticks()
# Plot label
header = self.data.header
self.canvas.axes.set_xlabel(
self._table_headers[header[0]], color='black', fontsize=10
)
self.canvas.axes.set_ylabel(
self._table_headers[header[1]], color='black', fontsize=10
)
self.canvas.axes.autoscale_view(True, True, True)
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
# self.toolbar.update()
self._init = True
@timer
def update(self, ind=None):
if not self._init:
self.draw()
return
self.update_data()
self.custom_ticks()
self.update_idle()
def update_data(self):
x = list(map(lambda v: v[0], self.data.data))
y = list(map(lambda v: v[1], self.data.data))
self._line.set_data(x, y)
self.custom_ticks()
self.canvas.axes.relim()
self.canvas.axes.autoscale()
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
......@@ -21,7 +21,11 @@ import traceback
from datetime import date, time, datetime, timedelta
from tools import trace, timer
from tools import (
trace, timer,
timestamp_to_old_pamhyr_date,
old_pamhyr_date_to_timestamp
)
from View.Tools.PamhyrTable import PamhyrTableModel
......@@ -70,9 +74,7 @@ class TableModel(PamhyrTableModel):
value = f"{v:.4f}"
elif self._data.header[column] == "time":
if self._opt_data == "time":
t0 = datetime.fromtimestamp(0)
t = datetime.fromtimestamp(v)
value = str(t - t0)
value = timestamp_to_old_pamhyr_date(int(v))
else:
value = str(datetime.fromtimestamp(v))
else:
......
......@@ -17,6 +17,9 @@
# -*- coding: utf-8 -*-
import matplotlib.colors as mplcolors
from matplotlib import ticker
from tools import timestamp_to_old_pamhyr_date
from View.Tools.Plot.APlot import APlot
from View.Tools.Plot.PamhyrCanvas import MplCanvas
......@@ -184,3 +187,13 @@ class PamhyrPlot(APlot):
def toolbar_update(self):
if self._toolbar is not None:
self._toolbar.update()
def set_ticks_time_formater(self):
self.canvas.axes.xaxis.set_major_formatter(
lambda x, pos: timestamp_to_old_pamhyr_date(int(x))
)
self.canvas.axes.tick_params(
labelsize=9,
labelrotation=45
)
......@@ -21,7 +21,7 @@ import time
import logging
import traceback
from datetime import datetime
from datetime import datetime, timedelta
from pathlib import Path
from colorama import Fore
......@@ -251,6 +251,21 @@ def old_pamhyr_date_to_timestamp(date: str):
return ts
def timestamp_to_old_pamhyr_date(time:int):
t0 = datetime.fromtimestamp(0)
t = datetime.fromtimestamp(time)
dt = t - t0
hours = dt.seconds // 3600
minutes = (dt.seconds % 3600) // 60
seconds = dt.seconds % 60
s = f"{dt.days:>3}:{hours:>2}:{minutes:>2}:{seconds:>2}"
s = s.replace(" ", "0")
return s
#######################
# COMMAND LINE PARSER #
#######################
......
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