From f27dde14676e2f0a0f9562085a225e9e6f69ee92 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Fri, 17 May 2024 09:38:06 -0400 Subject: [PATCH] download data --- environment.yml | 2 +- ogzaf/calibrate.py | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index c70e623..0a81fbf 100644 --- a/environment.yml +++ b/environment.yml @@ -2,7 +2,7 @@ name: ogzaf-dev channels: - conda-forge dependencies: -- python>=3.7.7 +- python>=3.7.7, <3.12 - numpy - numba>=0.54 - scipy>=1.7.1 diff --git a/ogzaf/calibrate.py b/ogzaf/calibrate.py index 1956065..b514194 100644 --- a/ogzaf/calibrate.py +++ b/ogzaf/calibrate.py @@ -6,6 +6,8 @@ from ogcore.utils import safe_read_pickle, mkdirs import pkg_resources +CUR_DIR = os.path.dirname(os.path.realpath(__file__)) + class Calibration: """OG-ZAF calibration class""" @@ -103,14 +105,55 @@ def __init__( initial_data_year=p.start_year - 1, final_data_year=p.start_year, GraphDiag=False, + download_path=os.path.join(CUR_DIR, "data", "demographic"), ) # demographics for 80 period lives (needed for getting e below) + # read in data downloaded above: + fert_rates = np.genfromtxt( + os.path.join(CUR_DIR, "data", "demographic", "fert_rates.csv"), + delimiter=",", + ) + mort_rates = np.genfromtxt( + os.path.join(CUR_DIR, "data", "demographic", "mort_rates.csv"), + delimiter=",", + ) + infmort_rates = np.genfromtxt( + os.path.join( + CUR_DIR, "data", "demographic", "infmort_rates.csv" + ), + delimiter=",", + ) + pop_dist = np.genfromtxt( + os.path.join( + CUR_DIR, + "data", + "demographic", + "population_distribution.csv", + ), + delimiter=",", + ) + pre_pop_dist = np.genfromtxt( + os.path.join( + CUR_DIR, + "data", + "demographic", + "pre_period_population_distribution.csv", + ), + delimiter=",", + ) demog80 = demographics.get_pop_objs( 20, 80, p.T, 0, 99, + fert_rates=fert_rates, + mort_rates=mort_rates, + infmort_rates=infmort_rates, + imm_rates=None, + infer_pop=False, + pop_dist=pop_dist, + pre_pop_dist=pre_pop_dist, country_id="710", # UN code for ZAF initial_data_year=p.start_year - 1, final_data_year=p.start_year, @@ -257,7 +300,7 @@ def get_tax_function_parameters( ) if p.S != S_in_tax_params: print( - "Warning: There is a discrepency between the ages" + "Warning: There is a discrepancy between the ages" + " used in the model and those in the tax functions!!" ) # After printing warning, make it work by tiling