mirror of https://gitlab.com/pamhyr/pamhyr2
SL: Add reach sediment layers plot.
parent
5fab694c27
commit
ebd05768a4
|
|
@ -260,6 +260,39 @@ class Reach(SQLSubModel):
|
||||||
return max(self.get_kp())
|
return max(self.get_kp())
|
||||||
|
|
||||||
|
|
||||||
|
# Sediment Layers
|
||||||
|
|
||||||
|
def get_sl(self):
|
||||||
|
"""Get sediment layer height of profile
|
||||||
|
|
||||||
|
Get sediment layer of profile (without spesific point sl)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of sediment layers height
|
||||||
|
"""
|
||||||
|
res = []
|
||||||
|
psl = [profile.sl for profile in self.profiles]
|
||||||
|
|
||||||
|
# Compute max number of layers
|
||||||
|
sl_max = 0
|
||||||
|
for sl in psl:
|
||||||
|
n = 0 if sl is None else len(sl)
|
||||||
|
sl_max = max(n, sl_max)
|
||||||
|
|
||||||
|
# Create list of height for each sl and each layer
|
||||||
|
for i in range(0, sl_max):
|
||||||
|
cur = []
|
||||||
|
# Compute new layer line for each sl
|
||||||
|
for sl in psl:
|
||||||
|
if sl is not None and i < len(sl):
|
||||||
|
cur.append(sl.get(i).height)
|
||||||
|
else:
|
||||||
|
cur.append(0)
|
||||||
|
# Add layer line to result
|
||||||
|
res.append(cur)
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
# Guidelines
|
# Guidelines
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class Layer(SQLSubModel):
|
||||||
|
|
||||||
@height.setter
|
@height.setter
|
||||||
def height(self, height):
|
def height(self, height):
|
||||||
self._height = height
|
self._height = float(height)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _sql_create(cls, execute):
|
||||||
|
|
@ -60,7 +60,7 @@ class Layer(SQLSubModel):
|
||||||
ind INTEGER NOT NULL,
|
ind INTEGER NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
height INTEGER NOT NULL,
|
height REAL NOT NULL,
|
||||||
sl INTEGER,
|
sl INTEGER,
|
||||||
FOREIGN KEY(sl) REFERENCES sedimentary_layer(id)
|
FOREIGN KEY(sl) REFERENCES sedimentary_layer(id)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
from tools import timer
|
||||||
|
from View.Plot.APlot import APlot
|
||||||
|
|
||||||
|
from PyQt5.QtCore import (
|
||||||
|
QCoreApplication
|
||||||
|
)
|
||||||
|
|
||||||
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
class Plot(APlot):
|
||||||
|
def __init__(self, canvas=None, data=None, toolbar=None,
|
||||||
|
display_current=True):
|
||||||
|
super(Plot, self).__init__(
|
||||||
|
canvas=canvas,
|
||||||
|
data=data,
|
||||||
|
toolbar=toolbar
|
||||||
|
)
|
||||||
|
|
||||||
|
self._display_current = display_current
|
||||||
|
|
||||||
|
self.line_kp_zmin = None
|
||||||
|
self.line_kp_sl = []
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def draw(self):
|
||||||
|
self.canvas.axes.cla()
|
||||||
|
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||||
|
|
||||||
|
if self.data is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.data.number_profiles == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.canvas.axes.set_xlabel(
|
||||||
|
_translate("MainWindow_reach", "Kp (m)"),
|
||||||
|
color='green', fontsize=12
|
||||||
|
)
|
||||||
|
self.canvas.axes.set_ylabel(
|
||||||
|
_translate("MainWindow_reach", "Height (m)"),
|
||||||
|
color='green', fontsize=12
|
||||||
|
)
|
||||||
|
|
||||||
|
kp = self.data.get_kp()
|
||||||
|
sl = self.data.get_sl()
|
||||||
|
z_min = self.data.get_z_min()
|
||||||
|
z_max = self.data.get_z_max()
|
||||||
|
|
||||||
|
self.canvas.axes.set_xlim(
|
||||||
|
left = min(kp), right = max(kp)
|
||||||
|
)
|
||||||
|
|
||||||
|
z_sl = reduce(
|
||||||
|
lambda acc, v: acc + [
|
||||||
|
list(
|
||||||
|
map(lambda x, y: y - x, v, acc[-1])
|
||||||
|
)
|
||||||
|
],
|
||||||
|
sl,
|
||||||
|
[z_min]
|
||||||
|
)
|
||||||
|
|
||||||
|
for i, z in enumerate(z_sl):
|
||||||
|
self.line_kp_sl.append(None)
|
||||||
|
self.line_kp_sl[i], = self.canvas.axes.plot(
|
||||||
|
kp, z,
|
||||||
|
linestyle="solid" if i == 0 else "--",
|
||||||
|
lw=1.8,
|
||||||
|
color='grey' if i == 0 else None
|
||||||
|
)
|
||||||
|
|
||||||
|
self.canvas.figure.tight_layout()
|
||||||
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
if self.toolbar is not None:
|
||||||
|
self.toolbar.update()
|
||||||
|
|
||||||
|
self._init = True
|
||||||
|
|
||||||
|
@timer
|
||||||
|
def update(self, ind=None):
|
||||||
|
if self._init == False:
|
||||||
|
self.draw()
|
||||||
|
return
|
||||||
|
|
||||||
|
if ind is None:
|
||||||
|
kp = self.data.get_kp()
|
||||||
|
z_min = self.data.get_z_min()
|
||||||
|
z_max = self.data.get_z_max()
|
||||||
|
|
||||||
|
self.line_kp_zmin.set_data(kp, z_min)
|
||||||
|
|
||||||
|
self.canvas.axes.autoscale_view(True, True, True)
|
||||||
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
|
@ -26,6 +26,7 @@ from PyQt5.QtWidgets import (
|
||||||
|
|
||||||
from View.SedimentLayers.Reach.UndoCommand import *
|
from View.SedimentLayers.Reach.UndoCommand import *
|
||||||
from View.SedimentLayers.Reach.Table import *
|
from View.SedimentLayers.Reach.Table import *
|
||||||
|
from View.SedimentLayers.Reach.Plot import Plot
|
||||||
|
|
||||||
from View.Plot.MplCanvas import MplCanvas
|
from View.Plot.MplCanvas import MplCanvas
|
||||||
from View.SedimentLayers.Reach.translate import *
|
from View.SedimentLayers.Reach.translate import *
|
||||||
|
|
@ -98,13 +99,13 @@ class ReachSedimentLayersWindow(ASubMainWindow, ListedSubWindow):
|
||||||
self.plot_layout = self.find(QVBoxLayout, "verticalLayout_2")
|
self.plot_layout = self.find(QVBoxLayout, "verticalLayout_2")
|
||||||
self.plot_layout.addWidget(self.canvas)
|
self.plot_layout.addWidget(self.canvas)
|
||||||
|
|
||||||
# self.plot = PlotKPC(
|
self.plot = Plot(
|
||||||
# canvas = self.canvas,
|
canvas = self.canvas,
|
||||||
# data = self._reach.reach,
|
data = self._reach,
|
||||||
# toolbar = None,
|
toolbar = None,
|
||||||
# display_current = False
|
display_current = False
|
||||||
# )
|
)
|
||||||
# self.plot.draw()
|
self.plot.draw()
|
||||||
|
|
||||||
|
|
||||||
def setup_connections(self):
|
def setup_connections(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue