From ed1a1a71ac4b4ff83cdc6f41ef38cb8719412d8e Mon Sep 17 00:00:00 2001 From: Theophile Terraz <theophile.terraz@inrae.fr> Date: Tue, 11 Feb 2025 10:20:12 +0100 Subject: [PATCH] debug --- .../InitialConditions/InitialConditions.py | 18 ++++++++++++------ src/Solver/Mage.py | 11 ++++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Model/InitialConditions/InitialConditions.py b/src/Model/InitialConditions/InitialConditions.py index b069a5db..16f1fcf5 100644 --- a/src/Model/InitialConditions/InitialConditions.py +++ b/src/Model/InitialConditions/InitialConditions.py @@ -384,9 +384,11 @@ class InitialConditions(SQLSubModel): width = profile.wet_width(profile.z_min() + height) frictions = self._reach.frictions.frictions strickler = None - for f in frictions: - if f.contains_rk(profile.rk): - strickler = f.get_friction(profile.rk)[0] + if frictions is not None: + if len(frictions) >= 1: + for f in frictions: + if f.contains_rk(profile.rk): + strickler = f.get_friction(profile.rk)[0] if strickler is None: strickler = 25.0 @@ -423,6 +425,8 @@ class InitialConditions(SQLSubModel): def generate_discharge(self, discharge: float, compute_height: bool): profiles = self._reach.reach.profiles.copy() + if profiles is None: + return None profiles.reverse() previous_elevation = -99999.99 @@ -443,9 +447,11 @@ class InitialConditions(SQLSubModel): width = profile.width_approximation() frictions = self._reach.frictions.frictions strickler = None - for f in frictions: - if f.contains_rk(profile.rk): - strickler = f.get_friction(profile.rk)[0] + if frictions is not None: + if len(frictions) >= 1: + for f in frictions: + if f.contains_rk(profile.rk): + strickler = f.get_friction(profile.rk)[0] if strickler is None: strickler = 25.0 diff --git a/src/Solver/Mage.py b/src/Solver/Mage.py index 5525efaf..c4696d16 100644 --- a/src/Solver/Mage.py +++ b/src/Solver/Mage.py @@ -994,6 +994,7 @@ class Mage8(Mage): reachs = [] iprofiles = {} + profile_len = [] reach_offset = {} data = read_int(2*nb_reach) @@ -1013,6 +1014,7 @@ class Mage8(Mage): # Profile ID offset reach_offset[r] = i1 + profile_len.append(i2-i1+1) logger.debug(f"read_bin: iprofiles = {iprofiles}") @@ -1041,6 +1043,13 @@ class Mage8(Mage): ] def ip_to_ri(r, i): return i - reach_offset[r] + # check results and geometry consistency + for i, r in enumerate(reachs): + if len(r.profiles) != profile_len[i]: + logger.warning(f"geometry reach {i} has {len(r.profiles)} profiles") + logger.warning(f"results reach {i} has {profile_len[i]} values") + return + ts = set() end = False while not end: @@ -1050,7 +1059,7 @@ class Mage8(Mage): f, dtype=np.byte, count=1)).decode() data = read_float(n) - logger.debug(f"read_bin: timestamp = {timestamp} sec") + #logger.debug(f"read_bin: timestamp = {timestamp} sec") ts.add(timestamp) if key in ["Z", "Q"]: -- GitLab