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