diff --git a/Snakefile b/Snakefile index 0b86042e..6db0bca0 100644 --- a/Snakefile +++ b/Snakefile @@ -571,7 +571,8 @@ rule plot_summary: costs=SDIR + '/csvs/costs.csv', energy=SDIR + '/csvs/energy.csv', balances=SDIR + '/csvs/supply_energy.csv', - clustered_pop_layout="resources/pop_layout_elec_s{simpl}_{clusters}.csv", + eurostat=input_eurostat, + country_codes='data/Country_codes.csv', output: costs=SDIR + '/graphs/costs.pdf', energy=SDIR + '/graphs/energy.pdf', diff --git a/scripts/plot_summary.py b/scripts/plot_summary.py index 7ebfde24..091957d5 100644 --- a/scripts/plot_summary.py +++ b/scripts/plot_summary.py @@ -202,7 +202,7 @@ def plot_energy(): new_index = preferred_order.intersection(df.index).append(df.index.difference(preferred_order)) new_columns = df.columns.sort_values() - + fig, ax = plt.subplots(figsize=(12,8)) print(df.loc[new_index, new_columns]) @@ -363,7 +363,7 @@ def historical_emissions(cts): -def plot_carbon_budget_distribution(): +def plot_carbon_budget_distribution(input_eurostat): """ Plot historical carbon emissions in the EU and decarbonization path """ @@ -385,9 +385,10 @@ def plot_carbon_budget_distribution(): ax1.set_xlim([1990,snakemake.config['scenario']['planning_horizons'][-1]+1]) path_cb = snakemake.config['results_dir'] + snakemake.config['run'] + '/csvs/' - countries=pd.read_csv(path_cb + 'countries.csv', index_col=1) + pop_layout = pd.read_csv(snakemake.input.clustered_pop_layout, index_col=0) + countries=pd.read_csv(snakemake.input.country_codes, index_col=1) cts=countries.index.to_list() - e_1990 = co2_emissions_year(cts, opts, year=1990) + e_1990 = co2_emissions_year(cts, input_eurostat, opts, year=1990) CO2_CAP=pd.read_csv(path_cb + 'carbon_budget_distribution.csv', index_col=0) @@ -438,8 +439,7 @@ if __name__ == "__main__": if 'snakemake' not in globals(): from helper import mock_snakemake snakemake = mock_snakemake('plot_summary') - - update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts) + n_header = 4 @@ -453,4 +453,4 @@ if __name__ == "__main__": opts=sector_opts.split('-') for o in opts: if "cb" in o: - plot_carbon_budget_distribution() + plot_carbon_budget_distribution(snakemake.input.eurostat) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index d77e2201..5d1594fc 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -158,18 +158,16 @@ def get(item, investment_year=None): return item -def co2_emissions_year(opts, year): +def co2_emissions_year(countries, input_eurostat, opts, year): """ Calculate CO2 emissions in one specific year (e.g. 1990 or 2018). """ emissions_scope = snakemake.config["energy"]["emissions"] eea_co2 = build_eea_co2(snakemake.input.co2, year, emissions_scope) - input_eurostat = snakemake.input.eurostat # TODO: read Eurostat data from year > 2014 # this only affects the estimation of CO2 emissions for BA, RS, AL, ME, MK report_year = snakemake.config["energy"]["eurostat_report_year"] - countries = pd.Index(pop_layout.ct.unique()) if year > 2014: eurostat_co2 = build_eurostat_co2(input_eurostat, countries, report_year, year=2014) else: @@ -205,10 +203,10 @@ def build_carbon_budget(o, fn): countries = n.buses.country.dropna().unique() - e_1990 = co2_emissions_year( opts, year=1990) + e_1990 = co2_emissions_year(countries, snakemake.input.eurostat, opts, year=1990) #emissions at the beginning of the path (last year available 2018) - e_0 = co2_emissions_year(opts, year=2018) + e_0 = co2_emissions_year(countries, snakemake.input.eurostat, opts, year=2018) planning_horizons = snakemake.config['scenario']['planning_horizons'] t_0 = planning_horizons[0]