mirror of https://gitlab.com/pamhyr/pamhyr2
Solver: export the relative time for solver files, in the case of a study in date mode, which is the date mentionned in the data minus the study start date
parent
0a0c00d877
commit
75f3c07cd9
|
|
@ -594,7 +594,9 @@ class AdisTSwc(AdisTS):
|
|||
f.write(f"*---------++++++++++\n")
|
||||
|
||||
for LC_data in LC.data:
|
||||
tmp = timestamp_to_old_pamhyr_date_adists(int(LC_data[0]))
|
||||
tmp = timestamp_to_old_pamhyr_date_adists(
|
||||
int(self.export_time(study, LC_data[0]))
|
||||
)
|
||||
f.write(" ".join((f"{tmp}",
|
||||
f"{LC_data[1]}\n")))
|
||||
f.write(f"*\n")
|
||||
|
|
@ -626,7 +628,9 @@ class AdisTSwc(AdisTS):
|
|||
f.write(f"*---------++++++++++\n")
|
||||
|
||||
for BC_data in BC.data:
|
||||
tmp = timestamp_to_old_pamhyr_date_adists(int(BC_data[0]))
|
||||
tmp = timestamp_to_old_pamhyr_date_adists(
|
||||
int(self.export_time(study, BC_data[0]))
|
||||
)
|
||||
f.write(" ".join((f"{tmp}",
|
||||
f"{BC_data[1]}\n")))
|
||||
f.write(f"*\n")
|
||||
|
|
|
|||
|
|
@ -884,7 +884,9 @@ class AdisTTwc(AdisTT):
|
|||
f.write("*temps |temperature (degC)\n")
|
||||
f.write("*---------++++++++++\n")
|
||||
for value in boundary_condition.data:
|
||||
date = timestamp_to_old_pamhyr_date_adists(int(value[0]))
|
||||
date = timestamp_to_old_pamhyr_date_adists(
|
||||
int(self.export_time(study, value[0]))
|
||||
)
|
||||
f.write(f"{date} {value[1]}\n")
|
||||
f.write("*\n")
|
||||
return filename
|
||||
|
|
@ -907,7 +909,9 @@ class AdisTTwc(AdisTT):
|
|||
f.write("*temps |value\n")
|
||||
f.write("*---------++++++++++\n")
|
||||
for value in weather_parameter.data:
|
||||
date = timestamp_to_old_pamhyr_date_adists(int(value[0]))
|
||||
date = timestamp_to_old_pamhyr_date_adists(
|
||||
int(self.export_time(study, value[0]))
|
||||
)
|
||||
f.write(f"{date} {value[1]}\n")
|
||||
f.write("*\n")
|
||||
return filename
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@
|
|||
import os
|
||||
import logging
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from tools import timer, parse_command_line, get_version, logger_exception
|
||||
from tools import parse_datetime
|
||||
|
||||
try:
|
||||
# Installation allow Unix-like signal
|
||||
|
|
@ -44,6 +45,15 @@ logger = logging.getLogger()
|
|||
class CommandLineSolver(AbstractSolver):
|
||||
_type = ""
|
||||
|
||||
@staticmethod
|
||||
def export_time(study, value):
|
||||
"""Return elapsed seconds before applying the solver file's units."""
|
||||
if study.time_system != "date":
|
||||
return value
|
||||
# Match the UTC timestamps produced by date entry in the tables.
|
||||
start = parse_datetime(study.date).replace(tzinfo=timezone.utc)
|
||||
return float(value) - start.timestamp()
|
||||
|
||||
def __init__(self, name):
|
||||
super(CommandLineSolver, self).__init__(name)
|
||||
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ class Mage(CommandLineSolver):
|
|||
# Point line
|
||||
wfile.write(f"{x} {y} {z} {n} {sediment}\n")
|
||||
|
||||
def _export_BC(self, t, bounds, repertory, qlog, name="0"):
|
||||
def _export_BC(self, study, t, bounds, repertory, qlog, name="0"):
|
||||
files = []
|
||||
|
||||
if len(bounds) == 0:
|
||||
|
|
@ -333,7 +333,7 @@ class Mage(CommandLineSolver):
|
|||
v1 = d[1]
|
||||
|
||||
if t in ["HYD", "LIM"]:
|
||||
v0 /= 60 # Convert first column to minute
|
||||
v0 = self.export_time(study, v0) / 60 # Minutes
|
||||
|
||||
f.write(f"{v0:9} {v1:9} \n")
|
||||
|
||||
|
|
@ -365,10 +365,16 @@ class Mage(CommandLineSolver):
|
|||
elif bound.bctype == "SL":
|
||||
QSO.append(bound)
|
||||
|
||||
files = files + self._export_BC("AVA", AVA, repertory, qlog, name=name)
|
||||
files = files + self._export_BC("HYD", HYD, repertory, qlog, name=name)
|
||||
files = files + self._export_BC("LIM", LIM, repertory, qlog, name=name)
|
||||
files = files + self._export_QSO(QSO, repertory, qlog, name=name)
|
||||
files = files + self._export_BC(
|
||||
study, "AVA", AVA, repertory, qlog, name=name
|
||||
)
|
||||
files = files + self._export_BC(
|
||||
study, "HYD", HYD, repertory, qlog, name=name
|
||||
)
|
||||
files = files + self._export_BC(
|
||||
study, "LIM", LIM, repertory, qlog, name=name
|
||||
)
|
||||
files = files + self._export_QSO(study, QSO, repertory, qlog, name=name)
|
||||
|
||||
return files
|
||||
|
||||
|
|
@ -422,10 +428,11 @@ class Mage(CommandLineSolver):
|
|||
if d.is_deleted():
|
||||
continue
|
||||
|
||||
time = self.export_time(study, d[0])
|
||||
if lateral.lctype in ["EV"]:
|
||||
f.write(f"{d[0]:10.3f}{-d[1]:10.3f}\n")
|
||||
f.write(f"{time:10.3f}{-d[1]:10.3f}\n")
|
||||
else:
|
||||
f.write(f"{d[0]:10.3f}{d[1]:10.3f}\n")
|
||||
f.write(f"{time:10.3f}{d[1]:10.3f}\n")
|
||||
|
||||
def _export_RUG(self, study, repertory, qlog, name="0"):
|
||||
files = []
|
||||
|
|
@ -964,7 +971,7 @@ class Mage8(Mage):
|
|||
|
||||
return files
|
||||
|
||||
def _export_QSO(self, bounds, repertory, qlog, name="0"):
|
||||
def _export_QSO(self, study, bounds, repertory, qlog, name="0"):
|
||||
files = []
|
||||
|
||||
if len(bounds) == 0:
|
||||
|
|
@ -994,7 +1001,8 @@ class Mage8(Mage):
|
|||
|
||||
# Data
|
||||
for d in bound.data:
|
||||
f.write(f"{d[0]/60:10.3f}{d[1]:10.3f}\n")
|
||||
time = self.export_time(study, d[0]) / 60
|
||||
f.write(f"{time:10.3f}{d[1]:10.3f}\n")
|
||||
|
||||
return files
|
||||
|
||||
|
|
|
|||
|
|
@ -550,7 +550,8 @@ class Rubar3(CommandLineSolver):
|
|||
for bc in bcs:
|
||||
f.write(f"{len(bc)}\n")
|
||||
for d0, d1 in bc.data:
|
||||
f.write(f"{d1} {d0}\n")
|
||||
time = self.export_time(study, d0)
|
||||
f.write(f"{d1} {time}\n")
|
||||
|
||||
def _export_condav(self, study, repertory, qlog, name="0"):
|
||||
if qlog is not None:
|
||||
|
|
@ -577,7 +578,8 @@ class Rubar3(CommandLineSolver):
|
|||
f.write(f"{d1} {d0}\n")
|
||||
else:
|
||||
for d0, d1 in bc.data:
|
||||
f.write(f"{d0} {d1}\n")
|
||||
time = self.export_time(study, d0)
|
||||
f.write(f"{time} {d1}\n")
|
||||
|
||||
def read_profil(self, study, fname, results, qlog=None, name="0"):
|
||||
logger.info(f"read: profil.{name}")
|
||||
|
|
|
|||
Loading…
Reference in New Issue