From 16f81ae845aad337117ddfda94375f2176551efe Mon Sep 17 00:00:00 2001 From: Joseph Lemaitre Date: Fri, 3 Nov 2023 19:49:16 +0100 Subject: [PATCH] fix the seeding bug dirtily (need some error message --- flepimop/gempyor_pkg/src/gempyor/seeding_ic.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/flepimop/gempyor_pkg/src/gempyor/seeding_ic.py b/flepimop/gempyor_pkg/src/gempyor/seeding_ic.py index d1b46c2c6..64e3a1b1e 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seeding_ic.py +++ b/flepimop/gempyor_pkg/src/gempyor/seeding_ic.py @@ -34,6 +34,8 @@ def _DataFrame2NumbaDict(df, amounts, setup) -> nb.typed.Dict: n_seeding_ignored_before = 0 n_seeding_ignored_after = 0 + + #id_seed = 0 for idx, (row_index, row) in enumerate(df.iterrows()): if row["place"] not in setup.spatset.nodenames: raise ValueError( @@ -42,6 +44,7 @@ def _DataFrame2NumbaDict(df, amounts, setup) -> nb.typed.Dict: if (row["date"].date() - setup.ti).days >= 0: if (row["date"].date() - setup.ti).days < len(nb_seed_perday): + nb_seed_perday[(row["date"].date() - setup.ti).days] = ( nb_seed_perday[(row["date"].date() - setup.ti).days] + 1 ) @@ -51,6 +54,7 @@ def _DataFrame2NumbaDict(df, amounts, setup) -> nb.typed.Dict: seeding_dict["seeding_destinations"][idx] = setup.compartments.get_comp_idx(destination_dict) seeding_dict["seeding_places"][idx] = setup.spatset.nodenames.index(row["place"]) seeding_amounts[idx] = amounts[idx] + #id_seed+=1 else: n_seeding_ignored_after += 1 else: @@ -230,7 +234,15 @@ def draw_seeding(self, sim_id: int, setup) -> nb.typed.Dict: raise NotImplementedError(f"unknown seeding method [got: {method}]") # Sorting by date is very important here for the seeding format necessary !!!! + print(seeding.shape) seeding = seeding.sort_values(by="date", axis="index").reset_index() + print(seeding) + mask = (seeding['date'].dt.date > setup.ti) & (seeding['date'].dt.date <= setup.tf) + seeding = seeding.loc[mask].reset_index() + print(seeding.shape) + print(seeding) + + # TODO: print. amounts = np.zeros(len(seeding)) if method == "PoissonDistributed": @@ -240,6 +252,7 @@ def draw_seeding(self, sim_id: int, setup) -> nb.typed.Dict: elif method == "FolderDraw" or method == "FromFile": amounts = seeding["amount"] + return _DataFrame2NumbaDict(df=seeding, amounts=amounts, setup=setup) def load_seeding(self, sim_id: int, setup) -> nb.typed.Dict: