Skip to content

Commit

Permalink
fix #129: the compartment picker can pass an error message, solves a …
Browse files Browse the repository at this point in the history
…lot of slacking
  • Loading branch information
jcblemai committed Nov 15, 2023
1 parent 90b38ad commit 05ec840
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions flepimop/gempyor_pkg/src/gempyor/compartments.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def fromFile(self, compartments_file, transitions_file):

return

def get_comp_idx(self, comp_dict: dict) -> int:
def get_comp_idx(self, comp_dict: dict, error_info: str = "no information") -> int:
"""
return the index of a compartiment given a filter. The filter has to isolate a compartiment,
but it ignore columns that don't exist:
Expand All @@ -294,7 +294,7 @@ def get_comp_idx(self, comp_dict: dict) -> int:
comp_idx = self.compartments[mask].index.values
if len(comp_idx) != 1:
raise ValueError(
f"The provided dictionary does not allow to isolate a compartment: {comp_dict} isolate {self.compartments[mask]} from options {self.compartments}"
f"The provided dictionary does not allow to isolate a compartment: {comp_dict} isolate {self.compartments[mask]} from options {self.compartments}. The get_comp_idx function was called by'{error_info}'."
)
return comp_idx[0]

Expand Down
4 changes: 2 additions & 2 deletions flepimop/gempyor_pkg/src/gempyor/seeding_ic.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def _DataFrame2NumbaDict(df, amounts, setup) -> nb.typed.Dict:
)
source_dict = {grp_name: row[f"source_{grp_name}"] for grp_name in cmp_grp_names}
destination_dict = {grp_name: row[f"destination_{grp_name}"] for grp_name in cmp_grp_names}
seeding_dict["seeding_sources"][idx] = setup.compartments.get_comp_idx(source_dict)
seeding_dict["seeding_destinations"][idx] = setup.compartments.get_comp_idx(destination_dict)
seeding_dict["seeding_sources"][idx] = setup.compartments.get_comp_idx(source_dict, error_info = f"(seeding source at idx={idx}, row_index={row_index}, row=>>{row}<<)")
seeding_dict["seeding_destinations"][idx] = setup.compartments.get_comp_idx(destination_dict, error_info = f"(seeding destination at idx={idx}, row_index={row_index}, row=>>{row}<<)")
seeding_dict["seeding_subpops"][idx] = setup.subpop_struct.subpop_names.index(row["subpop"])
seeding_amounts[idx] = amounts[idx]
#id_seed+=1
Expand Down

0 comments on commit 05ec840

Please sign in to comment.