def main(argv): parser = MdpArgs( description= "extract mean CO2 emissions at intervals of following MDP instance optimal policy" ) parser.add_paramsfile_single() parser.add_cycle_length() parser.add_iterations(default=500) parser.add_save() args = parser.get_args() if not args.paramsfile: print("error: must pass in paramsfile.") sys.exit(2) params = cl.get_params_single(MDP_VERSION, args.paramsfile) mdp_model = cl.get_mdp_model(MDP_VERSION, [params]) mdp_fh = cl.get_mdp_instance_single(mdp_model, params) t_range = [0, mdp_fh.n_years] _, _, y_emit, _ = mv.avg_co2_probabilistic_v(mdp_fh, t_range[0], t_range[1], args.iterations, True) y_emit = np.sum(y_emit, axis=0) / args.iterations for y in args.cycle: targets_mean, targets_dec = (dict() for i in range(2)) emit_dec = calc_emit_dec(mdp_fh, y_emit, y) years_sampled = [i * y for i in range(0, (mdp_fh.n_years // y))] # Sampled from mean of optimal policy. targets_mean['x'] = years_sampled targets_mean['y'] = [y_emit[i] for i in years_sampled] # Decrement evenly to align with optimal policy. targets_dec['x'] = years_sampled targets_dec['y'] = [ y_emit[0] - i * emit_dec for i in range(mdp_fh.n_years // y) ] targets_dir = Path("visuals/v{}/targets".format(DIR_VERSION)) name = args.paramsfile.replace("_exp", "").replace("_lin", "") tf_mean = targets_dir / "e_v{}_{}_{}_mean.txt".format( DIR_VERSION, y, name) with open(tf_mean, 'w+') as targetsfile: targetsfile.write(str(targets_mean)) tf_dec = targets_dir / "e_v{}_{}_{}_dec.txt".format( DIR_VERSION, y, name) with open(tf_dec, 'w+') as targetsfile: targetsfile.write(str(targets_dec)) targetsfile.close()
def main(argv): parser = argparse.ArgumentParser(description="plot costs of following MDP instance optimal policy") parser.add_argument("-m", "--version", help="MDP model version", type=int) parser.add_argument("-p", "--paramsfiles", help="list of txt files with version specific params as dict", nargs='*', action='store') parser.add_argument("-t", "--timerange", help="see specific time range", nargs=2, type=int, default=None) parser.add_argument("-i", "--iterations", help="number of simulations of tech stage transition", type=int, default=200) parser.add_argument("-e", "--CO2", help="limit on annual CO2 emissions", type=int, default=0) parser.add_argument("-r", "--RES", help="target RES penetration", type=int, default=0) parser.add_argument("--save", help="save plots as png files", action='store_true') args = parser.parse_args() if int(args.version) < 2: print("error: plot_compare_co2_res only supported for MDP V2 or higher.") sys.exit(1) if len(args.paramsfiles) == 0: print("error: plot_compare_co2_res requires at least one parameters file.") sys.exit(2) params_co2_res = [] for paramsfile in args.paramsfiles: params_dir = Path("results/v{}/params".format(args.version)) pf = params_dir / "p_v{}_{}.txt".format(args.version, paramsfile) with open(pf, 'r') as paramsfile: params = eval(paramsfile.read()) paramsfile.close() params_co2_res.append(params) param_names = [mv.format_param_names(pf) for pf in args.paramsfiles] mdp_model = None if int(args.version) == 2: mdp_model = MdpModelV2() p_adv_vary = False elif int(args.version) == 3: mdp_model = MdpModelV3() p_adv_vary = True elif int(args.version) == 4: mdp_model = MdpModelV4() p_adv_vary = True assert(mdp_model is not None) assert(mdp_model.param_names == list(params.keys())) mdp_fh_co2_res = [] for params in params_co2_res: mdp_fh = mdp_model.run_fh(params) mdp_fh_co2_res.append(mdp_fh) if args.timerange: t0, tN = args.timerange t0 = max(0, t0-1) if tN - t0 > mdp_fh.n_years: print("error: time range {}-{} out of range: {}".format(t0, tN, mdp_fh.n_tech_stages)) sys.exit(3) else: t0 = 0 tN = mdp_fh_co2_res[0].n_years np.set_printoptions(linewidth=300) visuals_dir = Path("visuals/v{}/plots".format(args.version)) fig_co2_emit = mv.opt_policy_co2_emit(mdp_fh_co2_res, [t0, tN], args.iterations, param_names, CO2=args.CO2, p_adv_vary=p_adv_vary) fig_res = mv.opt_policy_res_percent(mdp_fh_co2_res, [t0, tN], args.iterations, param_names, RES=args.RES, p_adv_vary=p_adv_vary) if args.save: fig_co2_emit.savefig(visuals_dir / "g_v{}_compare_co2_emit_ann{}.png".format(args.version, paramsfile)) fig_res.savefig(visuals_dir / "g_v{}_compare_res_ann{}.png".format(args.version, paramsfile)) plt.show()
def main(argv): parser = argparse.ArgumentParser(description="plot costs of following MDP instance optimal policy") parser.add_argument("-m", "--version", help="MDP model version", type=int) parser.add_argument("-p", "--paramsfile", help="txt file with version specific params dict") parser.add_argument("-c", "--component", help="see single cost component") parser.add_argument("-a", "--policy", help="txt file with policy as list", default=None) parser.add_argument("-t", "--timerange", help="see specific time range", nargs=2, type=int, default=None) parser.add_argument("-v", "--techstage", help="see single tech stage", type=int, default=None) parser.add_argument("--save", help="save plots as png files", action='store_true') args = parser.parse_args() if int(args.version) < 2: print("error: plot_cost_component only supported for MDP V2 or higher.") sys.exit(1) params_dir = Path("results/v{}/params".format(args.version)) pf = params_dir / "p_v{}_{}.txt".format(args.version, args.paramsfile) with open(pf, 'r') as paramsfile: params = eval(paramsfile.read()) paramsfile.close() mdp_model = None if int(args.version) == 2: mdp_model = MdpModelV2() elif int(args.version) == 3: mdp_model = MdpModelV3() elif int(args.version) == 4: mdp_model = MdpModelV4() assert(mdp_model is not None) assert(mdp_model.param_names == list(params.keys())) mdp_fh = mdp_model.run_fh(params) if args.techstage is not None: if args.techstage < 0 or args.techstage >= mdp_fh.n_tech_stages: print("error: tech stage {} out of range: {}".format(args.techstage, mdp_fh.n_tech_stages)) sys.exit(2) if args.policy: policies_dir = Path("visuals/v{}/policies".format(args.version)) af = policies_dir / "a_v{}_{}.txt".format(args.version, args.policy) with open(af, 'r') as policyfile: arb_policy = eval(policyfile.read()) policyfile.close() assert(len(arb_policy) == mdp_fh.n_years) policy_type = args.policy else: policy_type = "optimal" if args.techstage is not None: if args.policy: policy = mv.get_arb_policy_trajectory(arb_policy, args.techstage) else: policy = mv.get_opt_policy_trajectory(mdp_fh, args.techstage) v_str = str(args.techstage) else: policy = [] for v in np.arange(mdp_fh.n_tech_stages): if args.policy: policy.append(mv.get_arb_policy_trajectory(arb_policy, v)) else: policy.append(mv.get_opt_policy_trajectory(mdp_fh, v)) v_str = "all" if args.timerange: t0, tN = args.timerange t0 = max(0, t0-1) if tN - t0 > mdp_fh.n_years: print("error: time range {}-{} out of range: {}".format(t0, tN, mdp_fh.n_tech_stages)) sys.exit(3) else: t0 = 0 tN = mdp_fh.n_years np.set_printoptions(linewidth=300) visuals_dir = Path("visuals/v{}/plots".format(args.version)) fig_component = mv.cost_by_component_wrapper(mdp_fh, policy, policy_type, args.component, [t0, tN], v=args.techstage) if args.save: fig_component.savefig(visuals_dir / "g_v{}_{}_{}_{}.png".format(args.version, policy_type, args.component, paramsfile, v_str)) plt.show()
def main(argv): parser = MdpArgs(description="plot tax adjusted vs. non-adjusted targets of following optimal MDP policy") parser.add_model_version() parser.add_paramsfile_multiple() parser.add_time_range() parser.add_iterations() parser.add_confidence_interval() parser.add_use_data() parser.add_save() args = parser.get_args() if not parser.check_version(4, 4, "visualize_adjust only supported for MDP V3 with MDP V4 or higher."): sys.exit(1) if not parser.check_paramfile_multiple(): sys.exit(2) paramsfiles3 = [] paramsfiles4 = [] for i in range(0, len(args.paramsfiles)): if i % 2: paramsfiles4.append(args.paramsfiles[i]) else: paramsfiles3.append(args.paramsfiles[i]) # MDP V3. params3_all = cl.get_params_multiple(COMP_VERSION, paramsfiles3) mdp_model3 = cl.get_mdp_model(COMP_VERSION, params3_all) mdp_fh3_all = cl.get_mdp_instance_multiple(mdp_model3, params3_all) # MDP V4. params4_all = cl.get_params_multiple(args.version, paramsfiles4) mdp_model4 = cl.get_mdp_model(args.version, params4_all) t_range = cl.get_time_range(args, params4_all[0]) if not t_range: sys.exit(3) mdp_data = MdpDataGatherer(mdp_model4, args.iterations, t_range) if args.confidenceinterval: mdp_data.set_ci(ci_type=args.confidenceinterval) x = mdp_data.get_time_range(t_range) y_res3, y_emit3, y_tax3 = ([] for i in range(3)) for mdp_fh3 in mdp_fh3_all: _, res, emit, tax = mv.avg_co2_probabilistic_v(mdp_fh3, t_range[0], t_range[1], args.iterations, True, res_percent=True) y_res3.append(mdp_data.convert_to_percent(mdp_data.calc_data_bounds(res))) y_emit3.append(mdp_data.calc_data_bounds(emit)) y_tax3.append(mdp_data.calc_data_bounds(tax)) y_res4, y_emit4, y_tax4 = ([] for i in range(3)) if args.usedata: for pf in paramsfiles4: data = cl.get_mdp_data(args.version, pf) y_res4.append(mdp_data.convert_to_percent(mdp_data.get_data_component(data, 'res_penetration'))) y_emit4.append(mdp_data.get_data_component(data, 'co2_emissions')) y_tax4.append(mdp_data.get_data_component(data, 'co2_tax')) else: mdp_fh_all = cl.get_mdp_instance_multiple(mdp_model4, params4_all) for mdp_fh4 in mdp_fh_all: y_res4.append(mdp_data.convert_to_percent(mdp_data.calc_data_bounds(mdp_data.res_penetration(mdp_fh4)))) y_emit4.append(mdp_data.calc_data_bounds(mdp_data.co2_emissions(mdp_fh4))) y_tax4.append(mdp_data.calc_data_bounds(mdp_data.co2_tax_collected(mdp_fh4))) params3_names = paramsfiles3 params4_names = paramsfiles4 colors = None figs_compare = [] mdp_plot = MdpPlotter() # RES penetration mdp_plot.initialize("RES Penetration", "Time (years)", "RES Penetration (%)") mdp_plot.plot_lines(x, y_res3, params3_names, y_max=100, colors=colors, CI=args.confidenceinterval) mdp_plot.plot_lines(x, y_res4, params4_names, y_max=100, colors=colors, CI=args.confidenceinterval, linestyle='dashed') fig = mdp_plot.finalize() figs_compare.append(fig) # CO2 emissions mdp_plot.initialize("Annual CO2 Emissions", "Time (years)", "CO2 (million ton/yr)") mdp_plot.plot_lines(x, y_emit3, params3_names, scale=1e6, colors=colors, CI=args.confidenceinterval) mdp_plot.plot_lines(x, y_emit4, params4_names, scale=1e6, colors=colors, CI=args.confidenceinterval, linestyle='dashed') fig = mdp_plot.finalize() figs_compare.append(fig) # CO2 tax collected mdp_plot.initialize("Annual CO2 Tax Collected", "Time (years)", "Cost (million USD/yr)") mdp_plot.plot_lines(x, y_tax3, params3_names, scale=1e6, colors=colors, CI=args.confidenceinterval) mdp_plot.plot_lines(x, y_tax4, params4_names, scale=1e6, colors=colors, CI=args.confidenceinterval, linestyle='dashed') fig = mdp_plot.finalize() figs_compare.append(fig) names = ['res', 'emit', 'target'] visuals_dir = Path("visuals/v{}/plots".format(args.version)) if args.save: for fig, name in zip(figs_compare, names): fig.savefig(visuals_dir / "g_v{}_compare_{}.png".format(args.version, name)) plt.show()
def main(argv): parser = MdpArgs( description= "plot tax adjusted vs. non-adjusted targets of following optimal MDP policy" ) parser.add_model_version() parser.add_paramsfile_multiple() parser.add_targetsfile() parser.add_time_range() parser.add_iterations() parser.add_confidence_interval() parser.add_use_data() parser.add_save() args = parser.get_args() if not parser.check_version( 4, 4, "visualize_adjust only supported for MDP V3 with MDP V4 or higher." ): sys.exit(1) if not parser.check_paramfile_multiple(): sys.exit(2) # MDP V3. params3 = cl.get_params_single(COMP_VERSION, args.paramsfiles[0]) mdp_model3 = cl.get_mdp_model(COMP_VERSION, [params3]) mdp_fh3 = cl.get_mdp_instance_single(mdp_model3, params3) # MDP V4. params4_all = cl.get_params_multiple(args.version, args.paramsfiles[1:]) mdp_model4 = cl.get_mdp_model(args.version, params4_all) t_range = cl.get_time_range(args, params4_all[0]) if not t_range: sys.exit(3) mdp_data = MdpDataGatherer(mdp_model4, args.iterations, t_range) if args.confidenceinterval: mdp_data.set_ci(ci_type=args.confidenceinterval) x = mdp_data.get_time_range(t_range) _, y_res3, y_emit3, y_tax3 = mv.avg_co2_probabilistic_v(mdp_fh3, t_range[0], t_range[1], args.iterations, True, res_percent=True) y_res3 = mdp_data.convert_to_percent(mdp_data.calc_data_bounds(y_res3)) y_emit3 = mdp_data.calc_data_bounds(y_emit3) y_tax3 = mdp_data.calc_data_bounds(y_tax3) y_res4, y_emit4, y_tax4 = ([] for i in range(3)) if args.usedata: for pf in args.paramsfiles[1:]: data = cl.get_mdp_data(args.version, pf) y_res4.append( mdp_data.convert_to_percent( mdp_data.get_data_component(data, 'res_penetration'))) y_emit4.append(mdp_data.get_data_component(data, 'co2_emissions')) y_tax4.append(mdp_data.get_data_component(data, 'co2_tax')) else: mdp_fh_all = cl.get_mdp_instance_multiple(mdp_model4, params4_all) for mdp_fh4 in mdp_fh_all: y_res4.append( mdp_data.convert_to_percent( mdp_data.calc_data_bounds( mdp_data.res_penetration(mdp_fh4)))) y_emit4.append( mdp_data.calc_data_bounds(mdp_data.co2_emissions(mdp_fh4))) y_tax4.append( mdp_data.calc_data_bounds(mdp_data.co2_tax_collected(mdp_fh4))) y_res = [y_res3] + y_res4 y_emit = [y_emit3] + y_emit4 y_tax = [y_tax3] + y_tax4 if args.targetsfile: targets = cl.get_emissions_target(args.version, args.targetsfile) targets['x'] = [x + START_YEAR for x in targets['x']] targets['x'] = targets['x'][0:7] targets['y'] = targets['y'][0:7] else: targets = None # params_names = args.paramsfiles params_names = ["{}: static".format(args.paramsfiles[0])] + [ "{}: adjusted".format(pf) for pf in args.paramsfiles[1:] ] colors = None figs_compare = [] mdp_plot = MdpPlotter() # RES penetration mdp_plot.initialize("RES Penetration", "Time (years)", "RES Penetration (%)") mdp_plot.plot_lines(x, y_res, params_names, y_max=100, colors=colors, CI=args.confidenceinterval) fig = mdp_plot.finalize() figs_compare.append(fig) # CO2 emissions mdp_plot.initialize("Annual CO2 Emissions", "Time (years)", "CO2 (million ton/yr)") mdp_plot.plot_lines(x, y_emit, params_names, scale=1e6, colors=colors, CI=args.confidenceinterval) if targets: mdp_plot.add_scatter_points(targets['x'], targets['y'], "Emissions target", scale=1e6, marker='o') fig = mdp_plot.finalize() figs_compare.append(fig) # CO2 tax collected mdp_plot.initialize("Annual CO2 Tax Collected", "Time (years)", "Cost (billion USD/yr)") mdp_plot.plot_lines(x, y_tax, params_names, scale=1e9, colors=colors, CI=args.confidenceinterval) fig = mdp_plot.finalize() figs_compare.append(fig) names = ['res', 'emit', 'target'] visuals_dir = Path("visuals/v{}/plots".format(args.version)) if args.save: for fig, name in zip(figs_compare, names): fig.savefig(visuals_dir / "g_v{}_compare_{}.png".format(args.version, name)) plt.show()
def main(argv): parser = argparse.ArgumentParser( description="plot costs of following MDP instance optimal policy") parser.add_argument("-m", "--version", help="MDP model version", type=int) parser.add_argument("-p", "--paramsfile", help="txt file with version specific params as dict") parser.add_argument( "-a", "--policies", help="keyword opt and/or txt files with policy as list", nargs='*', action='store') parser.add_argument("-v", "--techstage", help="see single tech stage", type=int, default=None) parser.add_argument("-t", "--timerange", help="see specific time range", nargs=2, type=int, default=None) parser.add_argument("--granular", help="more granular cost component breakdown", action='store_true') parser.add_argument("--save", help="save plots as png files", action='store_true') args = parser.parse_args() if int(args.version) < 2: print( "error: plot_double_policy_costs only supported for MDP V2 or higher." ) sys.exit(1) if args.policies is not None and len(args.policies) not in (1, 2): print( "error: plot_double_policy_costs takes 2 arbitrary policies or 1 arbitrary and the optimal policy." ) sys.exit(1) params_dir = Path("results/v{}/params".format(args.version)) pf = params_dir / "p_v{}_{}.txt".format(args.version, args.paramsfile) with open(pf, 'r') as paramsfile: params = eval(paramsfile.read()) paramsfile.close() mdp_model = None if int(args.version) == 2: mdp_model = MdpModelV2() elif int(args.version) == 3: mdp_model = MdpModelV3() elif int(args.version) == 4: mdp_model = MdpModelV4() assert (mdp_model is not None) assert (mdp_model.param_names == list(params.keys())) mdp_fh = mdp_model.run_fh(params) if args.techstage: if args.techstage < 0 or args.techstage >= mdp_fh.n_tech_stages: print("error: tech stage {} out of range: {}".format( args.techstage, mdp_fh.n_tech_stages)) sys.exit(2) pol_strs = args.policies two_pols = [] for pol_str in pol_strs: policies_dir = Path("visuals/v{}/policies".format(args.version)) af = policies_dir / "a_v{}_{}.txt".format(args.version, pol_str) with open(af, 'r') as policyfile: arb_policy = eval(policyfile.read()) two_pols.append(arb_policy) policyfile.close() assert (len(arb_policy) == mdp_fh.n_years) if args.techstage is not None: double_policy = [ mv.get_arb_policy_trajectory(pol, args.techstage) for pol in two_pols ] if len(two_pols) == 1: double_policy.insert( 0, mv.get_opt_policy_trajectory(mdp_fh, args.techstage)) v_str = str(args.techstage) else: double_policy = [] if len(two_pols) == 1: double_policy.append([ mv.get_opt_policy_trajectory(mdp_fh, v) for v in np.arange(mdp_fh.n_tech_stages) ]) double_policy.append([ mv.get_arb_policy_trajectory(two_pols[0], v) for v in np.arange(mdp_fh.n_tech_stages) ]) else: for i in [0, 1]: double_policy.append([ mv.get_arb_policy_trajectory(two_pols[i], v) for v in np.arange(mdp_fh.n_tech_stages) ]) v_str = "all" if len(pol_strs) == 1: pol_strs.insert(0, "optimal") policy_type = "{}_VS_{}".format(pol_strs[0], pol_strs[1]) if args.timerange: t0, tN = args.timerange t0 = max(0, t0 - 1) if tN - t0 > mdp_fh.n_years: print("error: time range {}-{} out of range: {}".format( t0, tN, mdp_fh.n_tech_stages)) sys.exit(3) else: t0 = 0 tN = mdp_fh.n_years if args.granular: components = COMPONENTS_GRANULAR else: components = COMPONENTS np.set_printoptions(linewidth=300) visuals_dir = Path("visuals/v{}/plots".format(args.version)) fig_breakdown = mv.total_cost_wrapper(mdp_fh, double_policy, policy_type, [t0, tN], v=args.techstage) fig_percents = mv.cost_breakdown_wrapper(mdp_fh, double_policy, policy_type, components, [t0, tN], v=args.techstage) fig_total = mv.cost_breakdown_wrapper(mdp_fh, double_policy, policy_type, components, [t0, tN], v=args.techstage, percent=True) if args.save: fig_breakdown.savefig( visuals_dir / "g_v{}_{}_breakdown_{}_{}.png".format( args.version, policy_type, paramsfile, v_str)) fig_percents.savefig(visuals_dir / "g_v{}_{}_percents_{}_{}.png".format( args.version, policy_type, paramsfile, v_str)) fig_total.savefig(visuals_dir / "g_v{}_{}_total_{}_{}.png".format( args.version, policy_type, paramsfile, v_str)) plt.show()
def main(argv): parser = argparse.ArgumentParser( description="plot costs of following MDP instance optimal policy") parser.add_argument("-m", "--version", help="MDP model version", type=int) parser.add_argument("-p", "--paramsfile", help="txt file with version specific params as dict") parser.add_argument("-t", "--timerange", help="see specific time range", nargs=2, type=int, default=None) parser.add_argument("-i", "--iterations", help="number of simulations of tech stage transition", type=int, default=200) parser.add_argument("--save", help="save plots as png files", action='store_true') args = parser.parse_args() if int(args.version) < 2: print("error: plot_co2_impacts only supported for MDP V2 or higher.") sys.exit(1) params_dir = Path("results/v{}/params".format(args.version)) pf = params_dir / "p_v{}_{}.txt".format(args.version, args.paramsfile) with open(pf, 'r') as paramsfile: params = eval(paramsfile.read()) paramsfile.close() mdp_model = None if int(args.version) == 2: mdp_model = MdpModelV2() p_adv_vary = False elif int(args.version) == 3: mdp_model = MdpModelV3() p_adv_vary = True elif int(args.version) == 4: mdp_model = MdpModelV4() p_adv_vary = True assert (mdp_model is not None) assert (mdp_model.param_names == list(params.keys())) mdp_fh = mdp_model.run_fh(params) policy = [ mv.get_opt_policy_trajectory(mdp_fh, v) for v in np.arange(mdp_fh.n_tech_stages) ] if args.timerange: t0, tN = args.timerange t0 = max(0, t0 - 1) if tN - t0 > mdp_fh.n_years: print("error: time range {}-{} out of range: {}".format( t0, tN, mdp_fh.n_tech_stages)) sys.exit(3) else: t0 = 0 tN = mdp_fh.n_years np.set_printoptions(linewidth=300) visuals_dir = Path("visuals/v{}/plots".format(args.version)) fig_annual = mv.co2_emit_tax_wrapper(mdp_fh, policy, [t0, tN], args.iterations, is_annual=True, p_adv_vary=p_adv_vary) fig_cum = mv.co2_emit_tax_wrapper(mdp_fh, policy, [t0, tN], args.iterations, is_annual=False, p_adv_vary=p_adv_vary) if args.save: fig_annual.savefig( visuals_dir / "g_v{}_co2_emit_tax_ann_{}.png".format(args.version, paramsfile)) fig_cum.savefig( visuals_dir / "g_v{}_co2_emit_tax_cum_{}.png".format(args.version, paramsfile)) plt.show()
def main(argv): parser = argparse.ArgumentParser(description="plot costs of following MDP instance optimal policy") parser.add_argument("-m", "--version", help="MDP model version", type=int) parser.add_argument("-p", "--paramsfile", help="txt file with version specific params as dict") parser.add_argument("-s", "--reductions", help="fractional reductions in storage capital costs", nargs='+', type=float) parser.add_argument("-t", "--timerange", help="see specific time range", nargs=2, type=int, default=None) parser.add_argument("-i", "--iterations", help="number of simulations of tech stage transition", type=int, default=200) parser.add_argument("-b", "--budget", help="annual budget for renewable plants", type=int, default=0) parser.add_argument("-r", "--RES", help="target renewable penetration", type=int, default=0) parser.add_argument("--save", help="save plots as png files", action='store_true') args = parser.parse_args() if int(args.version) < 2: print("error: plot_storage_sensitivity only supported for MDP V2 or higher.") sys.exit(1) params_dir = Path("results/v{}/params".format(args.version)) pf = params_dir / "p_v{}_{}.txt".format(args.version, args.paramsfile) with open(pf, 'r') as paramsfile: params = eval(paramsfile.read()) paramsfile.close() params_storage_reduced = [] for frac in args.reductions: params_reduced = mv.reduce_storage_costs_params(params, frac) params_storage_reduced.append(params_reduced) mdp_model = None if int(args.version) == 2: mdp_model = MdpModelV2() p_adv_vary = False elif int(args.version) == 3: mdp_model = MdpModelV3() p_adv_vary = True elif int(args.version) == 4: mdp_model = MdpModelV4() p_adv_vary = True assert(mdp_model is not None) assert(mdp_model.param_names == list(params.keys())) mdp_fh_storage_reduced = [] for params in params_storage_reduced: mdp_fh = mdp_model.run_fh(params) mdp_fh_storage_reduced.append(mdp_fh) if args.timerange: t0, tN = args.timerange t0 = max(0, t0-1) if tN - t0 > mdp_fh.n_years: print("error: time range {}-{} out of range: {}".format(t0, tN, mdp_fh.n_tech_stages)) sys.exit(3) else: t0 = 0 tN = mdp_fh.n_years np.set_printoptions(linewidth=300) visuals_dir = Path("visuals/v{}/plots".format(args.version)) figs_budget, fig_res = mv.storage_reductions_wrapper(mdp_fh_storage_reduced, [t0, tN], args.iterations, args.reductions, budget=args.budget, RES=args.RES, p_adv_vary=p_adv_vary) if args.save: figs_budget[0].savefig(visuals_dir / "g_v{}_storage_reductions_budget_ann{}.png".format(args.version, paramsfile)) figs_budget[1].savefig(visuals_dir / "g_v{}_storage_reductions_budget_cum{}.png".format(args.version, paramsfile)) fig_res.savefig(visuals_dir / "g_v{}_storage_reductions_RESpenetration_{}.png".format(args.version, paramsfile)) plt.show()