-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cum_inc by age and get_derived_outputs
- Loading branch information
1 parent
20c2dd8
commit 40da43b
Showing
3 changed files
with
216 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 18 additions & 32 deletions
50
user/rragonnet/remote_run_outputs/country_highlights.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
user/rragonnet/remote_run_outputs/get_derived_outputs.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"from pathlib import Path\n", | ||
"from autumn.projects.sm_covid2.common_school.calibration import get_bcm_object\n", | ||
"from estival.sampling import tools as esamp\n", | ||
"import yaml\n", | ||
"from autumn.projects.sm_covid2.common_school.runner_tools import INCLUDED_COUNTRIES\n", | ||
"import pickle\n", | ||
"\n", | ||
"full_iso3_list = list(INCLUDED_COUNTRIES['all'].keys())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"analysis_folders = {\n", | ||
" \"main\": Path.cwd() / \"31747883_full_analysis_26Sep2023_main\",\n", | ||
" \"increased_hh_contacts\": Path.cwd() /\"31902886_full_analysis_05Oct2023_increased_hh_contacts\",\n", | ||
" \"no_google_mobility\": Path.cwd() /\"31915437_full_analysis_05Oct2023_no_google_mobility\"\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def get_mle_derived_outputs(iso3, analysis, save=True):\n", | ||
" best_params_path = analysis_folders[analysis] / iso3 / \"retained_best_params.yml\"\n", | ||
" with open(best_params_path, \"r\") as f:\n", | ||
" best_params = yaml.unsafe_load(f)\n", | ||
" mle_params = best_params[0]\n", | ||
" \n", | ||
" derived_outputs = {}\n", | ||
" for sc in [\"baseline\", \"scenario_1\"]:\n", | ||
" bcm = get_bcm_object(iso3, analysis=analysis, scenario=sc)\n", | ||
" res = esamp.model_results_for_samples([mle_params], bcm)\n", | ||
" derived_outputs[sc] = res.results.xs(0, level=\"sample\", axis=1)\n", | ||
"\n", | ||
" if save:\n", | ||
" with open(analysis_folders[analysis] / iso3 / \"derived_outputs.pickle\", \"wb\") as f:\n", | ||
" pickle.dump(derived_outputs, f)\n", | ||
"\n", | ||
" return derived_outputs" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for analysis in analysis_folders:\n", | ||
" for iso3 in full_iso3_list:\n", | ||
" print(f\"{analysis}: {iso3}\")\n", | ||
" derived_outputs = get_mle_derived_outputs(iso3, analysis)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"dos = pd.read_pickle(analysis_folders['main'] / 'FRA' / \"derived_outputs.pickle\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "summer2", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |