HS, Mage: Rewrite some code for coding style.

setup.py
Pierre-Antoine Rouby 2023-12-13 16:30:18 +01:00
parent 73ae571de1
commit cd2fda8224
2 changed files with 75 additions and 88 deletions

View File

@ -31,77 +31,6 @@ from Model.Results.River.River import River, Reach, Profile
logger = logging.getLogger()
def mage_param(bhs):
params = []
if bhs._type == "S1": # D
params = [bhs._data[0].value,
bhs._data[1].value,
0.0,
bhs._data[2].value,
9999.999,
]
elif bhs._type == "S2": # T
params = [bhs._data[0].value,
bhs._data[1].value,
bhs._data[2].value,
bhs._data[3].value,
bhs._data[4].value,
]
elif bhs._type == "S3": # T
params = [0.0,bhs._data[0].value,
bhs._data[1].value,
bhs._data[2].value,
bhs._data[3].value,
]
elif bhs._type == "OR": # O
params = [bhs._data[0].value,
bhs._data[1].value,
bhs._data[2].value,
bhs._data[3].value,
bhs._data[4].value,
]
elif bhs._type == "OC": # B
params = [bhs._data[0].value,
bhs._data[1].value,
bhs._data[2].value,
bhs._data[3].value,
0.0,
]
elif bhs._type == "V1": # V
params = [bhs._data[0].value,
bhs._data[1].value,
bhs._data[2].value,
bhs._data[3].value,
bhs._data[4].value,
]
elif bhs._type == "V2": # W
params = [bhs._data[0].value,
bhs._data[1].value,
bhs._data[2].value,
bhs._data[3].value,
bhs._data[4].value,
]
elif bhs._type == "BO": # B
params = [bhs._data[0].value,
bhs._data[1].value,
bhs._data[2].value,
0.0,
0.0,
]
elif bhs._type == "UD": # X
params = [bhs._data[0].value,
bhs._data[1].value,
bhs._data[2].value,
bhs._data[3].value,
bhs._data[4].value,
]
else:
params = [9999.999]*5
return params
def mage_file_open(filepath, mode):
f = open(filepath, mode)
@ -549,7 +478,7 @@ class Mage(CommandLineSolver):
param_str = ' '.join(
[
f'{p:>10.3f}'
for p in mage_param(bhs)
for p in self._export_SIN_parameters(bhs)
]
)
@ -561,6 +490,64 @@ class Mage(CommandLineSolver):
return files
def _export_SIN_parameters(self, bhs):
res = [9999.999]*5
if len(bhs) == 5:
res = self._export_SIN_parameters_5(bhs)
elif len(bhs) == 4:
res = self._export_SIN_parameters_4(bhs)
elif len(bhs) == 3:
res = self._export_SIN_parameters_3(bhs)
return res
def _export_SIN_parameters_5(self, bhs):
# S2, OR, V1, V2, UD
return [
bhs._data[0].value,
bhs._data[1].value,
bhs._data[2].value,
bhs._data[3].value,
bhs._data[4].value,
]
def _export_SIN_parameters_4(self, bhs):
# S3, OC
res = [
bhs._data[0].value,
bhs._data[1].value,
bhs._data[2].value,
bhs._data[3].value,
0.0,
]
if bhs._type == "T": # S3
res = [0.0] + res[:-1]
return res
def _export_SIN_parameters_3(self, bhs):
# S1, BO
if bhs._type == "S1":
res = [
bhs._data[0].value,
bhs._data[1].value,
0.0,
bhs._data[2].value,
9999.99,
]
else:
res = [
bhs._data[0].value,
bhs._data[1].value,
bhs._data[2].value,
0.0,
0.0,
]
return res
@timer
def _export_DEV(self, study, repertory, qlog, name="0"):
files = []