build industrial demand/production: ensure compat with multiprocesses on win/mac
This commit is contained in:
parent
2a5acedfee
commit
5260e0c71f
@ -90,7 +90,7 @@ eu28 = [
|
|||||||
jrc_names = {"GR": "EL", "GB": "UK"}
|
jrc_names = {"GR": "EL", "GB": "UK"}
|
||||||
|
|
||||||
|
|
||||||
def industrial_energy_demand_per_country(country, jrc_dir):
|
def industrial_energy_demand_per_country(country, year, jrc_dir):
|
||||||
jrc_country = jrc_names.get(country, country)
|
jrc_country = jrc_names.get(country, country)
|
||||||
fn = f"{jrc_dir}/JRC-IDEES-2015_EnergyBalance_{jrc_country}.xlsx"
|
fn = f"{jrc_dir}/JRC-IDEES-2015_EnergyBalance_{jrc_country}.xlsx"
|
||||||
|
|
||||||
@ -177,9 +177,9 @@ def add_non_eu28_industrial_energy_demand(demand):
|
|||||||
return pd.concat([demand, demand_non_eu28])
|
return pd.concat([demand, demand_non_eu28])
|
||||||
|
|
||||||
|
|
||||||
def industrial_energy_demand(countries):
|
def industrial_energy_demand(countries, year):
|
||||||
nprocesses = snakemake.threads
|
nprocesses = snakemake.threads
|
||||||
func = partial(industrial_energy_demand_per_country, jrc_dir=snakemake.input.jrc)
|
func = partial(industrial_energy_demand_per_country, year=year, jrc_dir=snakemake.input.jrc)
|
||||||
tqdm_kwargs = dict(
|
tqdm_kwargs = dict(
|
||||||
ascii=False,
|
ascii=False,
|
||||||
unit=" country",
|
unit=" country",
|
||||||
@ -203,7 +203,7 @@ if __name__ == "__main__":
|
|||||||
config = snakemake.config["industry"]
|
config = snakemake.config["industry"]
|
||||||
year = config.get("reference_year", 2015)
|
year = config.get("reference_year", 2015)
|
||||||
|
|
||||||
demand = industrial_energy_demand(eu28)
|
demand = industrial_energy_demand(eu28, year)
|
||||||
|
|
||||||
demand = add_ammonia_energy_demand(demand)
|
demand = add_ammonia_energy_demand(demand)
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ def find_physical_output(df):
|
|||||||
return slice(start, end)
|
return slice(start, end)
|
||||||
|
|
||||||
|
|
||||||
def get_energy_ratio(country, eurostat_dir, jrc_dir):
|
def get_energy_ratio(country, eurostat_dir, jrc_dir, year):
|
||||||
if country == "CH":
|
if country == "CH":
|
||||||
e_country = e_switzerland * tj_to_ktoe
|
e_country = e_switzerland * tj_to_ktoe
|
||||||
else:
|
else:
|
||||||
@ -215,7 +215,7 @@ def get_energy_ratio(country, eurostat_dir, jrc_dir):
|
|||||||
return pd.Series({k: e_ratio[v] for k, v in sub2sect.items()})
|
return pd.Series({k: e_ratio[v] for k, v in sub2sect.items()})
|
||||||
|
|
||||||
|
|
||||||
def industry_production_per_country(country, eurostat_dir, jrc_dir):
|
def industry_production_per_country(country, year, eurostat_dir, jrc_dir):
|
||||||
def get_sector_data(sector, country):
|
def get_sector_data(sector, country):
|
||||||
jrc_country = jrc_names.get(country, country)
|
jrc_country = jrc_names.get(country, country)
|
||||||
fn = f"{jrc_dir}/JRC-IDEES-2015_Industry_{jrc_country}.xlsx"
|
fn = f"{jrc_dir}/JRC-IDEES-2015_Industry_{jrc_country}.xlsx"
|
||||||
@ -237,17 +237,17 @@ def industry_production_per_country(country, eurostat_dir, jrc_dir):
|
|||||||
demand = pd.concat([get_sector_data(s, ct) for s in sect2sub.keys()])
|
demand = pd.concat([get_sector_data(s, ct) for s in sect2sub.keys()])
|
||||||
|
|
||||||
if country in non_EU:
|
if country in non_EU:
|
||||||
demand *= get_energy_ratio(country, eurostat_dir, jrc_dir)
|
demand *= get_energy_ratio(country, eurostat_dir, jrc_dir, year)
|
||||||
|
|
||||||
demand.name = country
|
demand.name = country
|
||||||
|
|
||||||
return demand
|
return demand
|
||||||
|
|
||||||
|
|
||||||
def industry_production(countries, eurostat_dir, jrc_dir):
|
def industry_production(countries, year, eurostat_dir, jrc_dir):
|
||||||
nprocesses = 1 # snakemake.threads
|
nprocesses = 1 # snakemake.threads
|
||||||
func = partial(
|
func = partial(
|
||||||
industry_production_per_country, eurostat_dir=eurostat_dir, jrc_dir=jrc_dir
|
industry_production_per_country, year=year, eurostat_dir=eurostat_dir, jrc_dir=jrc_dir
|
||||||
)
|
)
|
||||||
tqdm_kwargs = dict(
|
tqdm_kwargs = dict(
|
||||||
ascii=False,
|
ascii=False,
|
||||||
@ -265,7 +265,7 @@ def industry_production(countries, eurostat_dir, jrc_dir):
|
|||||||
return demand
|
return demand
|
||||||
|
|
||||||
|
|
||||||
def separate_basic_chemicals(demand):
|
def separate_basic_chemicals(demand, year):
|
||||||
"""
|
"""
|
||||||
Separate basic chemicals into ammonia, chlorine, methanol and HVC.
|
Separate basic chemicals into ammonia, chlorine, methanol and HVC.
|
||||||
"""
|
"""
|
||||||
@ -312,9 +312,9 @@ if __name__ == "__main__":
|
|||||||
jrc_dir = snakemake.input.jrc
|
jrc_dir = snakemake.input.jrc
|
||||||
eurostat_dir = snakemake.input.eurostat
|
eurostat_dir = snakemake.input.eurostat
|
||||||
|
|
||||||
demand = industry_production(countries, eurostat_dir, jrc_dir)
|
demand = industry_production(countries, year, eurostat_dir, jrc_dir)
|
||||||
|
|
||||||
separate_basic_chemicals(demand)
|
separate_basic_chemicals(demand, year)
|
||||||
|
|
||||||
fn = snakemake.output.industrial_production_per_country
|
fn = snakemake.output.industrial_production_per_country
|
||||||
demand.to_csv(fn, float_format="%.2f")
|
demand.to_csv(fn, float_format="%.2f")
|
||||||
|
Loading…
Reference in New Issue
Block a user