Skip to content

Commit 566fbb1

Browse files
committed
New databook
1 parent 41b3586 commit 566fbb1

File tree

4 files changed

+128
-35
lines changed

4 files changed

+128
-35
lines changed

inputs/en/demo_national_input.xlsx

2.73 KB
Binary file not shown.

nutrition/data.py

+97-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import pandas as pd
23
from scipy.stats import norm
34
import pandas
45
import openpyxl
@@ -144,6 +145,7 @@ def __init__(self, spreadsheet, calcscache):
144145
self.get_time_trends()
145146
self.get_incidences()
146147
self.get_economic_cost()
148+
self.get_lifetable()
147149

148150
self.impacted_pop = None
149151
self.prog_areas = sc.odict()
@@ -347,13 +349,101 @@ def get_time_trends(self):
347349

348350
@translate
349351
def get_economic_cost(self):
350-
econo_cost = utils.read_sheet(self._spreadsheet, _("Economic loss"), cols=[0], dropna=False)
351-
self.cost_wasting = econo_cost.loc[_("Child wasting episode")].values[0]
352-
self.cost_stunting = econo_cost.loc[_("Child turning age 5 stunted (over lifetime)")].values[0]
353-
self.cost_child_death = econo_cost.loc[_("Child death")].values[0]
354-
self.cost_pw_death = econo_cost.loc[_("Maternal death")].values[0]
355-
self.cost_child_anaemic = econo_cost.loc[_("Anaemic child (per year)")].values[0]
356-
self.cost_pw_anaemic = econo_cost.loc[_("Anaemic pregnant woman (per pregnancy)")].values[0]
352+
econo_inputs = utils.read_sheet(self._spreadsheet, _("Economic inputs"), cols=[0], dropna=False)
353+
life_exp = econo_inputs.loc[_("Life expectancy at birth")].values[0]
354+
gdp_growth = econo_inputs.loc[_("GDP growth rate")].values[0]
355+
gdp_pc = econo_inputs.loc[_("Life expectancy at birth")].values[0]
356+
per_earn_realised = econo_inputs.loc[_("Percentage of lifetime earning actually realized")].values[0]
357+
age_end_prod = econo_inputs.loc[_("Age for end of productivity")].values[0]
358+
age_sta_prod = econo_inputs.loc[_("Age start productivity")].values[0]
359+
fem_lb_part = econo_inputs.loc[_("Female labor force participation")].values[0]
360+
prop_pw_benef = econo_inputs.loc[_("Proportion of pregnancy to apply benefits to")].values[0]
361+
inc_iq_bf = econo_inputs.loc[_("Increase in IQ due to early breastfeeding")].values[0]
362+
inc_ear_iq = econo_inputs.loc[_("Increase in earnings due to increase in one IQ pt")].values[0]
363+
lab_share_gdp = econo_inputs.loc[_("Labor share of GDP")].values[0]
364+
low_earn_stunted = econo_inputs.loc[_("Percentage of lower lifetime earning of a stunted individual")].values[0]
365+
produc_gain_anemia = econo_inputs.loc[_("Gains in productivity from averted childhood anemia")].values[0]
366+
produc_gain_lbw = econo_inputs.loc[_("Productivity gains due to averted low birth weight")].values[0]
367+
wage_share_manual = econo_inputs.loc[_("Wage Share in GDP for manual occupations")].values[0]
368+
produc_light_lab = econo_inputs.loc[_("Gains productivity in light labour")].values[0]
369+
blue_col_share = econo_inputs.loc[_("Blue-Collar Share employment in total employment")].values[0]
370+
heavy_manu_lab = econo_inputs.loc[_("Wage Share of Heavy manual labor")].values[0]
371+
produc_heavy_lab = econo_inputs.loc[_("Gains in productivity in heavy labor")].values[0][0]
372+
373+
econo_inputs = utils.read_sheet(self._spreadsheet, _("Economic inputs"), cols=[0], skiprows=22)
374+
375+
num_people = econo_inputs.loc[_("Number of people")].values.tolist()
376+
377+
self.econ_inputs = {"Life expectancy at birth": life_exp,
378+
"GDP growth rate": gdp_growth,
379+
"GDP per capita": gdp_pc ,
380+
"Percent of lifetime earning actually realized": per_earn_realised,
381+
"Productivity year end": age_end_prod,
382+
"Productivity year start": age_sta_prod,
383+
"Female labor force participation": fem_lb_part,
384+
"Proportion of pregnancy to apply benefits to": prop_pw_benef,
385+
"Percentage of pregnant women 15-19 years": self.pw_agedist[0],
386+
"Percentage of pregnant women 20-29 years": self.pw_agedist[1],
387+
"Percentage of pregnant women 30-39 years": self.pw_agedist[2],
388+
"Percentage of pregnant women 40-49 years": self.pw_agedist[3],
389+
"Increase in IQ due to EBF": inc_iq_bf,
390+
"Rate of increase in earnings from IQ": inc_ear_iq,
391+
"Labor share of GDP": lab_share_gdp,
392+
"Percent lower lifetime earning of a stunted": low_earn_stunted,
393+
"Productivity gain from averting child anemia": produc_gain_anemia,
394+
"Productivity gain from averting LBW": produc_gain_lbw,
395+
"Wage Share in GDP for manual occupations": wage_share_manual,
396+
"Gains productivity in light labour": produc_light_lab,
397+
"Blue-Collar Share employment in total employment": blue_col_share,
398+
"Wage Share of Heavy manual labor": heavy_manu_lab,
399+
"Gains in productivity in heavy labor": produc_heavy_lab,
400+
"Number of people per 100,000": num_people}
401+
402+
def get_lifetable(self):
403+
all_ages = [a for a in range(5,66)]
404+
age_cats = ["5-9 years", "10-14 years", "15-19 years", "20-24 years", "25-29 years",
405+
"30-34 years", "35-39 years", "40-44 years", "45-49 years", "50-54 years",
406+
"55-59 years", "60-64 years","65-69 years"]
407+
408+
number_list = self.econ_inputs["Number of people per 100,000"]
409+
people_number = {age_cat: 0 for age_cat in age_cats}
410+
for c, cat in enumerate(age_cats):
411+
people_number[cat] = number_list[c]
412+
413+
Px = {cat: 0 for cat in age_cats}
414+
415+
proportion_left_since_age_5 = []
416+
proportion_left_since_age_15 = np.zeros(len(all_ages))
417+
proportion_left_since_age_25 = np.zeros(len(all_ages))
418+
proportion_left_since_age_35 = np.zeros(len(all_ages))
419+
proportion_left_since_age_45 = np.zeros(len(all_ages))
420+
421+
for cat in age_cats:
422+
Px[cat] = people_number[cat] / people_number["5-9 years"]
423+
424+
for i in range(0, len(age_cats) - 1):
425+
this_interp = np.linspace(Px[age_cats[i]],Px[age_cats[i + 1]],6)[:5]
426+
proportion_left_since_age_5.extend(this_interp)
427+
428+
proportion_left_since_age_5.append(Px["65-69 years"])
429+
430+
for i in range(10, len(all_ages)):
431+
proportion_left_since_age_15[i] = proportion_left_since_age_5[i] / Px["15-19 years"]
432+
for i in range(20, len(all_ages)):
433+
proportion_left_since_age_25[i] = proportion_left_since_age_5[i] / Px["25-29 years"]
434+
for i in range(30, len(all_ages)):
435+
proportion_left_since_age_35[i] = proportion_left_since_age_5[i] / Px["35-39 years"]
436+
for i in range(40, len(all_ages)):
437+
proportion_left_since_age_45[i] = proportion_left_since_age_5[i] / Px["45-49 years"]
438+
439+
self.life_table = pd.DataFrame({
440+
"Age": all_ages,
441+
"Proportion left since age 5": proportion_left_since_age_5,
442+
"Proportion left since age 15": proportion_left_since_age_15,
443+
"Proportion left since age 25": proportion_left_since_age_25,
444+
"Proportion left since age 35": proportion_left_since_age_35,
445+
"Proportion left since age 45": proportion_left_since_age_45
446+
})
357447

358448
@translate
359449
def get_incidences(self):

nutrition/economic.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import numpy as np
2+
from .data import Dataset
3+
from .results import reduce_results

tests/testscenarios.py

+28-28
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,43 @@
1717
p = nu.Project("eg")
1818
p.load_data("demo", "national", name="eg")
1919

20-
### define custom scenarios
21-
kwargs1 = {"name": "Treat SAM 100%", "model_name": "eg", "scen_type": "coverage", "progvals": sc.odict({"Treatment of SAM": [0.9, 0.5, 0.8]}), "growth": "fixed coverage", "enforce_constraints_year": 1}
20+
# ### define custom scenarios
21+
# kwargs1 = {"name": "Treat SAM 100%", "model_name": "eg", "scen_type": "coverage", "progvals": sc.odict({"Treatment of SAM": [0.9, 0.5, 0.8]}), "growth": "fixed coverage", "enforce_constraints_year": 1}
2222

23-
kwargs2 = sc.dcp(kwargs1)
24-
kwargs2.update({"name": "IYCF 1 100%", "progvals": sc.odict({"Small quantity lipid-based nutrition supplements": [1]})})
23+
# kwargs2 = sc.dcp(kwargs1)
24+
# kwargs2.update({"name": "IYCF 1 100%", "progvals": sc.odict({"Small quantity lipid-based nutrition supplements": [1]})})
2525

26-
kwargs3 = {"name": "IYCF at $10 mil", "model_name": "eg", "scen_type": "budget", "progvals": sc.odict({"IYCF 1": [1e8, 2e8, 1.5e8, 2.5e8], "IPTp": [2e7, 2.8e7, 2.8e7, 4.25e7]}), "growth": "fixed coverage", "enforce_constraints_year": 1}
26+
# kwargs3 = {"name": "IYCF at $10 mil", "model_name": "eg", "scen_type": "budget", "progvals": sc.odict({"IYCF 1": [1e8, 2e8, 1.5e8, 2.5e8], "IPTp": [2e7, 2.8e7, 2.8e7, 4.25e7]}), "growth": "fixed coverage", "enforce_constraints_year": 1}
2727

28-
### testing FE bugs
29-
kwargs4 = {"name": "FE check 1", "model_name": "eg", "scen_type": "budget", "progvals": sc.odict({u"IFA fortification of maize": [2000000], u"IPTp": [2000000], u"Iron and iodine fortification of salt": [], u"IYCF 1": [], u"Long-lasting insecticide-treated bednets": [], u"Micronutrient powders": [], u"Multiple micronutrient supplementation": [], u"Vitamin A supplementation": [], u"Zinc for treatment + ORS": []})}
28+
# ### testing FE bugs
29+
# kwargs4 = {"name": "FE check 1", "model_name": "eg", "scen_type": "budget", "progvals": sc.odict({u"IFA fortification of maize": [2000000], u"IPTp": [2000000], u"Iron and iodine fortification of salt": [], u"IYCF 1": [], u"Long-lasting insecticide-treated bednets": [], u"Micronutrient powders": [], u"Multiple micronutrient supplementation": [], u"Vitamin A supplementation": [], u"Zinc for treatment + ORS": []})}
3030

31-
kwargs5 = {"name": "FE check 2", "model_name": "eg", "scen_type": "budget", "progvals": sc.odict({u"IFA fortification of maize": [2000000], u"IPTp": [2000000], u"Iron and iodine fortification of salt": [], u"IYCF 1": [], u"Long-lasting insecticide-treated bednets": [0], u"Micronutrient powders": [], u"Multiple micronutrient supplementation": [], u"Vitamin A supplementation": [], u"Zinc for treatment + ORS": []})}
31+
# kwargs5 = {"name": "FE check 2", "model_name": "eg", "scen_type": "budget", "progvals": sc.odict({u"IFA fortification of maize": [2000000], u"IPTp": [2000000], u"Iron and iodine fortification of salt": [], u"IYCF 1": [], u"Long-lasting insecticide-treated bednets": [0], u"Micronutrient powders": [], u"Multiple micronutrient supplementation": [], u"Vitamin A supplementation": [], u"Zinc for treatment + ORS": []})}
3232

33-
kwargs5 = {"name": "Check WASH", "model_name": "eg", "scen_type": "budget", "progvals": sc.odict({"WASH: Handwashing": [1e6]})}
33+
# kwargs5 = {"name": "Check WASH", "model_name": "eg", "scen_type": "budget", "progvals": sc.odict({"WASH: Handwashing": [1e6]})}
3434

35-
kwargs6 = {"name": "Check bednets", "model_name": "eg", "scen_type": "budget", "progvals": sc.odict({"Long-lasting insecticide-treated bednets": [0]})}
35+
# kwargs6 = {"name": "Check bednets", "model_name": "eg", "scen_type": "budget", "progvals": sc.odict({"Long-lasting insecticide-treated bednets": [0]})}
3636

37-
kwargs7 = {"name": "IYCF", "model_name": "eg", "scen_type": "coverage", "progvals": sc.odict({"IYCF 1": [0.6, 0.2, 0.5, 0.95, 0.8]}), "growth": "fixed coverage"}
37+
# kwargs7 = {"name": "IYCF", "model_name": "eg", "scen_type": "coverage", "progvals": sc.odict({"IYCF 1": [0.6, 0.2, 0.5, 0.95, 0.8]}), "growth": "fixed coverage"}
3838

39-
kwargs8 = {"name": "Treat SAM 100%", "model_name": "Maximize thrive", "mults": [1], "weights": sc.odict({"thrive": 1}), "prog_set": ["Vitamin A supplementation", "IYCF 1", "IFA fortification of maize", "Balanced energy-protein supplementation", "Public provision of complementary foods", "Iron and iodine fortification of salt"], "fix_curr": False, "add_funds": 0, "filter_progs": True}
39+
# kwargs8 = {"name": "Treat SAM 100%", "model_name": "Maximize thrive", "mults": [1], "weights": sc.odict({"thrive": 1}), "prog_set": ["Vitamin A supplementation", "IYCF 1", "IFA fortification of maize", "Balanced energy-protein supplementation", "Public provision of complementary foods", "Iron and iodine fortification of salt"], "fix_curr": False, "add_funds": 0, "filter_progs": True}
4040

41-
if __name__ == "__main__":
42-
# mod = p.models.keys()[0]
43-
# progs = p.models[mod].prog_info.programs.keys()
44-
# zero_budget_kwargs = {"name": 'Zero spending exc FP', "model_name": mod, "scen_type": "budget", "progvals": sc.odict([(prog, [0]) for prog in progs])}
45-
# inf_budget_kwargs = {"name": 'Infinite spending exc FP', "model_name": mod, "scen_type": "budget", "progvals": sc.odict([(prog, [0 if prog=='Family planning' else 9999999999]) for prog in progs])}
46-
# scen_list = nu.make_scens([zero_budget_kwargs, inf_budget_kwargs])
41+
# if __name__ == "__main__":
42+
# # mod = p.models.keys()[0]
43+
# # progs = p.models[mod].prog_info.programs.keys()
44+
# # zero_budget_kwargs = {"name": 'Zero spending exc FP', "model_name": mod, "scen_type": "budget", "progvals": sc.odict([(prog, [0]) for prog in progs])}
45+
# # inf_budget_kwargs = {"name": 'Infinite spending exc FP', "model_name": mod, "scen_type": "budget", "progvals": sc.odict([(prog, [0 if prog=='Family planning' else 9999999999]) for prog in progs])}
46+
# # scen_list = nu.make_scens([zero_budget_kwargs, inf_budget_kwargs])
4747

48-
scen_list = nu.make_scens([kwargs1, kwargs7, kwargs3, kwargs2])
49-
p.add_scens(scen_list)
48+
# scen_list = nu.make_scens([kwargs1, kwargs7, kwargs3, kwargs2])
49+
# p.add_scens(scen_list)
5050

51-
results = p.run_scens(n_samples=1)
51+
# results = p.run_scens(n_samples=1)
5252

53-
if doplot:
54-
p.plot()
55-
# costeff = p.get_costeff()
56-
# p.write_results("scen_results_test.xlsx")
57-
all_reduce = reduce_results(results)
58-
write_results(results=results, reduced_results=all_reduce, filename="scen_results_test.xlsx")
59-
p.save("test")
53+
# if doplot:
54+
# p.plot()
55+
# # costeff = p.get_costeff()
56+
# # p.write_results("scen_results_test.xlsx")
57+
# all_reduce = reduce_results(results)
58+
# write_results(results=results, reduced_results=all_reduce, filename="scen_results_test.xlsx")
59+
# p.save("test")

0 commit comments

Comments
 (0)