mirror of https://gitlab.com/pamhyr/pamhyr2
Import INI files: handle INI RK matching and refresh table after import
parent
e19eeedcc3
commit
3458a5df9f
|
|
@ -19,6 +19,7 @@
|
|||
import logging
|
||||
|
||||
from copy import copy, deepcopy
|
||||
from math import isclose
|
||||
from tools import trace, timer
|
||||
from functools import reduce
|
||||
from numpy import interp
|
||||
|
|
@ -440,14 +441,26 @@ class InitialConditions(SQLSubModel):
|
|||
def new_from_data(self, rk, discharge, elevation):
|
||||
n = Data(reach=self._reach, status=self._status)
|
||||
|
||||
# Values read from Mage INI files are strings, whereas profile RK
|
||||
# values are stored as floats. Normalize the imported value before
|
||||
# looking up its associated profile.
|
||||
rk = float(rk)
|
||||
|
||||
section = reduce(
|
||||
lambda acc, s: (
|
||||
s if s.rk == rk else acc
|
||||
s if isclose(s.rk, rk, rel_tol=1e-9, abs_tol=1e-9)
|
||||
else acc
|
||||
),
|
||||
self._reach.reach.profiles,
|
||||
None
|
||||
)
|
||||
|
||||
if section is None:
|
||||
raise ValueError(
|
||||
f"No profile with RK {rk} exists in reach "
|
||||
f"{self._reach.name}"
|
||||
)
|
||||
|
||||
n['section'] = section
|
||||
n['discharge'] = discharge
|
||||
n['elevation'] = elevation
|
||||
|
|
|
|||
|
|
@ -290,8 +290,6 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
logger.error("No results data")
|
||||
return
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
ts = max(results.get("timestamps"))
|
||||
res_reach = results.river.get_reach_by_geometry(
|
||||
self._reach.reach
|
||||
|
|
@ -307,19 +305,15 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
)
|
||||
)
|
||||
|
||||
self._undo.push(
|
||||
ReplaceDataCommand(
|
||||
self._lst,
|
||||
list(
|
||||
map(
|
||||
lambda d: self._lst.new_from_data(*d),
|
||||
data
|
||||
)
|
||||
)
|
||||
new_data = list(
|
||||
map(
|
||||
lambda d: self._lst.new_from_data(*d),
|
||||
data
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self._undo.push(ReplaceDataCommand(self._lst, new_data))
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def read_from_ini(self, file_name):
|
||||
|
|
@ -355,18 +349,17 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
line_split[2],
|
||||
line_split[3]])
|
||||
|
||||
self._undo.push(
|
||||
ReplaceDataCommand(
|
||||
self._lst,
|
||||
list(
|
||||
map(
|
||||
lambda d: self._lst.new_from_data(*d),
|
||||
data
|
||||
)
|
||||
)
|
||||
new_data = list(
|
||||
map(
|
||||
lambda d: self._lst.new_from_data(*d),
|
||||
data
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self._undo.push(ReplaceDataCommand(self._lst, new_data))
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def undo(self):
|
||||
self._undo.undo()
|
||||
self.layoutChanged.emit()
|
||||
|
|
|
|||
Loading…
Reference in New Issue