Skip to content

Commit 18be96c

Browse files
macflo8khaeru
authored andcommitted
Add updated aluminum activity calibration
1 parent 9acc71d commit 18be96c

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

@@ -469,13 +470,15 @@ def gen_data_aluminum(
469470

470471
ts_dict = gen_data_alu_ts(data_aluminum_ts, nodes)
471472
ts_dict.update(gen_hist_new_cap())
473+
ts_dict = combine_df_dictionaries(ts_dict, gen_hist_act())
474+
472475
rel_dict = gen_data_alu_rel(data_aluminum_rel, modelyears)
476+
473477
trade_dict = gen_data_alu_trade(scenario)
474478

475479
results_aluminum = combine_df_dictionaries(
476480
const_dict, ts_dict, rel_dict, demand_dict, trade_dict
477481
)
478-
479482
return results_aluminum
480483

481484

@@ -827,3 +830,110 @@ def compute_differences(df, ref_col):
827830
ref_values = ref_values.where(df[col] <= ref_values, df[col])
828831

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

0 commit comments

Comments
 (0)