mirror of https://gitlab.com/pamhyr/pamhyr2
Scenario structure: adapting better structure for results with scenario mode + default data for weather parameters
parent
68aabb343d
commit
61baaeeffb
|
|
@ -352,11 +352,8 @@ class Scenario(SQLSubModel):
|
|||
return None
|
||||
|
||||
def workdir(self):
|
||||
srep = ""
|
||||
if self.id != 0:
|
||||
srep = os.path.join(
|
||||
self.parent.workdir(),
|
||||
"scenario_" + str(self.id)
|
||||
)
|
||||
current = "scenario_" + str(self.id)
|
||||
if self.parent is None or self.parent.id == 0:
|
||||
return current
|
||||
|
||||
return srep
|
||||
return os.path.join(self.parent.workdir(), current)
|
||||
|
|
|
|||
|
|
@ -40,6 +40,17 @@ class WeatherParametersList(PamhyrModelList):
|
|||
_default_types = [
|
||||
"AT", "SH", "GR", "RWS", "GT", "GFR", "ALB", "SC", "CCF"
|
||||
]
|
||||
_default_values = {
|
||||
"AT": 20.0,
|
||||
"SH": 0.001,
|
||||
"GR": 10.0,
|
||||
"RWS": 1.0,
|
||||
"GT": 0.0,
|
||||
"GFR": 0.0,
|
||||
"ALB": 0.06,
|
||||
"SC": 0.15,
|
||||
"CCF": 0.5,
|
||||
}
|
||||
|
||||
def __init__(self, status=None):
|
||||
super(WeatherParametersList, self).__init__(status=status)
|
||||
|
|
@ -109,7 +120,11 @@ class WeatherParametersList(PamhyrModelList):
|
|||
for type in self._default_types:
|
||||
if type not in existing:
|
||||
self._default.append(
|
||||
WeatherParametersDefault(type=type, status=self._status)
|
||||
WeatherParametersDefault(
|
||||
type=type,
|
||||
value=self._default_values[type],
|
||||
status=self._status,
|
||||
)
|
||||
)
|
||||
|
||||
self._sort_default_values()
|
||||
|
|
|
|||
|
|
@ -67,6 +67,10 @@ class StudyTestCase(unittest.TestCase):
|
|||
defaults = study.river.weather_parameters.default
|
||||
|
||||
self.assertEqual(len(defaults), 9)
|
||||
self.assertEqual(
|
||||
[default.value for default in defaults],
|
||||
[20.0, 0.001, 10.0, 1.0, 0.0, 0.0, 0.06, 0.15, 0.5]
|
||||
)
|
||||
defaults[0].value = 12.5
|
||||
|
||||
dir = tempfile.mkdtemp()
|
||||
|
|
|
|||
|
|
@ -75,7 +75,8 @@ class ScriptRun(AScript):
|
|||
os.path.dirname(study.filename),
|
||||
"_PAMHYR_",
|
||||
study.name.replace(" ", "_"),
|
||||
solver.name.replace(" ", "_")
|
||||
solver.name.replace(" ", "_"),
|
||||
study.status.scenario.workdir(),
|
||||
)
|
||||
os.makedirs(workdir, exist_ok=True)
|
||||
logger.info(f"Set working dir to {workdir}")
|
||||
|
|
|
|||
|
|
@ -363,13 +363,19 @@ class AdisTS(CommandLineSolver):
|
|||
if qlog is not None:
|
||||
qlog.put("Export REP file")
|
||||
|
||||
mage_path = (mage_rep if os.path.isabs(mage_rep) else os.path.join(
|
||||
os.path.abspath(os.path.join(repertory, os.pardir)),
|
||||
mage_rep,
|
||||
))
|
||||
relative_mage_path = os.path.relpath(mage_path, repertory)
|
||||
|
||||
# Write header
|
||||
with adists_file_open(
|
||||
os.path.join(
|
||||
repertory, f"{name}.REP"
|
||||
), "w+"
|
||||
) as f:
|
||||
path = os.path.join("..", mage_rep, name)
|
||||
path = os.path.join(relative_mage_path, name)
|
||||
f.write(f"NET {name}.NET\n")
|
||||
f.write(f"REP {path}.REP\n")
|
||||
|
||||
|
|
@ -384,9 +390,7 @@ class AdisTS(CommandLineSolver):
|
|||
|
||||
# fake mage_fin.ini:
|
||||
|
||||
path_mage = os.path.join(os.path.abspath(
|
||||
os.path.join(repertory, os.pardir)), mage_rep)
|
||||
self._export_fake_INI(study, path_mage,
|
||||
self._export_fake_INI(study, mage_path,
|
||||
qlog, name=name)
|
||||
|
||||
# path_mage_net = os.path.join(os.path.abspath(
|
||||
|
|
|
|||
|
|
@ -330,13 +330,19 @@ class AdisTT(CommandLineSolver):
|
|||
if qlog is not None:
|
||||
qlog.put("Export REP file")
|
||||
|
||||
mage_path = (mage_rep if os.path.isabs(mage_rep) else os.path.join(
|
||||
os.path.abspath(os.path.join(repertory, os.pardir)),
|
||||
mage_rep,
|
||||
))
|
||||
relative_mage_path = os.path.relpath(mage_path, repertory)
|
||||
|
||||
# Write header
|
||||
with adistt_file_open(
|
||||
os.path.join(
|
||||
repertory, f"{name}.REP"
|
||||
), "w+"
|
||||
) as f:
|
||||
path = os.path.join("..", mage_rep, name)
|
||||
path = os.path.join(relative_mage_path, name)
|
||||
f.write(f"NET {path}.NET\n")
|
||||
f.write(f"REP {path}.REP\n")
|
||||
|
||||
|
|
@ -348,9 +354,7 @@ class AdisTT(CommandLineSolver):
|
|||
|
||||
# fake mage_fin.ini:
|
||||
|
||||
path_mage = os.path.join(os.path.abspath(
|
||||
os.path.join(repertory, os.pardir)), mage_rep)
|
||||
self._export_fake_INI(study, path_mage,
|
||||
self._export_fake_INI(study, mage_path,
|
||||
qlog, name=name)
|
||||
|
||||
# path_mage_net = os.path.join(os.path.abspath(
|
||||
|
|
|
|||
|
|
@ -1885,6 +1885,23 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
self._solver_workdir(solver, scenario)
|
||||
)
|
||||
|
||||
def _solver_from_results_path(self, results_path):
|
||||
solvers_by_directory = {
|
||||
solver.name.replace(" ", "_"): solver
|
||||
for solver in self.conf.solvers
|
||||
}
|
||||
|
||||
path = os.path.abspath(results_path)
|
||||
while True:
|
||||
directory = os.path.basename(path)
|
||||
if directory in solvers_by_directory:
|
||||
return solvers_by_directory[directory]
|
||||
|
||||
parent = os.path.dirname(path)
|
||||
if parent == path:
|
||||
return None
|
||||
path = parent
|
||||
|
||||
def open_last_results(self):
|
||||
if self._last_solver is None:
|
||||
return
|
||||
|
|
@ -2186,10 +2203,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
text=self._trad["mb_results_bin_not_found"]
|
||||
)
|
||||
return
|
||||
path = os.path.normpath(dir_path)
|
||||
solver_name = path.split(os.sep)[-2]
|
||||
solver_results = next(filter(lambda x: x.name == solver_name,
|
||||
self.conf.solvers), None)
|
||||
solver_results = self._solver_from_results_path(dir_path)
|
||||
if solver_results is None:
|
||||
self.msg_results_warning(
|
||||
info=self._trad["mb_results_not_found"],
|
||||
|
|
|
|||
Loading…
Reference in New Issue