Skip to content

Commit

Permalink
Remove storage of incidence data as parameters in malaria.py to reduc…
Browse files Browse the repository at this point in the history
…e memory usage (#1545)

* removed logic storing incidence data as parameters (replaced with local variables) to prevent module from holding on to memory

* fix failing test

* remove worksheet with IRS/ITN coverage by year - superseded by district-level estimates

---------

Co-authored-by: tdm32 <t.mangal@imperial.ac.uk>
  • Loading branch information
joehcollins and tdm32 authored Dec 10, 2024
1 parent 92ed97a commit d150258
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
26 changes: 6 additions & 20 deletions src/tlo/methods/malaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,6 @@ def __init__(self, name=None, resourcefilepath=None):
}

PARAMETERS = {
'interv': Parameter(Types.REAL, 'data frame of intervention coverage by year'),
'clin_inc': Parameter(
Types.REAL,
'data frame of clinical incidence by age, district, intervention coverage',
),
'inf_inc': Parameter(
Types.REAL,
'data frame of infection incidence by age, district, intervention coverage',
),
'sev_inc': Parameter(
Types.REAL,
'data frame of severe case incidence by age, district, intervention coverage',
),
'itn_district': Parameter(
Types.REAL, 'data frame of ITN usage rates by district'
),
Expand Down Expand Up @@ -247,17 +234,16 @@ def read_parameters(self, data_folder):
p = self.parameters

# baseline characteristics
p['interv'] = workbook['interventions']
p['itn_district'] = workbook['MAP_ITNrates']
p['irs_district'] = workbook['MAP_IRSrates']

p['sev_symp_prob'] = workbook['severe_symptoms']
p['rdt_testing_rates'] = workbook['WHO_TestData2023']
p['highrisk_districts'] = workbook['highrisk_districts']

p['inf_inc'] = pd.read_csv(self.resourcefilepath / 'malaria' / 'ResourceFile_malaria_InfInc_expanded.csv')
p['clin_inc'] = pd.read_csv(self.resourcefilepath / 'malaria' / 'ResourceFile_malaria_ClinInc_expanded.csv')
p['sev_inc'] = pd.read_csv(self.resourcefilepath / 'malaria' / 'ResourceFile_malaria_SevInc_expanded.csv')
inf_inc_sheet = pd.read_csv(self.resourcefilepath / 'malaria' / 'ResourceFile_malaria_InfInc_expanded.csv')
clin_inc_sheet = pd.read_csv(self.resourcefilepath / 'malaria' / 'ResourceFile_malaria_ClinInc_expanded.csv')
sev_inc_sheet = pd.read_csv(self.resourcefilepath / 'malaria' / 'ResourceFile_malaria_SevInc_expanded.csv')

# load parameters for scale-up projections
p['scaleup_parameters'] = workbook["scaleup_parameters"]
Expand Down Expand Up @@ -296,13 +282,13 @@ def read_parameters(self, data_folder):
# ===============================================================================
# put the all incidence data into single table with month/admin/llin/irs index
# ===============================================================================
inf_inc = p['inf_inc'].set_index(['month', 'admin', 'llin', 'irs', 'age'])
inf_inc = inf_inc_sheet.set_index(['month', 'admin', 'llin', 'irs', 'age'])
inf_inc = inf_inc.loc[:, ['monthly_prob_inf']]

clin_inc = p['clin_inc'].set_index(['month', 'admin', 'llin', 'irs', 'age'])
clin_inc = clin_inc_sheet.set_index(['month', 'admin', 'llin', 'irs', 'age'])
clin_inc = clin_inc.loc[:, ['monthly_prob_clin']]

sev_inc = p['sev_inc'].set_index(['month', 'admin', 'llin', 'irs', 'age'])
sev_inc = sev_inc_sheet.set_index(['month', 'admin', 'llin', 'irs', 'age'])
sev_inc = sev_inc.loc[:, ['monthly_prob_sev']]

all_inc = pd.concat([inf_inc, clin_inc, sev_inc], axis=1)
Expand Down
7 changes: 3 additions & 4 deletions tests/test_malaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,18 +711,17 @@ def test_linear_model_for_clinical_malaria(sim):
# set perfect protection for IPTp against clinical malaria - no cases should occur
sim.modules['Malaria'].parameters['rr_clinical_malaria_iptp'] = 0

# set clinical incidence probability to very high value
sim.modules['Malaria'].parameters['clin_inc']['monthly_prob_clin'] = 0.99

# Run the simulation and flush the logger
sim.make_initial_population(n=10)
sim.make_initial_population(n=25)
# simulate for 0 days, just get everything set up (dxtests etc)
sim.simulate(end_date=sim.date + pd.DateOffset(days=0))

df = sim.population.props

# make the whole population infected with parasitaemia
# and therefore eligible for clinical/severe malaria poll
df.loc[df.is_alive, "district_of_residence"] = "Balaka" # put everyone in high-risk district
df.loc[df.is_alive, "district_num_of_residence"] = 28
df.loc[df.is_alive, "ma_is_infected"] = True
df.loc[df.is_alive, "ma_date_infected"] = sim.date
df.loc[df.is_alive, "ma_inf_type"] = "asym"
Expand Down

0 comments on commit d150258

Please sign in to comment.