def test_plot_aggregates_save_fig(tmpdir): path = os.path.join(tmpdir, 'test_plot.png') output_plots.plot_aggregates(base_tpi, base_params, plot_type='levels', path=path) img = mpimg.imread(path) assert isinstance(img, np.ndarray)
def test_plot_gdp_ratio_save_fig(tmpdir): path = os.path.join(tmpdir, 'test_plot.png') output_plots.plot_aggregates(base_tpi, base_params, reform_tpi=reform_tpi, reform_params=reform_params, path=path) img = mpimg.imread(path) assert isinstance(img, np.ndarray)
def test_plot_aggregates(base_tpi, base_params, reform_tpi, reform_parms, plot_type, vertical_line_years, plot_title): fig = output_plots.plot_aggregates(base_tpi, base_params, reform_tpi=reform_tpi, reform_params=reform_params, var_list=['Y', 'r'], plot_type=plot_type, num_years_to_plot=20, vertical_line_years=vertical_line_years, plot_title=plot_title) assert fig
def comp_output(base_params, base_ss, reform_params, reform_ss, time_path, base_tpi=None, reform_tpi=None, var='cssmat'): ''' Function to create output for the COMP platform ''' if time_path: table_title = 'Percentage Changes in Economic Aggregates Between' table_title += ' Baseline and Reform Policy' plot1_title = 'Pct Changes in Economic Aggregates Between' plot1_title += ' Baseline and Reform Policy' plot2_title = 'Pct Changes in Interest Rates and Wages' plot2_title += ' Between Baseline and Reform Policy' plot3_title = 'Differences in Fiscal Variables Relative to GDP' plot3_title += ' Between Baseline and Reform Policy' out_table = ot.tp_output_dump_table(base_params, base_tpi, reform_params, reform_tpi, table_format='csv') html_table = ot.macro_table( base_tpi, base_params, reform_tpi, reform_params, var_list=['Y', 'C', 'I_total', 'L', 'D', 'G', 'r', 'w'], output_type='pct_diff', num_years=10, include_SS=True, include_overall=True, start_year=base_params.start_year, table_format='html') fig1 = op.plot_aggregates(base_tpi, base_params, reform_tpi, reform_params, var_list=['Y', 'C', 'K', 'L'], plot_type='pct_diff', num_years_to_plot=50, start_year=base_params.start_year, vertical_line_years=[ base_params.start_year + base_params.tG1, base_params.start_year + base_params.tG2 ], plot_title=None, path=None) in_memory_file1 = io.BytesIO() fig1.savefig(in_memory_file1, format="png", bbox_inches="tight") in_memory_file1.seek(0) fig2 = op.plot_aggregates(base_tpi, base_params, reform_tpi, reform_params, var_list=['r_gov', 'w'], plot_type='pct_diff', num_years_to_plot=50, start_year=base_params.start_year, vertical_line_years=[ base_params.start_year + base_params.tG1, base_params.start_year + base_params.tG2 ], plot_title=None, path=None) in_memory_file2 = io.BytesIO() fig2.savefig(in_memory_file2, format="png", bbox_inches="tight") in_memory_file2.seek(0) fig3 = op.plot_gdp_ratio(base_tpi, base_params, reform_tpi, reform_params, var_list=['D', 'G', 'total_tax_revenue'], plot_type='diff', num_years_to_plot=50, start_year=base_params.start_year, vertical_line_years=[ base_params.start_year + base_params.tG1, base_params.start_year + base_params.tG2 ], plot_title=None, path=None) in_memory_file3 = io.BytesIO() fig3.savefig(in_memory_file3, format="png", bbox_inches="tight") in_memory_file3.seek(0) comp_dict = { "renderable": [{ "media_type": "PNG", "title": plot1_title, "data": in_memory_file1.read() }, { "media_type": "PNG", "title": plot2_title, "data": in_memory_file2.read() }, { "media_type": "PNG", "title": plot3_title, "data": in_memory_file3.read() }, { "media_type": "table", "title": table_title, "data": html_table }], "downloadable": [{ "media_type": "CSV", "title": table_title, "data": out_table.to_csv() }] } else: table_title = 'Percentage Changes in Economic Aggregates Between' table_title += ' Baseline and Reform Policy' plot_title = 'Percentage Changes in Consumption by Lifetime Income' plot_title += ' Percentile Group' out_table = ot.macro_table_SS(base_ss, reform_ss, var_list=[ 'Yss', 'Css', 'Iss_total', 'Gss', 'total_tax_revenue', 'Lss', 'rss', 'wss' ], table_format='csv') html_table = ot.macro_table_SS(base_ss, reform_ss, var_list=[ 'Yss', 'Css', 'Iss_total', 'Gss', 'total_tax_revenue', 'Lss', 'rss', 'wss' ], table_format='html') fig = op.ability_bar_ss(base_ss, base_params, reform_ss, reform_params, var=var) in_memory_file = io.BytesIO() fig.savefig(in_memory_file, format="png", bbox_inches="tight") in_memory_file.seek(0) comp_dict = { "renderable": [{ "media_type": "PNG", "title": plot_title, "data": in_memory_file.read() }, { "media_type": "table", "title": table_title, "data": html_table }], "downloadable": [{ "media_type": "CSV", "title": table_title, "data": out_table.to_csv() }] } return comp_dict
def test_plot_aggregates(): fig = output_plots.plot_aggregates(base_tpi, base_params, reform_tpi, reform_params) assert fig