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

Mnjowe/test running kenya analyses #1578

Closed
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
4 changes: 2 additions & 2 deletions resources/contraception/ResourceFile_Contraception.xlsx
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
4 changes: 2 additions & 2 deletions resources/demography/ResourceFile_Pop_Frac_Births_Male.csv
Git LFS file not shown
4 changes: 2 additions & 2 deletions resources/demography/ResourceFile_Population_2010.csv
Git LFS file not shown
3 changes: 3 additions & 0 deletions resources/demography/ResourceFile_Population_nuhdss_2015.csv
Git LFS file not shown
53 changes: 53 additions & 0 deletions src/scripts/contraception/kenya/analyses_contraception_kenya.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
a contraception analyses script for kenya
"""
import datetime
from pathlib import Path

from tlo import Date, Simulation, logging
from tlo.analysis.utils import parse_log_file
from tlo.methods import (
demography_nuhdss, contraception_nuhdss, demography
)

# The outputs' path. This is where will output be stored
outputpath = Path("./outputs/")

# date-stamp to label log files and any other outputs
datestamp = datetime.date.today().strftime("__%Y_%m_%d")

# Path to all resource files
resourcefilepath = Path("./resources")

# start and end dates of simulation.
start_date = Date(2010, 1, 1)
end_date = Date(2020, 1, 1)
# population size
popsize = 2000

# a file that will store all logs. Here if you want you include logs to specific files you should declare their
# logging level as logging.INFO. see below otherwise the logs for that particular module won't show in log file
log_config = {
'filename': 'kenya_contraception_analyses',
'directory': outputpath/'kenya_contraception_analyses',
'custom_levels': {"*": logging.WARNING,
"tlo.methods.demography_nuhdss": logging.INFO
}
}

# Establish the simulation object. assign to simulation log configuration above if you want log file created
sim = Simulation(start_date=start_date, seed=0, log_config=log_config)

# Register the appropriate modules
sim.register(
demography_nuhdss.Demography(resourcefilepath=resourcefilepath)
)

sim.make_initial_population(n=popsize)
sim.simulate(end_date=end_date)

# read results
output = parse_log_file(sim.log_filepath)
print(f"the outputs are {output['tlo.methods.demography_nuhdss']}")

# following the parsed outputs above you can proceed to extracting data and do your analyses
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""
This file defines a batch run to get sims results to be used by the analysis_contraception_plot_table.
Run on the remote batch system using:
```tlo batch-submit src/scripts/contraception/kenya/scenarios/run_analysis_contraception_no_diseases.py```
or locally using:
```tlo scenario-run src/scripts/contraception/kenya/scenarios/run_analysis_contraception_no_diseases.py```


SCENARIO SETTINGS
-----------------
used modules:
* Demography
* HealthSystem
- cons_availability="all", i.e. all consumables are assumed to be always available,
* Contraception, for which SimplifiedPregnancyAndLabour is used
- use_interventions=False/True according to what we need (False => without interventions,
True => interventions since 2023; it needs to be set in the ResourceFile_ContraceptionParams.csv)
* DummyHivModule (a supporting module required by Contraception module)

logging above warning level:
* contraception:
- INFO if only analysis_all_calibration or figs but not the table from analysis_contraception_plot_table required,
- DEBUG if tabel from analysis_contraception_plot_table required.
* demography: INFO.
NB. For analysis_all_calibration this is enough only if analysis_hsi_descriptions are not required, and the analysis
needs to be changed accordingly to run properly. We use an adjusted analysis_all_calibration script, stored in the
EvaJ/contraception_2023-02_inclPR807/AnalysisAllCalib_Contraception branch.


CONTRACEPTION PAPER (Tim C et al. 2023):
---------------------------------------
- 1 draw & 1 run/per draw with 250K initial_population_size
- use_interventions=False/True for simulation without/with interventions,
- for analysis_all_calibration adjusted in the branch
EvaJ/contraception_2023-02_inclPR807/AnalysisAllCalib_Contraception with the analysis_hsi_descriptions excluded (Fig 2):
2010-2099 simulated with contraception logging at the level INFO (a job to simulate that many years with DEBUG
logging fails)
- for analysis_contraception_plot_table (Fig 3, Fig 4, Tab 4, and Fig A6.1):
2010-2050 simulated with contraception logging at the level DEBUG
"""

from tlo import Date, logging
from tlo.methods import demography, contraception_nuhdss, demography_nuhdss
from tlo.scenario import BaseScenario


class RunAnalysisCo(BaseScenario):
def __init__(self):
super().__init__(
seed=0,
start_date=Date(2010, 1, 1),
end_date=Date(2020, 12, 31),
initial_population_size=1000, # selected size for the Tim C at al. 2023 paper: 250K
number_of_draws=1, # <- one scenario
runs_per_draw=1, # <- repeated this many times
)

def log_configuration(self):
return {
'filename': 'run_analysis_contraception_no_diseases', # <- (specified only for local running)
'directory': './outputs', # <- (specified only for local running)
'custom_levels': {
'*': logging.WARNING,
"tlo.methods.demography_nuhdss": logging.INFO
}
}

def modules(self):
return [
# Core Modules
demography_nuhdss.Demography(resourcefilepath=self.resources)
]

def draw_parameters(self, draw_number, rng):
# Using default parameters in all cases
return


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

scenario_run([__file__])
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"""

from tlo import Date, logging
from tlo.methods import contraception, demography, healthsystem, hiv
from tlo.methods import contraception, demography, healthsystem, hiv, demography_nuhdss
from tlo.scenario import BaseScenario


Expand All @@ -50,7 +50,7 @@ def __init__(self):
seed=0,
start_date=Date(2010, 1, 1),
end_date=Date(2099, 12, 31),
initial_population_size=250_000, # selected size for the Tim C at al. 2023 paper: 250K
initial_population_size=1000, # selected size for the Tim C at al. 2023 paper: 250K
number_of_draws=1, # <- one scenario
runs_per_draw=1, # <- repeated this many times
)
Expand All @@ -69,19 +69,20 @@ def log_configuration(self):
def modules(self):
return [
# Core Modules
demography.Demography(resourcefilepath=self.resources),
healthsystem.HealthSystem(resourcefilepath=self.resources,
cons_availability="all"),
#demography.Demography(resourcefilepath=self.resources),
Demography_Nuhdss.Demography(resourcefilepath=self.resources),
# healthsystem.HealthSystem(resourcefilepath=self.resources,
# cons_availability="all"),

# - Contraception and replacement for Labour etc.
contraception.Contraception(resourcefilepath=self.resources,
use_healthsystem=True # default: True <-- using HealthSystem
# if True initiation and switches to contraception require an HSI
),
contraception.SimplifiedPregnancyAndLabour(),

# - Supporting Module required by Contraception
hiv.DummyHivModule(),
# contraception.Contraception(resourcefilepath=self.resources,
# use_healthsystem=False # default: True <-- using HealthSystem
# # if True initiation and switches to contraception require an HSI
# ),
# contraception.SimplifiedPregnancyAndLabour(),

# # - Supporting Module required by Contraception
# hiv.DummyHivModule(),
]

def draw_parameters(self, draw_number, rng):
Expand Down
Loading