Merge branch 'daniel-rdt-fix-plot-summary'
This commit is contained in:
commit
1087b1a1af
@ -106,6 +106,8 @@ rule plot_summary:
|
||||
countries=config["countries"],
|
||||
planning_horizons=config["scenario"]["planning_horizons"],
|
||||
sector_opts=config["scenario"]["sector_opts"],
|
||||
emissions_scope=config["energy"]["emissions"],
|
||||
eurostat_report_year=config["energy"]["eurostat_report_year"],
|
||||
plotting=config["plotting"],
|
||||
RDIR=RDIR,
|
||||
input:
|
||||
@ -113,6 +115,7 @@ rule plot_summary:
|
||||
energy=RESULTS + "csvs/energy.csv",
|
||||
balances=RESULTS + "csvs/supply_energy.csv",
|
||||
eurostat=input_eurostat,
|
||||
co2="data/eea/UNFCCC_v23.csv",
|
||||
output:
|
||||
costs=RESULTS + "graphs/costs.pdf",
|
||||
energy=RESULTS + "graphs/energy.pdf",
|
||||
|
@ -711,5 +711,5 @@ if __name__ == "__main__":
|
||||
if snakemake.params.foresight == "myopic":
|
||||
cumulative_cost = calculate_cumulative_cost()
|
||||
cumulative_cost.to_csv(
|
||||
"results/" + snakemake.params.RDIR + "/csvs/cumulative_cost.csv"
|
||||
"results/" + snakemake.params.RDIR + "csvs/cumulative_cost.csv"
|
||||
)
|
||||
|
@ -387,6 +387,9 @@ def historical_emissions(countries):
|
||||
countries.remove("GB")
|
||||
countries.append("UK")
|
||||
|
||||
# remove countries which are not included in eea historical emission dataset
|
||||
countries_to_remove = {"AL", "BA", "ME", "MK", "RS"}
|
||||
countries = list(set(countries) - countries_to_remove)
|
||||
year = np.arange(1990, 2018).tolist()
|
||||
|
||||
idx = pd.IndexSlice
|
||||
@ -457,9 +460,20 @@ def plot_carbon_budget_distribution(input_eurostat):
|
||||
ax1.set_ylim([0, 5])
|
||||
ax1.set_xlim([1990, snakemake.params.planning_horizons[-1] + 1])
|
||||
|
||||
path_cb = "results/" + snakemake.params.RDIR + "/csvs/"
|
||||
path_cb = "results/" + snakemake.params.RDIR + "csvs/"
|
||||
countries = snakemake.params.countries
|
||||
e_1990 = co2_emissions_year(countries, input_eurostat, opts, year=1990)
|
||||
emissions_scope = snakemake.params.emissions_scope
|
||||
report_year = snakemake.params.eurostat_report_year
|
||||
input_co2 = snakemake.input.co2
|
||||
e_1990 = co2_emissions_year(
|
||||
countries,
|
||||
input_eurostat,
|
||||
opts,
|
||||
emissions_scope,
|
||||
report_year,
|
||||
input_co2,
|
||||
year=1990,
|
||||
)
|
||||
CO2_CAP = pd.read_csv(path_cb + "carbon_budget_distribution.csv", index_col=0)
|
||||
|
||||
ax1.plot(e_1990 * CO2_CAP[o], linewidth=3, color="dodgerblue", label=None)
|
||||
@ -535,7 +549,7 @@ def plot_carbon_budget_distribution(input_eurostat):
|
||||
fancybox=True, fontsize=18, loc=(0.01, 0.01), facecolor="white", frameon=True
|
||||
)
|
||||
|
||||
path_cb_plot = "results/" + snakemake.params.RDIR + "/graphs/"
|
||||
path_cb_plot = "results/" + snakemake.params.RDIR + "graphs/"
|
||||
plt.savefig(path_cb_plot + "carbon_budget_plot.pdf", dpi=300)
|
||||
|
||||
|
||||
|
@ -191,17 +191,15 @@ def get(item, investment_year=None):
|
||||
|
||||
|
||||
def co2_emissions_year(
|
||||
countries, input_eurostat, opts, emissions_scope, report_year, year
|
||||
countries, input_eurostat, opts, emissions_scope, report_year, input_co2, year
|
||||
):
|
||||
"""
|
||||
Calculate CO2 emissions in one specific year (e.g. 1990 or 2018).
|
||||
"""
|
||||
emissions_scope = snakemake.params.energy["emissions"]
|
||||
eea_co2 = build_eea_co2(snakemake.input.co2, year, emissions_scope)
|
||||
eea_co2 = build_eea_co2(input_co2, year, emissions_scope)
|
||||
|
||||
# TODO: read Eurostat data from year > 2014
|
||||
# this only affects the estimation of CO2 emissions for BA, RS, AL, ME, MK
|
||||
report_year = snakemake.params.energy["eurostat_report_year"]
|
||||
if year > 2014:
|
||||
eurostat_co2 = build_eurostat_co2(
|
||||
input_eurostat, countries, report_year, year=2014
|
||||
@ -222,7 +220,7 @@ def co2_emissions_year(
|
||||
|
||||
|
||||
# TODO: move to own rule with sector-opts wildcard?
|
||||
def build_carbon_budget(o, input_eurostat, fn, emissions_scope, report_year):
|
||||
def build_carbon_budget(o, input_eurostat, fn, emissions_scope, report_year, input_co2):
|
||||
"""
|
||||
Distribute carbon budget following beta or exponential transition path.
|
||||
"""
|
||||
@ -240,12 +238,24 @@ def build_carbon_budget(o, input_eurostat, fn, emissions_scope, report_year):
|
||||
countries = snakemake.params.countries
|
||||
|
||||
e_1990 = co2_emissions_year(
|
||||
countries, input_eurostat, opts, emissions_scope, report_year, year=1990
|
||||
countries,
|
||||
input_eurostat,
|
||||
opts,
|
||||
emissions_scope,
|
||||
report_year,
|
||||
input_co2,
|
||||
year=1990,
|
||||
)
|
||||
|
||||
# emissions at the beginning of the path (last year available 2018)
|
||||
e_0 = co2_emissions_year(
|
||||
countries, input_eurostat, opts, emissions_scope, report_year, year=2018
|
||||
countries,
|
||||
input_eurostat,
|
||||
opts,
|
||||
emissions_scope,
|
||||
report_year,
|
||||
input_co2,
|
||||
year=2018,
|
||||
)
|
||||
|
||||
planning_horizons = snakemake.params.planning_horizons
|
||||
@ -3392,12 +3402,18 @@ if __name__ == "__main__":
|
||||
if "cb" not in o:
|
||||
continue
|
||||
limit_type = "carbon budget"
|
||||
fn = "results/" + snakemake.params.RDIR + "/csvs/carbon_budget_distribution.csv"
|
||||
fn = "results/" + snakemake.params.RDIR + "csvs/carbon_budget_distribution.csv"
|
||||
if not os.path.exists(fn):
|
||||
emissions_scope = snakemake.params.emissions_scope
|
||||
report_year = snakemake.params.eurostat_report_year
|
||||
input_co2 = snakemake.input.co2
|
||||
build_carbon_budget(
|
||||
o, snakemake.input.eurostat, fn, emissions_scope, report_year
|
||||
o,
|
||||
snakemake.input.eurostat,
|
||||
fn,
|
||||
emissions_scope,
|
||||
report_year,
|
||||
input_co2,
|
||||
)
|
||||
co2_cap = pd.read_csv(fn, index_col=0).squeeze()
|
||||
limit = co2_cap.loc[investment_year]
|
||||
|
Loading…
Reference in New Issue
Block a user