make build_eurostat independent of snakemake object to be imported
This commit is contained in:
parent
41bfcf4068
commit
a2f97ad1b3
@ -84,22 +84,19 @@ def eurostat_per_country(input_eurostat, country):
|
|||||||
return pd.concat(sheet)
|
return pd.concat(sheet)
|
||||||
|
|
||||||
|
|
||||||
def build_eurostat(input_eurostat, countries):
|
def build_eurostat(input_eurostat, countries, nprocesses=1, disable_progressbar=False):
|
||||||
"""
|
"""
|
||||||
Return multi-index for all countries' energy data in TWh/a.
|
Return multi-index for all countries' energy data in TWh/a.
|
||||||
"""
|
"""
|
||||||
countries = {idees_rename.get(country, country) for country in countries} - {"CH"}
|
countries = {idees_rename.get(country, country) for country in countries} - {"CH"}
|
||||||
|
|
||||||
nprocesses = snakemake.threads
|
|
||||||
disable_progress = snakemake.config["run"].get("disable_progressbar", False)
|
|
||||||
|
|
||||||
func = partial(eurostat_per_country, input_eurostat)
|
func = partial(eurostat_per_country, input_eurostat)
|
||||||
tqdm_kwargs = dict(
|
tqdm_kwargs = dict(
|
||||||
ascii=False,
|
ascii=False,
|
||||||
unit=" country",
|
unit=" country",
|
||||||
total=len(countries),
|
total=len(countries),
|
||||||
desc="Build from eurostat database",
|
desc="Build from eurostat database",
|
||||||
disable=disable_progress,
|
disable=disable_progressbar,
|
||||||
)
|
)
|
||||||
with mute_print():
|
with mute_print():
|
||||||
with mp.Pool(processes=nprocesses) as pool:
|
with mp.Pool(processes=nprocesses) as pool:
|
||||||
@ -953,7 +950,12 @@ if __name__ == "__main__":
|
|||||||
idees_countries = pd.Index(countries).intersection(eu28)
|
idees_countries = pd.Index(countries).intersection(eu28)
|
||||||
|
|
||||||
input_eurostat = snakemake.input.eurostat
|
input_eurostat = snakemake.input.eurostat
|
||||||
eurostat = build_eurostat(input_eurostat, countries)
|
eurostat = build_eurostat(
|
||||||
|
input_eurostat,
|
||||||
|
countries,
|
||||||
|
nprocesses=snakemake.threads,
|
||||||
|
disable_progressbar=snakemake.config["run"].get("disable_progressbar", False),
|
||||||
|
)
|
||||||
swiss = build_swiss()
|
swiss = build_swiss()
|
||||||
idees = build_idees(idees_countries)
|
idees = build_idees(idees_countries)
|
||||||
|
|
||||||
|
@ -23,7 +23,12 @@ from _helpers import (
|
|||||||
update_config_from_wildcards,
|
update_config_from_wildcards,
|
||||||
)
|
)
|
||||||
from add_electricity import calculate_annuity, sanitize_carriers, sanitize_locations
|
from add_electricity import calculate_annuity, sanitize_carriers, sanitize_locations
|
||||||
from build_energy_totals import build_co2_totals, build_eea_co2, build_eurostat_co2
|
from build_energy_totals import (
|
||||||
|
build_co2_totals,
|
||||||
|
build_eea_co2,
|
||||||
|
build_eurostat,
|
||||||
|
build_eurostat_co2,
|
||||||
|
)
|
||||||
from networkx.algorithms import complement
|
from networkx.algorithms import complement
|
||||||
from networkx.algorithms.connectivity.edge_augmentation import k_edge_augmentation
|
from networkx.algorithms.connectivity.edge_augmentation import k_edge_augmentation
|
||||||
from prepare_network import maybe_adjust_costs_and_potentials
|
from prepare_network import maybe_adjust_costs_and_potentials
|
||||||
@ -255,12 +260,10 @@ def co2_emissions_year(
|
|||||||
"""
|
"""
|
||||||
eea_co2 = build_eea_co2(input_co2, year, emissions_scope)
|
eea_co2 = build_eea_co2(input_co2, year, emissions_scope)
|
||||||
|
|
||||||
# TODO: read Eurostat data from year > 2014
|
eurostat = build_eurostat(input_eurostat, countries)
|
||||||
|
|
||||||
# this only affects the estimation of CO2 emissions for BA, RS, AL, ME, MK
|
# this only affects the estimation of CO2 emissions for BA, RS, AL, ME, MK
|
||||||
if year > 2014:
|
eurostat_co2 = build_eurostat_co2(eurostat, year)
|
||||||
eurostat_co2 = build_eurostat_co2(input_eurostat, countries, 2014)
|
|
||||||
else:
|
|
||||||
eurostat_co2 = build_eurostat_co2(input_eurostat, countries, year)
|
|
||||||
|
|
||||||
co2_totals = build_co2_totals(countries, eea_co2, eurostat_co2)
|
co2_totals = build_co2_totals(countries, eea_co2, eurostat_co2)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user