[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-08-09 12:24:36 +00:00
parent 9b8139abbe
commit 156eccefb7
2 changed files with 29 additions and 26 deletions

View File

@ -1494,10 +1494,11 @@ def build_transformation_output_coke(eurostat, fn):
The resulting transformation output data for coke ovens is saved as a CSV The resulting transformation output data for coke ovens is saved as a CSV
file at the path specified in fn. file at the path specified in fn.
""" """
slicer = pd.IndexSlice[:,:,:, "Coke ovens", "Other sources", :] slicer = pd.IndexSlice[:, :, :, "Coke ovens", "Other sources", :]
df = eurostat.loc[slicer, :].droplevel(level=[2,3,4,5]) df = eurostat.loc[slicer, :].droplevel(level=[2, 3, 4, 5])
df.to_csv(fn) df.to_csv(fn)
# %% # %%
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
@ -1524,8 +1525,9 @@ if __name__ == "__main__":
disable_progressbar=snakemake.config["run"].get("disable_progressbar", False), disable_progressbar=snakemake.config["run"].get("disable_progressbar", False),
) )
build_transformation_output_coke(eurostat, build_transformation_output_coke(
snakemake.output.transformation_output_coke) eurostat, snakemake.output.transformation_output_coke
)
swiss = build_swiss() swiss = build_swiss()
idees = build_idees(idees_countries) idees = build_idees(idees_countries)

View File

@ -256,13 +256,15 @@ def add_coke_ovens(demand, fn, year, factor=0.75):
consumption added to the integrated steelworks energy demand. consumption added to the integrated steelworks energy demand.
""" """
df = pd.read_csv(fn, index_col=[0,1]).xs(year, level=1) df = pd.read_csv(fn, index_col=[0, 1]).xs(year, level=1)
df = df.rename(columns={'Total all products':'Total'})[fuels.keys()] df = df.rename(columns={"Total all products": "Total"})[fuels.keys()]
df = df.rename(columns=fuels).T.groupby(level=0).sum().T df = df.rename(columns=fuels).T.groupby(level=0).sum().T
df["other"] = df["all"] - df.loc[:,df.columns != "all"].sum(axis=1) df["other"] = df["all"] - df.loc[:, df.columns != "all"].sum(axis=1)
df = df.T.reindex_like(demand.xs("Integrated steelworks", axis=1, level=1)).fillna(0) df = df.T.reindex_like(demand.xs("Integrated steelworks", axis=1, level=1)).fillna(
sel = demand.columns.get_level_values(1)=="Integrated steelworks" 0
demand.loc[:,sel] += factor * df.values )
sel = demand.columns.get_level_values(1) == "Integrated steelworks"
demand.loc[:, sel] += factor * df.values
return demand return demand
@ -294,8 +296,7 @@ if __name__ == "__main__":
demand = demand.stack(future_stack=True).unstack(level=[0, 2]) demand = demand.stack(future_stack=True).unstack(level=[0, 2])
# add energy consumption of coke ovens # add energy consumption of coke ovens
demand = add_coke_ovens(demand, snakemake.input.transformation_output_coke, demand = add_coke_ovens(demand, snakemake.input.transformation_output_coke, year)
year)
# style and annotation # style and annotation
demand.index.name = "TWh/a" demand.index.name = "TWh/a"