Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scenario switcher - htm #1377

Merged
merged 144 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
7590a5b
updates from paper analyses for HIV, TB and malaria
tdm32 Feb 9, 2024
22c10f0
remove unused import statements
tdm32 Feb 9, 2024
e8612a3
fix imports
tdm32 Feb 9, 2024
c6802c9
update filepath for malaria resource file
tdm32 Feb 9, 2024
8014f02
remove test_hiv_tb_scenarios.py
tdm32 Feb 9, 2024
63a364a
updated test_healthsystem.py: test_manipulation_of_service_availabili…
tdm32 Feb 13, 2024
b591b82
change ipt_coverage in TB logger as conflicts with existing parameter
tdm32 Feb 13, 2024
68b295e
updated ResourceFile_Improved_Healthsystem_And_Healthcare_Seeking.xls…
tdm32 Feb 13, 2024
7dbe7b5
remove test code
tdm32 Feb 13, 2024
09c9b26
remove test code
tdm32 Feb 13, 2024
3800748
Merge branch 'master' into tara_feb2024_updates_clean
tdm32 Feb 13, 2024
73f19da
delete tmp resourcefiles
tdm32 Feb 13, 2024
b81b2d6
malaria code use person_id consistently instead of individual_id
tdm32 Feb 13, 2024
df2b77e
use individual_id for demography.do_death()
tdm32 Feb 13, 2024
b2bd355
style change to avoid conflicts with master
tdm32 Feb 14, 2024
09b9b66
style change to avoid conflicts with master
tdm32 Feb 14, 2024
8a241e4
Merge branch 'master' into tara_feb2024_updates_clean
tdm32 Feb 14, 2024
758955e
fix conflicts with master
tdm32 Feb 14, 2024
f7ac7e2
fix conflicts with master
tdm32 Feb 14, 2024
c037a4d
Merge branch 'master' into tara_feb2024_updates_clean
tdm32 Feb 14, 2024
9690949
merge in master
tdm32 Feb 14, 2024
05c69ff
check property hv_date_last_ART correctly set
tdm32 Feb 15, 2024
3e3c0d4
Manually add PostnatalCare_Comprehensive to policy priorities
tdm32 Feb 16, 2024
cfd9166
edit fix
tdm32 Feb 16, 2024
3ff7bcb
add schisto high infection as conditional predictor for bladder cancer
tdm32 Feb 27, 2024
434147c
fix conditional predictor for active TB - should check presence of Ca…
tdm32 Feb 27, 2024
808c5ae
add 'ss' prefix to properties from schisto module referenced in bladd…
tdm32 Feb 27, 2024
218f4cf
edit praziquantel code in schisto.py to use value from CMST in place …
tdm32 Feb 27, 2024
f8ebee5
add parameter rr_depr_hiv for risk of depression with HIV infection
tdm32 Feb 27, 2024
904905d
tidy up linear models in depression, include conditional predictors f…
tdm32 Feb 27, 2024
79216db
move hv_inf into conditional predictor for depression in initial popu…
tdm32 Feb 27, 2024
ade9f57
convert lm for incident cancer (site_confined) to model with conditio…
tdm32 Feb 28, 2024
754a1bf
add parameter rr_site_confined_hiv to other_adult_cancers.py
tdm32 Feb 28, 2024
876c979
update other_adult_cancers write-up to include HIV as risk factor
tdm32 Feb 28, 2024
865aae0
update Depression.docx to include HIV as risk factor for depression
tdm32 Feb 28, 2024
5bb2560
edit HIV in depression to include only HIV cases not virally suppressed
tdm32 Feb 28, 2024
9cb1043
update other_adult_cancers.py linear model to include HIV as risk fac…
tdm32 Feb 28, 2024
1e316af
edit: HIV remains as risk factor for depression independent of treatm…
tdm32 Feb 28, 2024
85cec50
include HIV as risk factor for low grade dysplasia (oesophageal cance…
tdm32 Feb 28, 2024
6f45dc7
update linear model for low grade dysplasia to include HIV as conditi…
tdm32 Feb 28, 2024
2dbb98d
update OesophagealCancer.docx write-up to include HIV risk
tdm32 Feb 28, 2024
b6b5fdc
add condition hiv diagnosed for increased risk of depression
tdm32 Mar 4, 2024
a040823
remove hiv as risk factor for oesophageal cancer
tdm32 Mar 4, 2024
1eeff16
remove parameter for hiv as risk factor for oesophageal cancer
tdm32 Mar 4, 2024
78b73e5
update OesophagealCancer.docx to remove hiv as risk factor
tdm32 Mar 4, 2024
b899660
update value for weighted risk of other_adult_cancers with unsuppress…
tdm32 Mar 4, 2024
599580b
add rr_hiv to linear model. update ResourceFile_cmd_condition_onset.x…
tdm32 Mar 4, 2024
953502e
update resourcefiles for CMD include rr_hiv for all, no effect of maj…
tdm32 Mar 4, 2024
b57a503
add diabetes as risk for active TB and relapse. add params to Resourc…
tdm32 Mar 5, 2024
465b18b
add diabetes as risk factor for tb death
tdm32 Mar 5, 2024
d573211
add diabetes as risk factor for PLHIV with active TB and on TB treatment
tdm32 Mar 5, 2024
3734acb
add diabetes as risk factor for PLHIV with active TB and on TB treatment
tdm32 Mar 5, 2024
7e5f6a6
set up run to check calibration of deaths and disability
tdm32 Mar 5, 2024
b786256
add predictor high-intensity S. haematobium infection to risk of blad…
tdm32 Mar 6, 2024
956b09a
add predictor high-intensity S. haematobium infection to risk of HIV …
tdm32 Mar 6, 2024
e375927
fix indenting in HSI_Hiv_StartOrContinueTreatment
tdm32 Mar 7, 2024
272558f
add hv_date_treated abd hv_date_last_ART to baseline_art
tdm32 Mar 7, 2024
8602f03
convert linear model in CMD to include conditional predictors
tdm32 Mar 11, 2024
2f87289
delete resourcefile created in error
tdm32 Mar 11, 2024
c8d65f4
comment out path-specific changes to analysis_cause_of_death_and_disa…
tdm32 Mar 11, 2024
1574c3a
fix CMD error if Hiv not registered
tdm32 Mar 11, 2024
7b6e3d5
Merge branch 'master' into tara_hiv_ncd_feb2024
tdm32 Mar 11, 2024
f20b151
Merge branch 'master' into tara_hiv_ncd_feb2024
tdm32 Mar 11, 2024
3e982bf
Merge remote-tracking branch 'origin/tara_hiv_ncd_feb2024' into tara_…
tdm32 Mar 11, 2024
f0466bf
Merge branch 'master' into tara_feb2024_updates_clean
tdm32 Mar 12, 2024
9901edd
remove parameter rr_bcg_inf from tb.py
tdm32 Mar 19, 2024
62e5c04
Merge branch 'master' into tara_feb2024_updates_clean
tdm32 Mar 22, 2024
7e3e20f
edit comment in initialise_simulation
tdm32 Mar 22, 2024
7ec6efa
Merge branch 'tara_hiv_ncd_feb2024' into tara_feb2024_updates_clean
tdm32 Mar 22, 2024
922ac8e
fix parameter name error
tdm32 Mar 22, 2024
1b61aaf
update parameters
tdm32 Mar 22, 2024
3aa7b46
test runs
tdm32 Mar 22, 2024
604bd14
edit and fix flake8 errors
tdm32 Mar 22, 2024
629e2e0
fix failing test
tdm32 Mar 22, 2024
8bba11c
update ResourceFile_Improved_Healthsystem_And_Healthcare_Seeking.xlsx
tdm32 Mar 25, 2024
6543bd0
update ResourceFile_PriorityRanking_ALLPOLICIES.xlsx
tdm32 Mar 25, 2024
5edc77d
updated ResourceFile_Improved_Healthsystem_And_Healthcare_Seeking.xlsx
tdm32 Mar 25, 2024
a1f0da9
Merge branch 'master' into tara_feb2024_updates_clean
tdm32 Apr 22, 2024
b34d670
edit check for last ART when new dispensation occurs
tdm32 May 2, 2024
d56c3d8
update schisto risk on HIV to only include women
tdm32 May 13, 2024
9667bd3
add scale-up parameter for htm programs
tdm32 May 13, 2024
73c6abf
add catch for malaria rdt_testing_rates post-2024
tdm32 May 14, 2024
39cce9b
malaria parameters scale-up included
tdm32 May 14, 2024
15d63bc
set up test for HTM scenario scale-up
tdm32 May 27, 2024
e8699b8
add tests for HTM scale-up
tdm32 May 28, 2024
89435ad
check resourcefiles updated
tdm32 May 28, 2024
1f261b9
check the usage of '' versus ""
tdm32 May 28, 2024
ac58f0a
reset to single quotes to match PR #1273
tdm32 May 28, 2024
4bcb25d
remove unneeded resource files
tdm32 May 28, 2024
f67fa42
remove unneeded resource files
tdm32 May 28, 2024
7082b51
edit filepaths
tdm32 May 29, 2024
721fe0b
isort for imports
tdm32 May 29, 2024
7782350
edit ResourceFile_Improved_Healthsystem_And_Healthcare_Seeking.xlsx t…
tdm32 May 29, 2024
e2c81e2
fix filename for test_HTMscaleup.py
tdm32 May 29, 2024
c21fbc3
set scaleup parameters separately in each module
tdm32 Jun 10, 2024
c2a4590
set scaleup parameters separately in each module
tdm32 Jun 10, 2024
32d2314
Merge branch 'master' into tara_scenario_switcher_updatedHTM
tdm32 Jun 10, 2024
f161de3
update resourcefiles
tdm32 Jun 10, 2024
af5d6a9
update resourcefiles
tdm32 Jun 10, 2024
7fa127f
set up script to test scenarios - scale-up of HTM programs
tdm32 Jun 10, 2024
4e8d6c0
test runs
tdm32 Jun 10, 2024
3458525
add scenario switch to malaria.py
tdm32 Jun 10, 2024
bc1a864
cherry-pick inadvertently updated files and revert
tdm32 Jun 10, 2024
b57379f
isort fixes
tdm32 Jun 10, 2024
8d13b17
Delete resources/~$ResourceFile_HIV.xlsx
tdm32 Jun 10, 2024
e6c7dcf
Delete resources/~$ResourceFile_TB.xlsx
tdm32 Jun 10, 2024
d72487e
Delete resources/malaria/~$ResourceFile_malaria.xlsx
tdm32 Jun 10, 2024
b8163d4
fix failing tests
tdm32 Jun 10, 2024
ee2c8b6
Merge remote-tracking branch 'origin/tara_scenario_switcher_updatedHT…
tdm32 Jun 10, 2024
6304c76
rollback changes to calibration_analyses/scenarios/long_run_all_disea…
tdm32 Jun 10, 2024
63a7dc6
fix error in filename
tdm32 Jun 11, 2024
d06cb84
revert timedelta format to 'M'
tdm32 Jun 11, 2024
7580779
Merge branch 'master' into tara_scenario_switcher_updatedHTM
tdm32 Jun 25, 2024
3443603
merge in master
tdm32 Jun 25, 2024
9ba266f
set up test runs for scale-up
tdm32 Jun 25, 2024
975509c
edit scenario start date
tdm32 Jun 25, 2024
304c423
change parameter scaleup_start_date to an integer value used in DateO…
tdm32 Jun 25, 2024
01745de
change scale-up event scheduling to use new DateOffset parameter
tdm32 Jun 25, 2024
0d8d8e9
test runs
tdm32 Jun 26, 2024
acae16e
set up test runs
tdm32 Jun 26, 2024
67f2fa4
set up test runs
tdm32 Jun 26, 2024
7d668de
fix failing tests
tdm32 Jun 26, 2024
0b3e938
Update tests/test_HTMscaleup.py
tdm32 Jun 26, 2024
fcea78b
address comments on PR review
tdm32 Jun 26, 2024
1a86e9c
isort fixes
tdm32 Jun 26, 2024
a0be80c
isort fixes
tdm32 Jun 26, 2024
802939a
change np.timedelta in enhanced_lifestyle.py back to original
tdm32 Jun 26, 2024
7ff54e6
remove json file
tbhallett Jun 27, 2024
8e19f4f
call it 'htm_scenario_analysis' rather than just 'scenario_analysis'
tbhallett Jun 27, 2024
7ef4914
update comment
tbhallett Jun 27, 2024
d08e346
roll back change in test_tb.py
tbhallett Jun 27, 2024
08e2421
remove .py extension for clarity
tbhallett Jun 27, 2024
52949f8
roll back incidental change
tbhallett Jun 27, 2024
3e91f88
linting and editing string for clarity
tbhallett Jun 27, 2024
ea0eebe
roll back incidental changes
tbhallett Jun 27, 2024
b5ccd4d
defaults for healthsystem ok -- no need to step through each option
tbhallett Jun 27, 2024
9ae9615
remove inadvertent duplication in code
tbhallett Jun 27, 2024
419d2b4
remove comment
tbhallett Jun 27, 2024
66eecb6
use dict for ease of accessing
tbhallett Jun 27, 2024
dc0dd8b
parameter to be the YEAR (int) of the change to fit with the conventi…
tbhallett Jun 27, 2024
08dea6a
remove comment
tbhallett Jun 27, 2024
d591890
refactor module method for clarity
tbhallett Jun 27, 2024
467066d
refactor to prevent same name being used for events specific to diffe…
tbhallett Jun 27, 2024
830f83f
specify year for scale-up in analysis file
tbhallett Jun 27, 2024
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
4 changes: 2 additions & 2 deletions resources/ResourceFile_HIV.xlsx
Git LFS file not shown
4 changes: 2 additions & 2 deletions resources/ResourceFile_TB.xlsx
Git LFS file not shown
4 changes: 2 additions & 2 deletions resources/malaria/ResourceFile_malaria.xlsx
Git LFS file not shown
112 changes: 112 additions & 0 deletions src/scripts/htm_scenario_analyses/analysis_htm_scaleup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

"""
This scenario file sets up the scenarios for simulating the effects of scaling up programs

The scenarios are:
*0 baseline mode 1
*1 scale-up HIV program
*2 scale-up TB program
*3 scale-up malaria program
*4 scale-up HIV and Tb and malaria programs

scale-up occurs on the default scale-up start date (01/01/2025: in parameters list of resourcefiles)

For all scenarios, keep all default health system settings

check the batch configuration gets generated without error:
tlo scenario-run --draw-only src/scripts/htm_scenario_analyses/analysis_htm_scaleup.py

Run on the batch system using:
tlo batch-submit src/scripts/htm_scenario_analyses/analysis_htm_scaleup.py

or locally using:
tlo scenario-run src/scripts/htm_scenario_analyses/analysis_htm_scaleup.py

or execute a single run:
tlo scenario-run src/scripts/htm_scenario_analyses/analysis_htm_scaleup.py --draw 1 0

"""

from pathlib import Path

from tlo import Date, logging
from tlo.methods import (
demography,
enhanced_lifestyle,
epi,
healthburden,
healthseekingbehaviour,
healthsystem,
hiv,
malaria,
simplified_births,
symptommanager,
tb,
)
from tlo.scenario import BaseScenario


class EffectOfProgrammes(BaseScenario):
def __init__(self):
super().__init__()
self.seed = 0
self.start_date = Date(2010, 1, 1)
self.end_date = Date(2020, 1, 1)
self.pop_size = 75_000
self.number_of_draws = 5
self.runs_per_draw = 1

def log_configuration(self):
return {
'filename': 'scaleup_tests',
'directory': Path('./outputs'), # <- (specified only for local running)
'custom_levels': {
'*': logging.WARNING,
'tlo.methods.hiv': logging.INFO,
'tlo.methods.tb': logging.INFO,
'tlo.methods.malaria': logging.INFO,
'tlo.methods.demography': logging.INFO,
}
}

def modules(self):

return [
demography.Demography(resourcefilepath=self.resources),
simplified_births.SimplifiedBirths(resourcefilepath=self.resources),
enhanced_lifestyle.Lifestyle(resourcefilepath=self.resources),
healthsystem.HealthSystem(resourcefilepath=self.resources),
symptommanager.SymptomManager(resourcefilepath=self.resources),
healthseekingbehaviour.HealthSeekingBehaviour(resourcefilepath=self.resources),
healthburden.HealthBurden(resourcefilepath=self.resources),
epi.Epi(resourcefilepath=self.resources),
hiv.Hiv(resourcefilepath=self.resources),
tb.Tb(resourcefilepath=self.resources),
malaria.Malaria(resourcefilepath=self.resources),
]

def draw_parameters(self, draw_number, rng):
scaleup_start_year = 2012

return {
'Hiv': {
'do_scaleup': [False, True, False, False, True][draw_number],
'scaleup_start_year': scaleup_start_year
},
'Tb': {
'do_scaleup': [False, False, True, False, True][draw_number],
'scaleup_start_year': scaleup_start_year
},
'Malaria': {
'do_scaleup': [False, False, False, True, True][draw_number],
'scaleup_start_year': scaleup_start_year
},
}


if __name__ == '__main__':
from tlo.cli import scenario_run

scenario_run([__file__])


139 changes: 139 additions & 0 deletions src/scripts/htm_scenario_analyses/scenario_plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
""" this reads in the outputs generates through analysis_htm_scaleup.py
and produces plots for HIV, TB and malaria incidence
"""


import datetime
from pathlib import Path

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

from tlo import Date
from tlo.analysis.utils import (
extract_params,
extract_results,
get_scenario_info,
get_scenario_outputs,
load_pickled_dataframes,
)

resourcefilepath = Path("./resources")
datestamp = datetime.date.today().strftime("__%Y_%m_%d")

outputspath = Path("./outputs")


# 0) Find results_folder associated with a given batch_file (and get most recent [-1])
results_folder = get_scenario_outputs("scaleup_tests", outputspath)[-1]

# Declare path for output graphs from this script
make_graph_file_name = lambda stub: results_folder / f"{stub}.png" # noqa: E731

# look at one log (so can decide what to extract)
log = load_pickled_dataframes(results_folder)

# get basic information about the results
info = get_scenario_info(results_folder)

# 1) Extract the parameters that have varied over the set of simulations
params = extract_params(results_folder)


# DEATHS


def get_num_deaths_by_cause_label(_df):
"""Return total number of Deaths by label within the TARGET_PERIOD
values are summed for all ages
df returned: rows=COD, columns=draw
"""
return _df \
.loc[pd.to_datetime(_df.date).between(*TARGET_PERIOD)] \
.groupby(_df['label']) \
.size()


TARGET_PERIOD = (Date(2015, 1, 1), Date(2020, 1, 1))

num_deaths_by_cause_label = extract_results(
results_folder,
module='tlo.methods.demography',
key='death',
custom_generate_series=get_num_deaths_by_cause_label,
do_scaling=True
)


def summarise_deaths_for_one_cause(results_folder, label):
""" returns mean deaths for each year of the simulation
values are aggregated across the runs of each draw
for the specified cause
"""

results_deaths = extract_results(
results_folder,
module="tlo.methods.demography",
key="death",
custom_generate_series=(
lambda df: df.assign(year=df["date"].dt.year).groupby(
["year", "label"])["person_id"].count()
),
do_scaling=True,
)
# removes multi-index
results_deaths = results_deaths.reset_index()

# select only cause specified
tmp = results_deaths.loc[
(results_deaths.label == label)
]

# group deaths by year
tmp = pd.DataFrame(tmp.groupby(["year"]).sum())

# get mean for each draw
mean_deaths = pd.concat({'mean': tmp.iloc[:, 1:].groupby(level=0, axis=1).mean()}, axis=1).swaplevel(axis=1)

return mean_deaths


aids_deaths = summarise_deaths_for_one_cause(results_folder, 'AIDS')
tb_deaths = summarise_deaths_for_one_cause(results_folder, 'TB (non-AIDS)')
malaria_deaths = summarise_deaths_for_one_cause(results_folder, 'Malaria')

draw_labels = ['No scale-up', 'HIV, scale-up', 'TB scale-up', 'Malaria scale-up']

colors = sns.color_palette("Set1", 4) # Blue, Orange, Green, Red


# Create subplots
fig, axs = plt.subplots(3, 1, figsize=(6, 10))

# Plot for df1
for i, col in enumerate(aids_deaths.columns):
axs[0].plot(aids_deaths.index, aids_deaths[col], label=draw_labels[i], color=colors[i])
axs[0].set_title('HIV/AIDS')
axs[0].legend()
axs[0].axvline(x=2015, color='gray', linestyle='--')

# Plot for df2
for i, col in enumerate(tb_deaths.columns):
axs[1].plot(tb_deaths.index, tb_deaths[col], color=colors[i])
axs[1].set_title('TB')
axs[1].axvline(x=2015, color='gray', linestyle='--')

# Plot for df3
for i, col in enumerate(malaria_deaths.columns):
axs[2].plot(malaria_deaths.index, malaria_deaths[col], color=colors[i])
axs[2].set_title('Malaria')
axs[2].axvline(x=2015, color='gray', linestyle='--')

for ax in axs:
ax.set_xlabel('Years')
ax.set_ylabel('Number deaths')

plt.tight_layout()
plt.show()

15 changes: 12 additions & 3 deletions src/scripts/malaria/analysis_malaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
resourcefilepath = Path("./resources")

start_date = Date(2010, 1, 1)
end_date = Date(2016, 1, 1)
popsize = 300
end_date = Date(2014, 1, 1)
popsize = 100


# set up the log config
Expand Down Expand Up @@ -84,6 +84,15 @@
)
)

# update parameters
sim.modules["Hiv"].parameters["do_scaleup"] = True
sim.modules["Tb"].parameters["do_scaleup"] = True
sim.modules["Malaria"].parameters["do_scaleup"] = True
sim.modules["Hiv"].parameters["scaleup_start"] = 2
sim.modules["Tb"].parameters["scaleup_start"] = 2
sim.modules["Malaria"].parameters["scaleup_start"] = 2


# Run the simulation and flush the logger
sim.make_initial_population(n=popsize)
sim.simulate(end_date=end_date)
Expand All @@ -97,5 +106,5 @@
pickle.dump(dict(output), f, pickle.HIGHEST_PROTOCOL)

# load the results
with open(outputpath / "default_run.pickle", "rb") as f:
with open(outputpath / "malaria_run.pickle", "rb") as f:
output = pickle.load(f)
Loading