diff --git a/notebooks/samenvoegen_modellen.py b/notebooks/samenvoegen_modellen.py index 27fddd0..4d3a156 100644 --- a/notebooks/samenvoegen_modellen.py +++ b/notebooks/samenvoegen_modellen.py @@ -195,13 +195,18 @@ def get_model_path(model, model_version): # read model ribasim_model = Model.read(model_path) + # TODO: make sure this isn't needed next round! + if model["authority"] in RESET_TABLES: + ribasim_model.remove_unassigned_basin_area() + ribasim_model = reset_static_tables(ribasim_model) + # run model if not ribasim_model.basin_outstate.filepath.exists(): print("run model to update state") returncode = ribasim_model.run() if returncode != 0: raise Exception("model won't run successfully!") - ribasim_model.update_state() + ribasim_model.update_state() # add meta_waterbeheerder for node_type in ribasim_model.node_table().df.node_type.unique(): @@ -211,11 +216,6 @@ def get_model_path(model, model_version): if idx == 0: lhm_model = ribasim_model else: - # TODO: make sure this isn't needed next round! - if model["authority"] in RESET_TABLES: - ribasim_model.remove_unassigned_basin_area() - ribasim_model = reset_static_tables(ribasim_model) - lhm_model = concat([lhm_model, ribasim_model]) readme += f""" **{model["authority"]}**: {model["model"]} ({model_version.version})""" diff --git a/src/ribasim_nl/ribasim_nl/model.py b/src/ribasim_nl/ribasim_nl/model.py index dddc0fd..0e5ecdc 100644 --- a/src/ribasim_nl/ribasim_nl/model.py +++ b/src/ribasim_nl/ribasim_nl/model.py @@ -122,13 +122,13 @@ def update_state(self, time_stamp: pd.Timestamp | None = None): time_stamp (pd.Timestamp | None, optional): Timestamp in results to update basin.state with . Defaults to None. """ if time_stamp is None: - self.basin.state = self.basin_outstate.df + df = self.basin_outstate.df else: df = self.basin_results.df.loc[time_stamp][["node_id", "level"]] df.reset_index(inplace=True, drop=True) - df.index += 1 - df.index.name = "fid" - self.basin.state = df + df.index += 1 + df.index.name = "fid" + self.basin.state.df = df # methods relying on networkx. Discuss making this all in a subclass of Model def _upstream_nodes(self, node_id):