move snakemake dependencies out for co2limit cb option to work
This commit is contained in:
parent
530e453eba
commit
f10628930e
@ -464,12 +464,14 @@ rule prepare_sector_network:
|
||||
overrides="data/override_component_attrs",
|
||||
network=pypsaeur('networks/elec_s{simpl}_{clusters}_ec_lv{lv}_{opts}.nc'),
|
||||
energy_totals_name='resources/energy_totals.csv',
|
||||
eurostat=input_eurostat,
|
||||
pop_weighted_energy_totals="resources/pop_weighted_energy_totals_s{simpl}_{clusters}.csv",
|
||||
transport_demand="resources/transport_demand_s{simpl}_{clusters}.csv",
|
||||
transport_data="resources/transport_data_s{simpl}_{clusters}.csv",
|
||||
avail_profile="resources/avail_profile_s{simpl}_{clusters}.csv",
|
||||
dsm_profile="resources/dsm_profile_s{simpl}_{clusters}.csv",
|
||||
co2_totals_name='resources/co2_totals.csv',
|
||||
co2="data/eea/UNFCCC_v23.csv",
|
||||
biomass_potentials='resources/biomass_potentials_s{simpl}_{clusters}.csv',
|
||||
heat_profile="data/heat_load_profile_BDEW.csv",
|
||||
costs=CDIR + "costs_{planning_horizons}.csv",
|
||||
@ -568,7 +570,8 @@ rule plot_summary:
|
||||
input:
|
||||
costs=SDIR + '/csvs/costs.csv',
|
||||
energy=SDIR + '/csvs/energy.csv',
|
||||
balances=SDIR + '/csvs/supply_energy.csv'
|
||||
balances=SDIR + '/csvs/supply_energy.csv',
|
||||
clustered_pop_layout="resources/pop_layout_elec_s{simpl}_{clusters}.csv",
|
||||
output:
|
||||
costs=SDIR + '/graphs/costs.pdf',
|
||||
energy=SDIR + '/graphs/energy.pdf',
|
||||
|
@ -127,17 +127,16 @@ to_ipcc = {
|
||||
}
|
||||
|
||||
|
||||
def build_eurostat(countries, year):
|
||||
def build_eurostat(input_eurostat, countries, report_year, year):
|
||||
"""Return multi-index for all countries' energy data in TWh/a."""
|
||||
|
||||
report_year = snakemake.config["energy"]["eurostat_report_year"]
|
||||
filenames = {
|
||||
2016: f"/{year}-Energy-Balances-June2016edition.xlsx",
|
||||
2017: f"/{year}-ENERGY-BALANCES-June2017edition.xlsx"
|
||||
}
|
||||
|
||||
dfs = pd.read_excel(
|
||||
snakemake.input.eurostat + filenames[report_year],
|
||||
input_eurostat + filenames[report_year],
|
||||
sheet_name=None,
|
||||
skiprows=1,
|
||||
index_col=list(range(4)),
|
||||
@ -563,18 +562,18 @@ def build_energy_totals(countries, eurostat, swiss, idees):
|
||||
return df
|
||||
|
||||
|
||||
def build_eea_co2(year=1990):
|
||||
def build_eea_co2(input_co2, year=1990, emissions_scope="CO2"):
|
||||
|
||||
# https://www.eea.europa.eu/data-and-maps/data/national-emissions-reported-to-the-unfccc-and-to-the-eu-greenhouse-gas-monitoring-mechanism-16
|
||||
# downloaded 201228 (modified by EEA last on 201221)
|
||||
df = pd.read_csv(snakemake.input.co2, encoding="latin-1")
|
||||
df = pd.read_csv(input_co2, encoding="latin-1")
|
||||
|
||||
df.replace(dict(Year="1985-1987"), 1986, inplace=True)
|
||||
df.Year = df.Year.astype(int)
|
||||
index_col = ["Country_code", "Pollutant_name", "Year", "Sector_name"]
|
||||
df = df.set_index(index_col).sort_index()
|
||||
|
||||
emissions_scope = snakemake.config["energy"]["emissions"]
|
||||
emissions_scope = emissions_scope
|
||||
|
||||
cts = ["CH", "EUA", "NO"] + eu28_eea
|
||||
|
||||
@ -611,9 +610,9 @@ def build_eea_co2(year=1990):
|
||||
return emissions / 1e3
|
||||
|
||||
|
||||
def build_eurostat_co2(countries, year=1990):
|
||||
def build_eurostat_co2(input_eurostat, countries, report_year, year=1990):
|
||||
|
||||
eurostat = build_eurostat(countries, year)
|
||||
eurostat = build_eurostat(input_eurostat, countries, report_year, year)
|
||||
|
||||
specific_emissions = pd.Series(index=eurostat.columns, dtype=float)
|
||||
|
||||
@ -702,7 +701,9 @@ if __name__ == "__main__":
|
||||
idees_countries = countries.intersection(eu28)
|
||||
|
||||
data_year = config["energy_totals_year"]
|
||||
eurostat = build_eurostat(countries, data_year)
|
||||
report_year = snakemake.config["energy"]["eurostat_report_year"]
|
||||
input_eurostat = snakemake.input.eurostat
|
||||
eurostat = build_eurostat(input_eurostat, countries, report_year, data_year)
|
||||
swiss = build_swiss(data_year)
|
||||
idees = build_idees(idees_countries, data_year)
|
||||
|
||||
@ -710,8 +711,9 @@ if __name__ == "__main__":
|
||||
energy.to_csv(snakemake.output.energy_name)
|
||||
|
||||
base_year_emissions = config["base_emissions_year"]
|
||||
eea_co2 = build_eea_co2(base_year_emissions)
|
||||
eurostat_co2 = build_eurostat_co2(countries, base_year_emissions)
|
||||
emissions_scope = snakemake.config["energy"]["emissions"]
|
||||
eea_co2 = build_eea_co2(snakemake.input.co2, base_year_emissions, emissions_scope)
|
||||
eurostat_co2 = build_eurostat_co2(input_eurostat, countries, report_year, base_year_emissions)
|
||||
|
||||
co2 = build_co2_totals(countries, eea_co2, eurostat_co2)
|
||||
co2.to_csv(snakemake.output.co2_name)
|
||||
|
@ -158,21 +158,24 @@ def get(item, investment_year=None):
|
||||
return item
|
||||
|
||||
|
||||
def co2_emissions_year(countries, opts, year):
|
||||
def co2_emissions_year(opts, year):
|
||||
"""
|
||||
Calculate CO2 emissions in one specific year (e.g. 1990 or 2018).
|
||||
"""
|
||||
|
||||
eea_co2 = build_eea_co2(year)
|
||||
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(year=2014)
|
||||
eurostat_co2 = build_eurostat_co2(input_eurostat, countries, report_year, year=2014)
|
||||
else:
|
||||
eurostat_co2 = build_eurostat_co2(year)
|
||||
eurostat_co2 = build_eurostat_co2(input_eurostat, countries, report_year, year)
|
||||
|
||||
co2_totals = build_co2_totals(eea_co2, eurostat_co2)
|
||||
co2_totals = build_co2_totals(countries, eea_co2, eurostat_co2)
|
||||
|
||||
sectors = emission_sectors_from_opts(opts)
|
||||
|
||||
@ -202,10 +205,10 @@ def build_carbon_budget(o, fn):
|
||||
|
||||
countries = n.buses.country.dropna().unique()
|
||||
|
||||
e_1990 = co2_emissions_year(countries, opts, year=1990)
|
||||
e_1990 = co2_emissions_year( opts, year=1990)
|
||||
|
||||
#emissions at the beginning of the path (last year available 2018)
|
||||
e_0 = co2_emissions_year(countries, opts, year=2018)
|
||||
e_0 = co2_emissions_year(opts, year=2018)
|
||||
|
||||
planning_horizons = snakemake.config['scenario']['planning_horizons']
|
||||
t_0 = planning_horizons[0]
|
||||
@ -233,8 +236,9 @@ def build_carbon_budget(o, fn):
|
||||
co2_cap = pd.Series({t: exponential_decay(t) for t in planning_horizons}, name=o)
|
||||
|
||||
# TODO log in Snakefile
|
||||
if not os.path.exists(fn):
|
||||
os.makedirs(fn)
|
||||
csvs_folder = fn.rsplit("/", 1)[0]
|
||||
if not os.path.exists(csvs_folder):
|
||||
os.makedirs(csvs_folder)
|
||||
co2_cap.to_csv(fn, float_format='%.3f')
|
||||
|
||||
|
||||
@ -2333,7 +2337,7 @@ if __name__ == "__main__":
|
||||
opts="",
|
||||
clusters="37",
|
||||
lv=1.5,
|
||||
sector_opts='Co2L0-168H-T-H-B-I-solar3-dist1',
|
||||
sector_opts='cb40ex0-365H-T-H-B-I-A-solar+p3-dist1',
|
||||
planning_horizons="2020",
|
||||
)
|
||||
|
||||
@ -2439,7 +2443,7 @@ if __name__ == "__main__":
|
||||
if not os.path.exists(fn):
|
||||
build_carbon_budget(o, fn)
|
||||
co2_cap = pd.read_csv(fn, index_col=0).squeeze()
|
||||
limit = co2_cap[investment_year]
|
||||
limit = co2_cap.loc[investment_year]
|
||||
break
|
||||
for o in opts:
|
||||
if not "Co2L" in o: continue
|
||||
|
Loading…
Reference in New Issue
Block a user