[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
file at the path specified in fn.
"""
slicer = pd.IndexSlice[:,:,:, "Coke ovens", "Other sources", :]
df = eurostat.loc[slicer, :].droplevel(level=[2,3,4,5])
slicer = pd.IndexSlice[:, :, :, "Coke ovens", "Other sources", :]
df = eurostat.loc[slicer, :].droplevel(level=[2, 3, 4, 5])
df.to_csv(fn)
# %%
if __name__ == "__main__":
if "snakemake" not in globals():
@ -1524,8 +1525,9 @@ if __name__ == "__main__":
disable_progressbar=snakemake.config["run"].get("disable_progressbar", False),
)
build_transformation_output_coke(eurostat,
snakemake.output.transformation_output_coke)
build_transformation_output_coke(
eurostat, snakemake.output.transformation_output_coke
)
swiss = build_swiss()
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.
"""
df = pd.read_csv(fn, index_col=[0,1]).xs(year, level=1)
df = df.rename(columns={'Total all products':'Total'})[fuels.keys()]
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=fuels).T.groupby(level=0).sum().T
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)
sel = demand.columns.get_level_values(1)=="Integrated steelworks"
demand.loc[:,sel] += factor * df.values
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
)
sel = demand.columns.get_level_values(1) == "Integrated steelworks"
demand.loc[:, sel] += factor * df.values
return demand
@ -294,8 +296,7 @@ if __name__ == "__main__":
demand = demand.stack(future_stack=True).unstack(level=[0, 2])
# add energy consumption of coke ovens
demand = add_coke_ovens(demand, snakemake.input.transformation_output_coke,
year)
demand = add_coke_ovens(demand, snakemake.input.transformation_output_coke, year)
# style and annotation
demand.index.name = "TWh/a"