Skip to content

Commit 6712692

Browse files
authored
Merge pull request #239 from iiasa/ssp-dev-mm
Add scripts to modify "Low" and "Very Low" ScenarioMIP/SSP scenarios
2 parents d1004ff + 4fd9173 commit 6712692

File tree

8 files changed

+801
-0
lines changed

8 files changed

+801
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:20766b4dda378f9bc44879ff70b4f5fa9c4d6e0c0e467e157b0e8b00812f44f3
3+
size 17460
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:44fd66b543a316fb3a837d4a70d64262a416074fd230dc85e5ecf4b62614f516
3+
size 17546

message_ix_models/project/ssp/script/__init__.py

Whitespace-only changes.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import ixmp # type: ignore
2+
import message_ix # type: ignore
3+
4+
from message_ix_models.project.ssp.script.util.functions import (
5+
add_balance_equality,
6+
add_steel_sector_nze,
7+
modify_steel_growth,
8+
modify_steel_initial,
9+
remove_bof_steel_lower,
10+
)
11+
12+
# selections
13+
sel_scen = "SSP1"
14+
scen_suffix = ""
15+
rem_bof_steel = True
16+
mod_growth_steel = True
17+
mod_initial_steel = True
18+
add_steel_target = False
19+
20+
# parameters
21+
trp_year_start = 2035
22+
mult_price = 5.5
23+
rc_years = [2060, 2070, 2080, 2090, 2100, 2110]
24+
steel_years = [2030, 2035, 2040, 2045, 2050, 2055, 2060, 2070, 2080, 2090, 2100, 2110]
25+
steel_growth = 0.075
26+
steel_inital = 1.0
27+
nze_targets = [
28+
4.2,
29+
3.7,
30+
3.2,
31+
2.7,
32+
]
33+
34+
# model and scenario names
35+
snames = {"SSP1": "SSP1 - Low Emissions", "SSP2": "SSP2 - Low Emissions"}
36+
svers = {"SSP1": 1, "SSP2": 1}
37+
model_orig = "SSP_" + sel_scen + "_v1.0"
38+
scenario_orig = snames[sel_scen]
39+
40+
if rem_bof_steel:
41+
scen_suffix += "_bof"
42+
if mod_growth_steel:
43+
scen_suffix += "_growth"
44+
if mod_initial_steel:
45+
scen_suffix += "_initial"
46+
if add_steel_target:
47+
scen_suffix += "_nzsteel"
48+
49+
# target scenario
50+
model_target = "MM_ScenarioMIP"
51+
scenario_target = "Low_" + sel_scen + scen_suffix # + "_v" + str(scen_vers)
52+
53+
# connect to database
54+
mp = ixmp.Platform("ixmp_dev")
55+
56+
# load scenario
57+
s_orig = message_ix.Scenario(
58+
mp, model=model_orig, scenario=scenario_orig, version=svers[sel_scen]
59+
)
60+
61+
# clone scenario
62+
s_tar = s_orig.clone(model_target, scenario_target, keep_solution=False)
63+
s_tar.set_as_default()
64+
65+
# modify steel sector
66+
if rem_bof_steel:
67+
remove_bof_steel_lower(s_tar, steel_years)
68+
69+
if mod_growth_steel:
70+
modify_steel_growth(
71+
s_tar,
72+
["dri_gas_steel", "dri_h2_steel", "eaf_steel"],
73+
steel_years,
74+
steel_growth,
75+
)
76+
77+
if mod_initial_steel:
78+
modify_steel_initial(
79+
s_tar,
80+
["dri_gas_steel", "dri_h2_steel"],
81+
steel_years,
82+
steel_inital,
83+
)
84+
85+
if add_steel_target:
86+
add_steel_sector_nze(s_tar, nze_targets)
87+
88+
# add balance equality
89+
add_balance_equality(s_tar)
90+
91+
solve_typ = "MESSAGE-MACRO"
92+
solve_args = dict(model=solve_typ)
93+
s_tar.solve(**solve_args)
94+
s_tar.set_as_default()
95+
96+
mp.close_db()
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import os
2+
3+
import ixmp # type: ignore
4+
import message_ix # type: ignore
5+
6+
from message_ix_models.project.ssp.script.util.functions import (
7+
add_balance_equality,
8+
add_steel_sector_nze,
9+
modify_rc_bounds,
10+
modify_steel_growth,
11+
modify_steel_initial,
12+
modify_tax_emission,
13+
remove_bof_steel_lower,
14+
)
15+
from message_ix_models.project.ssp.script.util.shares import (
16+
main as add_UE_share_constraints,
17+
)
18+
from message_ix_models.util import package_data_path
19+
20+
# selections
21+
sel_scen = "LED"
22+
scen_suffix = "g05_e9"
23+
rem_bof_steel = True
24+
mod_growth_steel = True
25+
mod_initial_steel = True
26+
add_steel_target = False
27+
file_ue = "trp_gas0.05_elec0.9.xlsx"
28+
29+
# parameters
30+
trp_year_start = 2035
31+
mult_price = 5.5
32+
rc_years = [2060, 2070, 2080, 2090, 2100, 2110]
33+
steel_years = [2030, 2035, 2040, 2045, 2050, 2055, 2060, 2070, 2080, 2090, 2100, 2110]
34+
steel_growth = 0.075
35+
steel_inital = 1.0
36+
nze_targets = [
37+
0,
38+
0,
39+
0,
40+
0,
41+
]
42+
43+
# scenario names
44+
snames = {"SSP1": "SSP1 - Very Low Emissions", "LED": "SSP2 - Very Low Emissions"}
45+
svers = {"SSP1": 1, "LED": 2}
46+
model_orig = "SSP_" + sel_scen + "_v1.0"
47+
scenario_orig = snames[sel_scen]
48+
49+
if rem_bof_steel:
50+
scen_suffix += "_bof"
51+
if mod_growth_steel:
52+
scen_suffix += "_growth"
53+
if mod_initial_steel:
54+
scen_suffix += "_initial"
55+
if add_steel_target:
56+
scen_suffix += "_nzsteel"
57+
58+
# read UE share file
59+
path_ue = package_data_path("ue-shares")
60+
path_ue_file = os.path.join(path_ue, file_ue)
61+
62+
# target scenario
63+
model_target = "MM_ScenarioMIP"
64+
scenario_target = "VL_" + sel_scen + "_" + scen_suffix
65+
66+
# connect to database
67+
mp = ixmp.Platform("ixmp_dev")
68+
69+
# load scenario
70+
s_orig = message_ix.Scenario(
71+
mp, model=model_orig, scenario=scenario_orig, version=svers[sel_scen]
72+
)
73+
74+
# clone scenario
75+
s_tar = s_orig.clone(model_target, scenario_target, keep_solution=False)
76+
s_tar.set_as_default()
77+
78+
# modify bounds for some fuels in residential and commercial sector
79+
modify_rc_bounds(s_orig, s_tar, rc_years)
80+
81+
# add UE share constraints to transport
82+
add_UE_share_constraints(
83+
s_tar, # scenario object
84+
path_UE_share_input=path_ue_file, # path
85+
ssp=sel_scen, # SSP-name i.e "LED"
86+
start_year=trp_year_start, # the year as of which a constraint should be added
87+
calibration_year=2020, # 2020
88+
clean_relations=False, # set to False
89+
verbose=True, # set to True
90+
)
91+
92+
# modify tax/price emissions
93+
modify_tax_emission(s_orig, s_tar, mult_price)
94+
95+
# modify steel sector
96+
if rem_bof_steel:
97+
remove_bof_steel_lower(s_tar, steel_years)
98+
99+
if mod_growth_steel:
100+
modify_steel_growth(
101+
s_tar,
102+
["dri_gas_steel", "dri_h2_steel", "eaf_steel"],
103+
steel_years,
104+
steel_growth,
105+
)
106+
107+
if mod_initial_steel:
108+
modify_steel_initial(
109+
s_tar,
110+
["dri_gas_steel", "dri_h2_steel"],
111+
steel_years,
112+
steel_inital,
113+
)
114+
115+
if add_steel_target:
116+
add_steel_sector_nze(s_tar, nze_targets)
117+
118+
# add balance equality
119+
add_balance_equality(s_tar)
120+
121+
# solve
122+
solve_typ = "MESSAGE-MACRO"
123+
solve_args = dict(model=solve_typ)
124+
s_tar.solve(**solve_args)
125+
s_tar.set_as_default()
126+
127+
mp.close_db()

message_ix_models/project/ssp/script/util/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)