Skip to content

Commit d490a5f

Browse files
committed
Add updated aluminum activity calibration
1 parent 8416618 commit d490a5f

File tree

6 files changed

+126
-1
lines changed

6 files changed

+126
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:39d71fb24b6b9b292ee80564c0fc5cf68e897cdae9bb461c3f346aa58b5b5aad
3+
size 13247
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:a9e10491ab5987991f54c7c7afc5196d8d8987168f84019261466ee13a9cab48
3+
size 15122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:285542e66b342ca362ddbe4bb2d3a003ae64943043f76c28cdc095206a22df7e
3+
size 10484
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:3edf2080d7ffc809c025a77fb524ce34e9d2b27f99f312aa5145ebc68ca7372f
3+
size 10342
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:c98dfc193d16815f676e254298391a97bb30048f4a5e0718401e457b746d06b6
3+
size 15561

message_ix_models/model/material/data_aluminum.py

+111-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from collections import defaultdict
23
from collections.abc import Iterable
34

@@ -472,13 +473,15 @@ def gen_data_aluminum(
472473

473474
ts_dict = gen_data_alu_ts(data_aluminum_ts, nodes)
474475
ts_dict.update(gen_hist_new_cap())
476+
ts_dict = combine_df_dictionaries(ts_dict, gen_hist_act())
477+
475478
rel_dict = gen_data_alu_rel(data_aluminum_rel, modelyears)
479+
476480
trade_dict = gen_data_alu_trade(scenario)
477481

478482
results_aluminum = combine_df_dictionaries(
479483
const_dict, ts_dict, rel_dict, demand_dict, trade_dict
480484
)
481-
482485
return results_aluminum
483486

484487

@@ -830,3 +833,110 @@ def compute_differences(df, ref_col):
830833
ref_values = ref_values.where(df[col] <= ref_values, df[col])
831834

832835
return differences
836+
837+
838+
def load_bgs_data():
839+
bgs_data_path = package_data_path("material", "aluminum", "bgs_data")
840+
841+
dfs = []
842+
843+
for fname in os.listdir(bgs_data_path):
844+
if not fname.endswith(".xlsx"):
845+
continue
846+
# read and format BGS data
847+
df_prim = pd.read_excel(bgs_data_path + fname, skipfooter=9, skiprows=1)
848+
year_cols = df_prim.columns[2::2]
849+
df_prim = df_prim[
850+
[df_prim.columns.tolist()[0]] + df_prim.columns[3::2].tolist()
851+
]
852+
df_prim.columns = ["Country"] + [int(i) for i in year_cols]
853+
df_prim["ISO"] = df_prim["Country"].apply(
854+
lambda x: get_pycountry_iso(
855+
x,
856+
{
857+
"Turkey": "TUR",
858+
"Russia": "RUS",
859+
"Bosnia & Herzegovina": "BIH",
860+
"Czechoslovakia": "CSK",
861+
"German Democratic Rep": "DEU",
862+
"Korea (Rep. of)": "KOR",
863+
"Soviet Union": "RUS",
864+
"Korea, Dem. P.R. of": "PRK",
865+
"Serbia and Montenegro": "SRB",
866+
"Yugoslavia": "YUG",
867+
"German Federal Republic": "DEU",
868+
},
869+
)
870+
)
871+
df_prim.drop("Country", axis=1, inplace=True)
872+
for year in [i for i in df_prim.columns if isinstance(i, int)]:
873+
df_prim[year] = pd.to_numeric(df_prim[year], errors="coerce")
874+
dfs.append(df_prim)
875+
876+
df_prim = dfs[0].groupby("ISO").sum()
877+
for _df in dfs[1:]:
878+
df_prim = _df.groupby("ISO").sum().join(df_prim, how="outer")
879+
df_prim = df_prim.dropna(how="all")
880+
df_prim = df_prim[sorted(df_prim.columns)]
881+
882+
df_prim.reset_index(inplace=True)
883+
884+
# add R12 column
885+
df_prim = add_R12_column(
886+
df_prim.rename(columns={"ISO": "COUNTRY"}),
887+
package_data_path("node", "R12_worldsteel.yaml"),
888+
)
889+
df_prim.rename(columns={"COUNTRY": "ISO"}, inplace=True)
890+
891+
return df_prim
892+
893+
894+
def gen_hist_act():
895+
df_prim = load_bgs_data()
896+
df_prim_r12 = df_prim.groupby("R12").sum(numeric_only=True).div(10**6)
897+
898+
# Soderberg
899+
df_ss_act = df_prim_r12[[2015, 2020]].copy(deep=True)
900+
# calculate historical production with soderberg electrodes in the only 3 regions
901+
# that still have soderberg capacity (based on capacity data from genisim)
902+
df_ss_act.loc["R12_WEU"] *= 0.025
903+
df_ss_act.loc["R12_LAM"] *= 0.25
904+
df_ss_act.loc["R12_FSU"] *= 0.65
905+
df_ss_act.loc[["R12_FSU", "R12_LAM", "R12_WEU"]]
906+
df_ss_act = (
907+
df_ss_act.reset_index()
908+
.rename(columns={"R12": "node_loc"})
909+
.melt(id_vars="node_loc", var_name="year_act")
910+
)
911+
df_ss_act = df_ss_act.assign(
912+
technology="soderberg_aluminum", mode="M1", time="year", unit="Mt/yr"
913+
)
914+
df_ss_act = make_df("historical_activity", **df_ss_act)
915+
916+
# Prebake
917+
df_pb_act = df_prim_r12[[2015, 2020]].copy(deep=True)
918+
# deduct historical production with soderberg electrodes in the only 3 regions that
919+
# still have soderberg capacity (based on capacity data from genisim) to get
920+
# production with prebaked electrodes
921+
df_pb_act.loc["R12_WEU"] *= 1 - 0.025
922+
df_pb_act.loc["R12_LAM"] *= 1 - 0.25
923+
df_pb_act.loc["R12_FSU"] *= 1 - 0.65
924+
df_pb_act = (
925+
df_pb_act.reset_index()
926+
.rename(columns={"R12": "node_loc"})
927+
.melt(id_vars="node_loc", var_name="year_act")
928+
)
929+
df_pb_act = df_pb_act.assign(
930+
technology="prebake_aluminum", mode="M1", time="year", unit="Mt/yr"
931+
)
932+
df_pb_act = make_df("historical_activity", **df_pb_act)
933+
934+
par_dict = {}
935+
par_dict["bound_activity_up"] = pd.concat(
936+
[
937+
df_pb_act[df_pb_act["year_act"] == 2020],
938+
df_ss_act[df_ss_act["year_act"] == 2020],
939+
]
940+
)
941+
par_dict["bound_activity_lo"] = par_dict["bound_activity_up"].copy(deep=True)
942+
return par_dict

0 commit comments

Comments
 (0)