Skip to content

Commit 8296b5d

Browse files
macflo8khaeru
authored andcommitted
Extend methanol fs downstream supply chain
* Add additional technology "meth_fs_ind" between meth_t_d and demand * Move CO2_Emision from "steam_craker_petro" and "meth_t_d" to "production_HVC" and "meth_fs_ind"
1 parent 1ce240d commit 8296b5d

File tree

7 files changed

+78
-28
lines changed

7 files changed

+78
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:61bee83deb171587bf1087a8689ae7401eac31692c200de7a8be78e9c56b3933
3-
size 619006
2+
oid sha256:c2a06bb96944e11c097ce01187fb4a69e0553d973aad35f256bd760b05be9c08
3+
size 611057

message_ix_models/data/material/set.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ methanol:
640640
- meth_trd
641641
- meth_exp
642642
- meth_imp
643+
- meth_ind_fs
643644
remove:
644645
- sp_meth_I
645646
- meth_rc

message_ix_models/model/material/data_methanol_new.py

+54-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from message_ix import make_df
77

88
import message_ix_models.util
9+
from message_ix_models import ScenarioInfo
10+
from message_ix_models.model.material.data_util import gen_plastics_emission_factors
911
from message_ix_models.model.material.material_demand import material_demand_calc
10-
from message_ix_models.model.material.util import read_config
12+
from message_ix_models.model.material.util import combine_df_dictionaries, read_config
1113
from message_ix_models.util import broadcast, same_node
1214

1315
if TYPE_CHECKING:
@@ -88,6 +90,13 @@ def gen_data_methanol_new(scenario: "Scenario") -> Dict[str, pd.DataFrame]:
8890
)
8991
pars_dict["demand"] = df_final
9092

93+
s_info = ScenarioInfo(scenario)
94+
downstream_tec_pars = gen_meth_fs_downstream(s_info)
95+
meth_downstream_emi = gen_plastics_emission_factors(s_info, "methanol")
96+
pars_dict = combine_df_dictionaries(
97+
pars_dict, downstream_tec_pars, meth_downstream_emi
98+
)
99+
91100
scen_rel_set = scenario.set("relation")
92101
for par in ["activity", "upper", "lower"]:
93102
df_rel = pars_dict[f"relation_{par}"]
@@ -270,3 +279,47 @@ def unpivot_input_data(df: pd.DataFrame, par_name: str):
270279
].index
271280
)
272281
return make_df(par_name, **df_final_full)
282+
283+
284+
def gen_meth_fs_downstream(s_info: "ScenarioInfo") -> Dict[str, pd.DataFrame]:
285+
# input parameter
286+
yv_ya = s_info.yv_ya
287+
year_all = yv_ya["year_act"].unique()
288+
289+
tec_name = "meth_ind_fs"
290+
cols = {
291+
"technology": tec_name,
292+
"commodity": "methanol",
293+
"mode": "M1",
294+
"level": "final_material",
295+
"time": "year",
296+
"time_origin": "year",
297+
"value": 1,
298+
"unit": "Mt",
299+
}
300+
df_in = (
301+
make_df("input", **cols)
302+
.pipe(broadcast, node_loc=s_info.N, year_act=year_all)
303+
.pipe(same_node)
304+
)
305+
df_in["year_vtg"] = df_in["year_act"]
306+
307+
# output parameter
308+
tec_name = "meth_ind_fs"
309+
cols = {
310+
"technology": tec_name,
311+
"commodity": "methanol",
312+
"mode": "M1",
313+
"level": "demand",
314+
"time": "year",
315+
"time_dest": "year",
316+
"value": 1,
317+
"unit": "Mt",
318+
}
319+
df_out = (
320+
make_df("output", **cols)
321+
.pipe(broadcast, node_loc=s_info.N, year_act=year_all)
322+
.pipe(same_node)
323+
)
324+
df_out["year_vtg"] = df_out["year_act"]
325+
return dict(input=df_in, output=df_out)

message_ix_models/model/material/data_petro.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@
66
from message_ix import make_df
77

88
from message_ix_models import ScenarioInfo
9-
from message_ix_models.model.material.data_util import read_timeseries
9+
from message_ix_models.model.material.data_util import (
10+
gen_plastics_emission_factors,
11+
read_timeseries,
12+
)
1013
from message_ix_models.model.material.material_demand import material_demand_calc
11-
from message_ix_models.model.material.util import get_ssp_from_context, read_config
14+
from message_ix_models.model.material.util import (
15+
combine_df_dictionaries,
16+
get_ssp_from_context,
17+
read_config,
18+
)
1219
from message_ix_models.util import (
1320
broadcast,
1421
nodes_ex_world,
@@ -545,6 +552,9 @@ def gen_data_petro_chemicals(
545552
df["technology"] = "gas_processing_petro"
546553
results["relation_activity"] = df
547554

555+
meth_downstream_emi = gen_plastics_emission_factors(s_info, "HVCs")
556+
results = combine_df_dictionaries(results, meth_downstream_emi)
557+
548558
# TODO: move this to input xlsx file
549559
df_gro = results["growth_activity_up"]
550560
drop_idx = df_gro[

message_ix_models/model/material/data_util.py

+6-20
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,9 @@ def read_sector_data(
424424
list_ef = data_df[["Parameter", "Species", "Mode"]].apply(list, axis=1)
425425

426426
data_df["parameter"] = list_series.str.join("|")
427-
data_df.loc[
428-
data_df["Parameter"] == "emission_factor", "parameter"
429-
] = list_ef.str.join("|")
427+
data_df.loc[data_df["Parameter"] == "emission_factor", "parameter"] = (
428+
list_ef.str.join("|")
429+
)
430430

431431
data_df = data_df.drop(["Parameter", "Level", "Commodity", "Mode"], axis=1)
432432
data_df = data_df.drop(data_df[data_df.Value == ""].index)
@@ -1866,7 +1866,7 @@ def calibrate_for_SSPs(scenario: "Scenario") -> None:
18661866

18671867
def gen_plastics_emission_factors(
18681868
info, species: Literal["methanol", "HVCs"]
1869-
) -> pd.DataFrame:
1869+
) -> dict[str, pd.DataFrame]:
18701870
"""Generate "CO2_Emission" relation parameter that
18711871
represents stored carbon in produced plastics.
18721872
The calculation considers:
@@ -1890,12 +1890,8 @@ def gen_plastics_emission_factors(
18901890
pd.DataFrame
18911891
"""
18921892

1893-
if species != "HVCs":
1894-
raise NotImplementedError
1893+
tec_species_map = {"methanol": "meth_ind_fs", "HVCs": "production_HVC"}
18951894

1896-
tec_species_map = {"methanol": NotImplemented, "HVCs": "production_HVC"}
1897-
1898-
# TODO: do same calculation for methanol not used for MTO but other plastics
18991895
carbon_pars = read_yaml_file(
19001896
package_data_path(
19011897
"material", "petrochemicals", "chemicals_carbon_parameters.yaml"
@@ -1943,14 +1939,4 @@ def apply_eol_factor(row, pars):
19431939
co2_emi_rel["value"] = co2_emi_rel.apply(
19441940
lambda x: apply_eol_factor(x, end_of_life_pars), axis=1
19451941
).mul(-1)
1946-
return co2_emi_rel
1947-
1948-
1949-
if __name__ == "__main__":
1950-
from ixmp import Platform
1951-
from message_ix import Scenario
1952-
1953-
mp = Platform("ixmp_dev")
1954-
scen = Scenario(mp, "MESSAGEix-Materials", "test_c901_refactoring")
1955-
s_info = ScenarioInfo(scen)
1956-
gen_plastics_emission_factors(s_info, "methanol")
1942+
return {"relation_activity": co2_emi_rel}

message_ix_models/model/material/material_demand/material_demand_calc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def get_demand_t1_with_income_elasticity(
520520

521521
df_melt = df_demand.melt(ignore_index=False).reset_index()
522522

523-
level = "demand" if chemical == "HVC" else "final_material"
523+
level = "demand" if chemical in ["HVC", "methanol"] else "final_material"
524524

525525
return make_df(
526526
"demand",

message_ix_models/tests/model/material/test_data_util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ def test_map_iea_db_to_msg_regs() -> None:
132132
"species",
133133
[
134134
"HVCs",
135-
pytest.param("methanol", marks=pytest.mark.xfail(raises=NotImplementedError)),
135+
"methanol",
136136
],
137137
)
138138
def test_gen_plastics_emission_factors(species):
139139
info = ScenarioInfo()
140140
info.set["node"] = ["node0", "node1"]
141141
info.set["year"] = [2020, 2025]
142-
out = gen_plastics_emission_factors(info, "HVCs")
142+
out = gen_plastics_emission_factors(info, species)["relation_activity"]
143143

144144
assert not out.isna().any(axis=None) # Completely full
145145

0 commit comments

Comments
 (0)