From b90787718bf4df6c15fb0968112f011f260e95b1 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 8 Aug 2024 02:39:29 -0400 Subject: [PATCH 1/8] add more labels for tthe to gdp plots --- ogcore/constants.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ogcore/constants.py b/ogcore/constants.py index 877de6da8..f5298b1f9 100644 --- a/ogcore/constants.py +++ b/ogcore/constants.py @@ -4,7 +4,7 @@ BASELINE_DIR = "OUTPUT_BASELINE" # Default year for model runs -DEFAULT_START_YEAR = 2021 +DEFAULT_START_YEAR = 2025 VAR_LABELS = { @@ -83,6 +83,9 @@ } ToGDP_LABELS = { + "Y": "GDP-to-GDP (=1 ;-))", + "B": "Savings-to-GDP ($B_{t}/Y_t$)", + "C": "Consumption-to-GDP ($C_{t}/Y_t$)", "D": "Debt-to-GDP ($D_{t}/Y_t$)", "D_d": "Domestically-owned Debt-to-GDP ($D^d_{t}/Y_t$)", "D_f": "Foreign-owned Debt-to-GDP ($D^f_{t}/Y_t$)", @@ -90,9 +93,25 @@ "K": "Capital-Output Ratio ($K_{t}/Y_t$)", "K_d": "Domestically-owned Capital-Output Ratio ($K^d_{t}/Y_t$)", "K_f": "Foreign-owned Capital-Output Ratio ($K^f_{t}/Y_t$)", + "K_g": "Infrastructure-Output Ratio ($K^g_{t}/Y_t$)", "C": "Consumption-Output Ratio ($C_{t}/Y_t$)", "I": "Investment-Output Ratio ($I_{t}/Y_t$)", + "I_total": "Investment-Output Ratio ($I_{t}/Y_t$)", + "I_d": "Domestic Investment-Output Ratio ($I^d_{t}/Y_t$)", + "I_g": "Infrastructure Investment-Output Ratio ($I^g_{t}/Y_t$)", "total_tax_revenue": "Tax Revenue-to-GDP ($REV_{t}/Y_t$)", + "TR": "Transfer Spending-to-GDP ($TR_{t}/Y_t$)", + "BQ": "Bequests-to-GDP ($BQ_{t}/Y_t$)", + "total_tax_revenue": "Tax Revenue-to-GDP ($Revenue_{t}/Y_t$)", + "business_tax_revenue": "Corporate Tax Revenue-to-GDP", + "iit_revenue": "Personal Income Tax Revenue-to-GDP", + "iit_payroll_revenue": "Personal Income + Payroll Tax Revenue-to-GDP", + "payroll_tax_revenue": "Payroll Tax Revenue-to-GDP", + "bequest_tax_revenue": "Bequest Tax Revenue-to-GDP", + "wealth_tax_revenue": "Wealth Tax Revenue-to-GDP", + "cons_tax_revenue": "Consumption Tax Revenue-to-GDP", + "agg_pension_outlays": "Pension Outlays-to-GDP ($Pensions_{t}/Y_t$)", + "UBI_path": "UBI Outlays-to-GDP ($UBI_{t}/Y_t$)", } GROUP_LABELS = { From 4e8b4407a7d1e8ff355c1e7de301f10c4308f080 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 8 Aug 2024 02:42:42 -0400 Subject: [PATCH 2/8] ensure variable passed in variable label list --- ogcore/output_plots.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ogcore/output_plots.py b/ogcore/output_plots.py index 50a5a7094..ba0a362bf 100644 --- a/ogcore/output_plots.py +++ b/ogcore/output_plots.py @@ -76,6 +76,7 @@ def plot_aggregates( assert reform_tpi is not None fig1, ax1 = plt.subplots() for i, v in enumerate(var_list): + assert v in VAR_LABELS.keys() #TODO provide warning message here if plot_type == "pct_diff": if v in ["r_gov", "r", "r_p"]: # Compute just percentage point changes for rates @@ -237,6 +238,7 @@ def plot_industry_aggregates( assert reform_tpi is not None fig1, ax1 = plt.subplots() for i, v in enumerate(var_list): + assert v in VAR_LABELS.keys() #TODO provide warning message here if len(var_list) == 1: var_label = "" else: @@ -449,6 +451,7 @@ def plot_gdp_ratio( start_index = start_year - base_params.start_year fig1, ax1 = plt.subplots() for i, v in enumerate(var_list): + assert v in ToGDP_LABELS.keys() #TODO provide warning message here if plot_type == "levels": plot_var_base = ( base_tpi[v][: base_params.T] / base_tpi["Y"][: base_params.T] From c5d086b5fea2a46e642901ef84c3bf80988e7c96 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 8 Aug 2024 02:50:16 -0400 Subject: [PATCH 3/8] provide no python arg --- ogcore/pensions.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ogcore/pensions.py b/ogcore/pensions.py index 41dbd11d4..35b28cadf 100644 --- a/ogcore/pensions.py +++ b/ogcore/pensions.py @@ -712,7 +712,7 @@ def delta_ret(r, Y, p): return delta_ret -@numba.jit +@numba.jit(nopython=True) def deriv_DB_loop( w, e, S, S_ret, per_rmn, avg_earn_num_years, alpha_db, yr_contr ): @@ -744,7 +744,7 @@ def deriv_DB_loop( return d_theta -@numba.jit +@numba.jit(nopython=True) def deriv_PS_loop(w, e, S, S_ret, per_rmn, d_theta, vpoint, factor): """ Change in points system pension benefits for another unit of @@ -776,7 +776,7 @@ def deriv_PS_loop(w, e, S, S_ret, per_rmn, d_theta, vpoint, factor): return d_theta -@numba.jit +@numba.jit(nopython=True) def deriv_NDC_loop( w, e, per_rmn, S, S_ret, tau_p, g_ndc_value, delta_ret_value, d_theta ): @@ -813,7 +813,7 @@ def deriv_NDC_loop( return d_theta -@numba.jit +@numba.jit(nopython=True) def delta_ret_loop(S, S_ret, surv_rates, g_dir_value, dir_delta_s): """ Compute conversion coefficient for the NDC pension amount @@ -842,7 +842,7 @@ def delta_ret_loop(S, S_ret, surv_rates, g_dir_value, dir_delta_s): return dir_delta -@numba.jit +@numba.jit(nopython=True) def PS_1dim_loop(w, e, n, S_ret, S, g_y, vpoint, factor, L_inc_avg_s, PS): """ Calculate public pension from a points system. @@ -876,7 +876,7 @@ def PS_1dim_loop(w, e, n, S_ret, S, g_y, vpoint, factor, L_inc_avg_s, PS): return PS -@numba.jit +@numba.jit(nopython=True) def PS_2dim_loop(w, e, n, S_ret, S, J, g_y, vpoint, factor, L_inc_avg_sj, PS): """ Calculate public pension from a points system. @@ -912,7 +912,7 @@ def PS_2dim_loop(w, e, n, S_ret, S, J, g_y, vpoint, factor, L_inc_avg_sj, PS): return PS -@numba.jit +@numba.jit(nopython=True) def DB_1dim_loop( w, e, @@ -962,7 +962,7 @@ def DB_1dim_loop( return DB -@numba.jit +@numba.jit(nopython=True) def DB_2dim_loop( w, e, @@ -1010,7 +1010,7 @@ def DB_2dim_loop( return DB -@numba.jit +@numba.jit(nopython=True) def NDC_1dim_loop(w, e, n, S_ret, S, g_y, tau_p, g_ndc, delta_ret, NDC_s, NDC): """ Calculate public pension from a notional defined contribution @@ -1046,7 +1046,7 @@ def NDC_1dim_loop(w, e, n, S_ret, S, g_y, tau_p, g_ndc, delta_ret, NDC_s, NDC): return NDC -@numba.jit +@numba.jit(nopython=True) def NDC_2dim_loop( w, e, n, S_ret, S, g_y, tau_p, g_ndc, delta_ret, NDC_sj, NDC ): From 8eccd44cafaf71840bbec38d231f94e9857ea414 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 8 Aug 2024 02:50:27 -0400 Subject: [PATCH 4/8] allow for markdown table --- ogcore/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ogcore/utils.py b/ogcore/utils.py index 1bde6c585..a92b69eba 100644 --- a/ogcore/utils.py +++ b/ogcore/utils.py @@ -401,7 +401,7 @@ def save_return_table(table_df, output_type, path, precision=2): Args: table_df (Pandas DataFrame): table output_type (string): specifies the type of file to save - table to: 'csv', 'tex', 'excel', 'json' + table to: 'csv', 'tex', 'excel', 'json', 'md' path (string): specifies path to save file with table to precision (integer): number of significant digits to print. Defaults to 0. @@ -433,6 +433,8 @@ def save_return_table(table_df, output_type, path, precision=2): table_df.to_csv(path_or_buf=path, index=False, na_rep="") elif output_type == "json": table_df.to_json(path_or_buf=path, double_precision=precision) + elif output_type == "md": + table_df.to_markdown(path_or_buf=path, double_precision=precision) elif output_type == "excel": table_df.to_excel(excel_writer=path, index=False, na_rep="") else: From 02f1246c23a10bc76b0dcf1e18f5a6eb4b2f5b93 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 8 Aug 2024 03:01:59 -0400 Subject: [PATCH 5/8] more informative note in parameter table: --- ogcore/parameter_tables.py | 2 +- ogcore/utils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ogcore/parameter_tables.py b/ogcore/parameter_tables.py index b567dc90a..4e9a392cd 100644 --- a/ogcore/parameter_tables.py +++ b/ogcore/parameter_tables.py @@ -194,7 +194,7 @@ def param_table(p, table_format="tex", path=None): value = getattr(p, k) if hasattr(value, "__len__") & ~isinstance(value, str): if value.ndim > 1: - report = "See elsewhere" + report = "Too large to report here, see default parameters JSON" else: report = ( "[" diff --git a/ogcore/utils.py b/ogcore/utils.py index a92b69eba..14ac43305 100644 --- a/ogcore/utils.py +++ b/ogcore/utils.py @@ -433,8 +433,8 @@ def save_return_table(table_df, output_type, path, precision=2): table_df.to_csv(path_or_buf=path, index=False, na_rep="") elif output_type == "json": table_df.to_json(path_or_buf=path, double_precision=precision) - elif output_type == "md": - table_df.to_markdown(path_or_buf=path, double_precision=precision) + # elif output_type == "md": # TODO: figure out how to save md to disk + # table_df.to_markdown(path_or_buf=path, double_precision=precision) elif output_type == "excel": table_df.to_excel(excel_writer=path, index=False, na_rep="") else: From b5c2a05fabafb714642935b2f4b2bfbd5377c556 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 8 Aug 2024 11:12:31 -0400 Subject: [PATCH 6/8] add assertion statement --- ogcore/output_plots.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ogcore/output_plots.py b/ogcore/output_plots.py index ba0a362bf..99b43b45a 100644 --- a/ogcore/output_plots.py +++ b/ogcore/output_plots.py @@ -76,7 +76,7 @@ def plot_aggregates( assert reform_tpi is not None fig1, ax1 = plt.subplots() for i, v in enumerate(var_list): - assert v in VAR_LABELS.keys() #TODO provide warning message here + assert v in VAR_LABELS.keys(), "{} is not in the list of variable labels".format(v) if plot_type == "pct_diff": if v in ["r_gov", "r", "r_p"]: # Compute just percentage point changes for rates @@ -238,7 +238,7 @@ def plot_industry_aggregates( assert reform_tpi is not None fig1, ax1 = plt.subplots() for i, v in enumerate(var_list): - assert v in VAR_LABELS.keys() #TODO provide warning message here + assert v in VAR_LABELS.keys(), "{} is not in the list of variable labels".format(v) if len(var_list) == 1: var_label = "" else: @@ -451,7 +451,7 @@ def plot_gdp_ratio( start_index = start_year - base_params.start_year fig1, ax1 = plt.subplots() for i, v in enumerate(var_list): - assert v in ToGDP_LABELS.keys() #TODO provide warning message here + assert v in ToGDP_LABELS.keys(), "{} is not in the list of variable labels".format(v) if plot_type == "levels": plot_var_base = ( base_tpi[v][: base_params.T] / base_tpi["Y"][: base_params.T] From 402a0c3f3275c2d62379395a2a630ff07c6fdf27 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 8 Aug 2024 11:12:50 -0400 Subject: [PATCH 7/8] format --- ogcore/output_plots.py | 12 +++++++++--- ogcore/parameter_tables.py | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ogcore/output_plots.py b/ogcore/output_plots.py index 99b43b45a..fdc07a224 100644 --- a/ogcore/output_plots.py +++ b/ogcore/output_plots.py @@ -76,7 +76,9 @@ def plot_aggregates( assert reform_tpi is not None fig1, ax1 = plt.subplots() for i, v in enumerate(var_list): - assert v in VAR_LABELS.keys(), "{} is not in the list of variable labels".format(v) + assert ( + v in VAR_LABELS.keys() + ), "{} is not in the list of variable labels".format(v) if plot_type == "pct_diff": if v in ["r_gov", "r", "r_p"]: # Compute just percentage point changes for rates @@ -238,7 +240,9 @@ def plot_industry_aggregates( assert reform_tpi is not None fig1, ax1 = plt.subplots() for i, v in enumerate(var_list): - assert v in VAR_LABELS.keys(), "{} is not in the list of variable labels".format(v) + assert ( + v in VAR_LABELS.keys() + ), "{} is not in the list of variable labels".format(v) if len(var_list) == 1: var_label = "" else: @@ -451,7 +455,9 @@ def plot_gdp_ratio( start_index = start_year - base_params.start_year fig1, ax1 = plt.subplots() for i, v in enumerate(var_list): - assert v in ToGDP_LABELS.keys(), "{} is not in the list of variable labels".format(v) + assert ( + v in ToGDP_LABELS.keys() + ), "{} is not in the list of variable labels".format(v) if plot_type == "levels": plot_var_base = ( base_tpi[v][: base_params.T] / base_tpi["Y"][: base_params.T] diff --git a/ogcore/parameter_tables.py b/ogcore/parameter_tables.py index 4e9a392cd..dbaa75d2d 100644 --- a/ogcore/parameter_tables.py +++ b/ogcore/parameter_tables.py @@ -194,7 +194,9 @@ def param_table(p, table_format="tex", path=None): value = getattr(p, k) if hasattr(value, "__len__") & ~isinstance(value, str): if value.ndim > 1: - report = "Too large to report here, see default parameters JSON" + report = ( + "Too large to report here, see default parameters JSON" + ) else: report = ( "[" From 79dcd4675d0a88b0dd9c02e9ba6a323ad6571c20 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Thu, 8 Aug 2024 12:29:30 -0400 Subject: [PATCH 8/8] markdown table --- ogcore/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ogcore/utils.py b/ogcore/utils.py index 14ac43305..25896a551 100644 --- a/ogcore/utils.py +++ b/ogcore/utils.py @@ -433,8 +433,10 @@ def save_return_table(table_df, output_type, path, precision=2): table_df.to_csv(path_or_buf=path, index=False, na_rep="") elif output_type == "json": table_df.to_json(path_or_buf=path, double_precision=precision) - # elif output_type == "md": # TODO: figure out how to save md to disk - # table_df.to_markdown(path_or_buf=path, double_precision=precision) + elif output_type == "md": + table_df.to_markdown( + buf=path, index=False, floatfmt=".{}f".format(precision) + ) elif output_type == "excel": table_df.to_excel(excel_writer=path, index=False, na_rep="") else: