Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions renal_capacity_model/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ def __init__(
self.time_to_event_curves = load_time_to_event_curves(
path_to_time_to_event_curves
)
self.daily_costs = config_dict["daily_costs"]
logger.info("🔧 Config loaded successfully")
6 changes: 6 additions & 0 deletions renal_capacity_model/config_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@
"pre_emptive_transplant_cadaver_donor_dist": {
y: {"early": 0.22, "late": 0.05} for y in range(1, 14)
},
"daily_costs": {
"ichd": 62842 / 365,
"hhd": 51122 / 365,
"pd": 39391 / 365,
"transplant": 9005 / 365,
},
}

# Time to death: conservative care
Expand Down
2 changes: 1 addition & 1 deletion renal_capacity_model/load_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def load_scenario_from_excel(
"ichd": input_scenario.iat[36, 1],
"hhd": input_scenario.iat[37, 1],
"pd": input_scenario.iat[38, 1],
"living_with_transplant": input_scenario.iat[39, 1],
"transplant": input_scenario.iat[39, 1],
}

return config_from_excel
4 changes: 1 addition & 3 deletions renal_capacity_model/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def main(
)
for excel_file in [path_to_inputs_file, path_to_outputs_file]:
filepaths.append(copy_excel_files(excel_file, run_start_time))
write_results_to_excel(
filepaths[1], combined_results, trial.yearly_activity_duration
)
write_results_to_excel(filepaths[1], combined_results, trial.costs_dfs)


if __name__ == "__main__":
Expand Down
35 changes: 29 additions & 6 deletions renal_capacity_model/process_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ def copy_excel_files(path_to_file: str, run_start_time: str) -> str:
def write_results_to_excel(
path_to_results_excel_file: str,
combined_df: pd.DataFrame,
yearly_activity_duration: pd.DataFrame,
costs_dfs: dict[str, pd.DataFrame],
):
"""Write combined model results from all model runs to Excel file

Args:
path_to_excel_file (str): Path to Excel file
combined_df (pd.DataFrame): Dataframe of all model results combined and processed
yearly_activity_duration (pd.DataFrame): Dataframe of counts of activity for each year of
costs_dfs (pd.DataFrame): Dataframe of costs of activity for each year of
model simulation, for each model run
"""
with pd.ExcelWriter(
Expand All @@ -214,10 +214,33 @@ def write_results_to_excel(
combined_df.loc[outcome].to_excel(
writer, sheet_name=outcome.replace("waiting_for_transplant", "wft")
)
for activity in ["ichd", "hhd", "pd", "transplant"]:
yearly_activity_duration.pivot(
index="model_run", columns="year", values=activity
).sort_index(axis=1).to_excel(writer, sheet_name=f"{activity}_yearly")
for activity, df in costs_dfs.items():
df.to_excel(writer, sheet_name=f"{activity}_yearly")
logger.info(
f"✅ 💾 Excel format model results written to: \n{path_to_results_excel_file}"
)


def convert_activity_to_costs(
yearly_activity_duration: pd.DataFrame, daily_costs: dict[str, float]
) -> dict[str, pd.DataFrame]:
"""Converts yearly activity duration dataframe into costs for each type of activity

Args:
yearly_activity_duration (pd.DataFrame): Dataframe with yearly activity durations
for each of the activity types
daily_costs (dict[str, float]): Daily costs dictionary, set in config

Returns:
dict[str, pd.DataFrame]: Dictionary where keys are treatment modality and
values are a DataFrame with the yearly costs for each across each of the model runs
"""
costs_dfs = {}
for activity in ["ichd", "hhd", "pd", "transplant"]:
costs_dfs[activity] = (
yearly_activity_duration.pivot(
index="model_run", columns="year", values=activity
).sort_index(axis=1)
* daily_costs[activity]
)
return costs_dfs
4 changes: 4 additions & 0 deletions renal_capacity_model/trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
create_results_folder,
save_result_files,
calculate_activity_duration_per_year,
convert_activity_to_costs,
)
import numpy as np
from tqdm import tqdm
Expand Down Expand Up @@ -96,6 +97,9 @@ def run_trial(self):
self.yearly_activity_duration = calculate_activity_duration_per_year(
self.event_log_dfs
)
self.costs_dfs = convert_activity_to_costs(
self.yearly_activity_duration, self.config.daily_costs
)
logger.info("💾 Saving full trial results")
self.save_trial_results(
self.process_eventlog_dfs(self.activity_change_dfs), "activity_change"
Expand Down
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.