forked from rikvanheerden/navigate-demand-mip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readdata.py
32 lines (26 loc) · 1.01 KB
/
readdata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os.path
import pyam
import pandas as pd
if not os.path.exists("credentials.py"):
with open("credentials.py", 'w') as f:
f.write('USERNAME = "here.your.username"\n')
f.write('PASSWORD = "here.your.password"\n')
raise Exception("Provide your credentials in credentials.py")
from credentials import *
FILENAME_DB = "iiasa_db_data.csv"
pyam.iiasa.set_config(USERNAME, PASSWORD)
def get_from_iiasadb(update=True):
if update and os.path.exists(FILENAME_DB):
return pyam.read_iiasa
else:
return lambda **x: pyam.lazy_read_iiasa(file=FILENAME_DB, **x)
def read_iiasa(region='World', update=True, no_hist_data=False):
df_database = get_from_iiasadb(update)(
name='navigate_internal',
scenario='NAV_Dem*',
region=region
)
if not no_hist_data:
hist_df = pyam.IamDataFrame(r'NAV_Dem-NPi-ref_historicresults.csv')
df = pyam.IamDataFrame(pd.concat([df_database.as_pandas(meta_cols=False), hist_df.as_pandas(meta_cols=False)]))
return df