|
| 1 | +import os |
1 | 2 | from collections import defaultdict
|
2 | 3 | from collections.abc import Iterable
|
3 | 4 |
|
@@ -469,13 +470,15 @@ def gen_data_aluminum(
|
469 | 470 |
|
470 | 471 | ts_dict = gen_data_alu_ts(data_aluminum_ts, nodes)
|
471 | 472 | ts_dict.update(gen_hist_new_cap())
|
| 473 | + ts_dict = combine_df_dictionaries(ts_dict, gen_hist_act()) |
| 474 | + |
472 | 475 | rel_dict = gen_data_alu_rel(data_aluminum_rel, modelyears)
|
| 476 | + |
473 | 477 | trade_dict = gen_data_alu_trade(scenario)
|
474 | 478 |
|
475 | 479 | results_aluminum = combine_df_dictionaries(
|
476 | 480 | const_dict, ts_dict, rel_dict, demand_dict, trade_dict
|
477 | 481 | )
|
478 |
| - |
479 | 482 | return results_aluminum
|
480 | 483 |
|
481 | 484 |
|
@@ -827,3 +830,110 @@ def compute_differences(df, ref_col):
|
827 | 830 | ref_values = ref_values.where(df[col] <= ref_values, df[col])
|
828 | 831 |
|
829 | 832 | 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