11
11
import numpy as np
12
12
import pandas as pd
13
13
import yaml
14
-
15
14
from message_ix .models import MESSAGE_ITEMS
16
15
from message_ix .utils import make_df
17
16
18
17
19
18
def generate_df (
20
19
scenario ,
21
- filepath = "" ,
20
+ tech_data ,
22
21
):
23
22
"""
24
23
This function generate parameter dataframe, matching the data input
@@ -28,24 +27,9 @@ def generate_df(
28
27
----------
29
28
scenario : message_ix.Scenario()
30
29
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
33
31
"""
34
32
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
-
49
33
# Set up dictionary of parameter indices list
50
34
par_idx = {}
51
35
data = {}
@@ -287,29 +271,15 @@ def generate_df(
287
271
return data
288
272
289
273
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 )
310
280
311
281
312
- def add_tech (scenario , filepath = "" ):
282
+ def add_tech (scenario , tech_data ):
313
283
"""
314
284
Parameters
315
285
----------
@@ -334,31 +304,7 @@ def add_tech(scenario, filepath=""):
334
304
# scenario.add_set("cat_tec", ["co2_potential", "co2_stor"])
335
305
336
306
# 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 )
362
308
363
309
# TODO: @ywpratama, bring in the set information here from the YAML file
364
310
# Adding parameters by technology and name
0 commit comments