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 = MdpArgs(description="debug") parser.add_model_version() parser.add_paramsfile_single() args = parser.get_args() params = cl.get_params_single(args.version, args.paramsfile) mdp_model = cl.get_mdp_model(args.version, [params]) mdp_fh = cl.get_mdp_instance_single(mdp_model, params) # Iterations set to 1, timerange set to 0-20 yr. mdp_data = MdpDataGatherer(mdp_model, 1, [0, 20]) # Variable pulled out of _adjust_co2_tax function in MdpCostCalculator. y_base = mdp_data.co2_base(mdp_fh) # Variable pulled from y_l = mdp_data.get_state_variable(mdp_fh, 'l') y_price = mdp_data.co2_current_price(mdp_fh) y_e = mdp_data.get_state_variable(mdp_fh, 'e') y_inc = mdp_data.co2_inc(mdp_fh) # # Use if changing iterations to > 1. # y_base = np.mean(mdp_data.co2_base(mdp_fh), axis=0) # y_l = np.mean(mdp_data.get_state_variable(mdp_fh, 'l'), axis=0) # y_price = np.mean(mdp_data.co2_current_price(mdp_fh), axis=0) # y_e = np.mean(mdp_data.get_state_variable(mdp_fh, 'e'), axis=0) # y_inc = np.mean(mdp_data.co2_inc(mdp_fh), axis=0) np.set_printoptions(linewidth=200) with open("debug_co2_output.txt", "a+") as debugfile: sys.stdout = debugfile print("### DEBUGGING CO2 ###\n\n") print(params, "\n") time = 0 # for l, e, base, inc in zip(y_l, y_e, y_base, y_inc): # print("TIME: ", time) # print("level: ", l) # print("act: ", e) # print("base: ", base) # print("inc: ", inc) # time += 1 print("inc: ", y_inc) print("base: ", y_base) print("level: ", y_l) print("price: ", y_price) print("act: ", y_e) print("\n\n") sys.stdout = og debugfile.close()