Skip to content

Commit a2f768b

Browse files
authored
Merge pull request #249 from iiasa/ssp-dev_dac-ywp
update data reading in add_tech function
2 parents fd9485c + 795a0c5 commit a2f768b

File tree

2 files changed

+14
-68
lines changed

2 files changed

+14
-68
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from message_ix_models.tools.add_dac import add_tech
99
from message_ix_models.tools.costs.config import Config
1010
from message_ix_models.tools.costs.projections import create_cost_projections
11+
from message_ix_models.util import load_package_data
1112

1213

1314
def modify_rc_bounds(s_original, s_target, mod_years):
@@ -275,6 +276,7 @@ def gen_te_projections(
275276
tuple[pd.DataFrame, pd.DataFrame]
276277
tuple with "inv_cost" and "fix_cost" DataFrames
277278
"""
279+
dac_techs = ["dac_lt", "dac_hte", "dac_htg"]
278280
model_tec_set = dac_techs
279281
cfg = Config(
280282
module="dac",
@@ -499,12 +501,10 @@ def add_ccs_setup(scen: message_ix.Scenario, ssp="SSP2"):
499501
# ==============================================
500502
# Add new setup ================================
501503
## setup pipelines, storage, and non-dac ccs technologies
502-
filepath = r"C:\Users\pratama\Documents\GitHub\MESSAGEix\message-ix-models\message_ix_models\data\ccs-dac"
503-
add_tech(scen, filepath=filepath + f"\co2infrastructure_data_{ssp}dev.yaml")
504+
add_tech(scen, load_package_data(f"ccs-dac\co2infrastructure_data_{ssp}dev.yaml"))
504505

505506
## setup dac technologies
506-
filepath = r"C:\Users\pratama\Documents\GitHub\MESSAGEix\message-ix-models\message_ix_models\data\ccs-dac"
507-
add_tech(scen, filepath=filepath + f"\daccs_setup_data_{ssp}dev.yaml")
507+
add_tech(scen, load_package_data(f"ccs-dac\daccs_setup_data_{ssp}dev.yaml"))
508508

509509
## add dac costs using meas's tool
510510
##> making the projection

message_ix_models/tools/add_dac/__init__.py

+10-64
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
import numpy as np
1212
import pandas as pd
1313
import yaml
14-
1514
from message_ix.models import MESSAGE_ITEMS
1615
from message_ix.utils import make_df
1716

1817

1918
def generate_df(
2019
scenario,
21-
filepath="",
20+
tech_data,
2221
):
2322
"""
2423
This function generate parameter dataframe, matching the data input
@@ -28,24 +27,9 @@ def generate_df(
2827
----------
2928
scenario : message_ix.Scenario()
3029
MESSAGEix Scenario where the data will be included
31-
filepath : string, path of the input file
32-
the default is in the module's folder
30+
tech_data : dictionary, technology data read using load_package_data
3331
"""
3432

35-
if not filepath:
36-
module_path = os.path.abspath(__file__) # get the module path
37-
package_path = os.path.dirname(
38-
os.path.dirname(module_path)
39-
) # get the package path
40-
path = os.path.join(
41-
package_path, "add_dac/tech_data.yaml"
42-
) # join the current working directory with a filename
43-
with open(path, "r") as stream:
44-
tech_data = yaml.safe_load(stream)
45-
else:
46-
with open(filepath, "r") as stream:
47-
tech_data = yaml.safe_load(stream)
48-
4933
# Set up dictionary of parameter indices list
5034
par_idx = {}
5135
data = {}
@@ -287,29 +271,15 @@ def generate_df(
287271
return data
288272

289273

290-
def print_df(scenario, filepath=""):
291-
if not filepath:
292-
module_path = os.path.abspath(__file__) # get the module path
293-
package_path = os.path.dirname(
294-
os.path.dirname(module_path)
295-
) # get the package path
296-
path = os.path.join(
297-
package_path, "add_dac/tech_data.yaml"
298-
) # join the current working directory with a filename
299-
data = generate_df(scenario, path)
300-
for tec, val in data.items():
301-
with pd.ExcelWriter(f"{tec}.xlsx", engine="xlsxwriter", mode="w") as writer:
302-
for sheet_name, sheet_data in val.items():
303-
sheet_data.to_excel(writer, sheet_name=sheet_name, index=False)
304-
else:
305-
data = generate_df(scenario, filepath)
306-
for tec, val in data.items():
307-
with pd.ExcelWriter(f"{tec}.xlsx", engine="xlsxwriter", mode="w") as writer:
308-
for sheet_name, sheet_data in val.items():
309-
sheet_data.to_excel(writer, sheet_name=sheet_name, index=False)
274+
def print_df(scenario, tech_data):
275+
data = generate_df(scenario, tech_data)
276+
for tec, val in data.items():
277+
with pd.ExcelWriter(f"{tec}.xlsx", engine="xlsxwriter", mode="w") as writer:
278+
for sheet_name, sheet_data in val.items():
279+
sheet_data.to_excel(writer, sheet_name=sheet_name, index=False)
310280

311281

312-
def add_tech(scenario, filepath=""):
282+
def add_tech(scenario, tech_data):
313283
"""
314284
Parameters
315285
----------
@@ -334,31 +304,7 @@ def add_tech(scenario, filepath=""):
334304
# scenario.add_set("cat_tec", ["co2_potential", "co2_stor"])
335305

336306
# Reading new technology database
337-
if not filepath:
338-
module_path = os.path.abspath(__file__) # get the module path
339-
package_path = os.path.dirname(
340-
os.path.dirname(module_path)
341-
) # get the package path
342-
path = os.path.join(
343-
package_path, "add_dac/tech_data.yaml"
344-
) # join the current working directory with a filename
345-
data = generate_df(scenario, path)
346-
else:
347-
data = generate_df(scenario, filepath)
348-
349-
if not filepath:
350-
module_path = os.path.abspath(__file__) # get the module path
351-
package_path = os.path.dirname(
352-
os.path.dirname(module_path)
353-
) # get the package path
354-
path = os.path.join(
355-
package_path, "add_dac/tech_data.yaml"
356-
) # join the current working directory with a filename
357-
with open(path, "r") as stream:
358-
tech_data = yaml.safe_load(stream)
359-
else:
360-
with open(filepath, "r") as stream:
361-
tech_data = yaml.safe_load(stream)
307+
data = generate_df(scenario, tech_data)
362308

363309
# TODO: @ywpratama, bring in the set information here from the YAML file
364310
# Adding parameters by technology and name

0 commit comments

Comments
 (0)