|
1
|
|
|
"""The central module containing all code dealing with importing data from |
|
2
|
|
|
the pysa-eur-sec scenario parameter creation |
|
3
|
|
|
""" |
|
4
|
|
|
|
|
5
|
|
|
import os |
|
6
|
|
|
import pandas as pd |
|
7
|
|
|
from egon.data import db |
|
8
|
|
|
from egon.data.importing.nep_input_data import scenario_config |
|
9
|
|
|
from sqlalchemy.ext.declarative import declarative_base |
|
10
|
|
|
import egon.data.subprocess as subproc |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
### will be later imported from another file ### |
|
14
|
|
|
Base = declarative_base() |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
def run_pypsa_eur_sec(): |
|
18
|
|
|
|
|
19
|
|
|
# execute pypsa-eur-sec |
|
20
|
|
|
import os |
|
21
|
|
|
import egon.data.subprocess as subproc |
|
22
|
|
|
from pathlib import Path |
|
23
|
|
|
|
|
24
|
|
|
filepath = Path(".") |
|
25
|
|
|
pypsa_eur_repos = filepath / "pypsa-eur" |
|
26
|
|
|
technology_data_repos = filepath / "technology-data" |
|
27
|
|
|
pypsa_eur_sec_repos = filepath / "pypsa-eur-sec" |
|
28
|
|
|
pypsa_eur_sec_repos_data = pypsa_eur_sec_repos / "data/" |
|
29
|
|
|
|
|
30
|
|
|
if not os.path.exists(pypsa_eur_repos): |
|
31
|
|
|
subproc.run( |
|
32
|
|
|
[ |
|
33
|
|
|
"git", |
|
34
|
|
|
"clone", |
|
35
|
|
|
"https://github.com/PyPSA/pypsa-eur.git", |
|
36
|
|
|
], |
|
37
|
|
|
cwd=filepath, |
|
38
|
|
|
) |
|
39
|
|
|
|
|
40
|
|
|
if not os.path.exists(technology_data_repos): |
|
41
|
|
|
subproc.run( |
|
42
|
|
|
[ |
|
43
|
|
|
"git", |
|
44
|
|
|
"clone", |
|
45
|
|
|
"https://github.com/PyPSA/technology-data.git", |
|
46
|
|
|
], |
|
47
|
|
|
cwd=filepath, |
|
48
|
|
|
) |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
if not os.path.exists(pypsa_eur_sec_repos): |
|
52
|
|
|
subproc.run( |
|
53
|
|
|
[ |
|
54
|
|
|
"git", |
|
55
|
|
|
"clone", |
|
56
|
|
|
"https://github.com/openego/pypsa-eur-sec.git", |
|
57
|
|
|
], |
|
58
|
|
|
cwd=filepath, |
|
59
|
|
|
) |
|
60
|
|
|
|
|
61
|
|
|
subproc.run( |
|
62
|
|
|
[ |
|
63
|
|
|
"wget", |
|
64
|
|
|
"https://nworbmot.org/pypsa-eur-sec-data-bundle-201012.tar.gz", |
|
65
|
|
|
], |
|
66
|
|
|
cwd=pypsa_eur_sec_repos_data, |
|
67
|
|
|
) |
|
68
|
|
|
|
|
69
|
|
|
subproc.run( |
|
70
|
|
|
[ |
|
71
|
|
|
"tar", |
|
72
|
|
|
"xvzf", |
|
73
|
|
|
"pypsa-eur-sec-data-bundle-201012.tar.gz", |
|
74
|
|
|
], |
|
75
|
|
|
cwd=pypsa_eur_sec_repos_data, |
|
76
|
|
|
) |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
subproc.run( |
|
80
|
|
|
[ |
|
81
|
|
|
"snakemake", |
|
82
|
|
|
"-j1", |
|
83
|
|
|
"prepare_sector_networks", |
|
84
|
|
|
], |
|
85
|
|
|
cwd=pypsa_eur_sec_repos, |
|
86
|
|
|
) |
|
87
|
|
|
|
|
88
|
|
|
def pypsa_eur_sec_eGon100_capacities(): |
|
89
|
|
|
"""Inserts installed capacities for the eGon100 scenario |
|
90
|
|
|
|
|
91
|
|
|
Returns |
|
92
|
|
|
------- |
|
93
|
|
|
None. |
|
94
|
|
|
|
|
95
|
|
|
""" |
|
96
|
|
|
|
|
97
|
|
|
# Connect to local database |
|
98
|
|
|
engine = db.engine() |
|
99
|
|
|
|
|
100
|
|
|
# Delete rows if already exist |
|
101
|
|
|
db.execute_sql("DELETE FROM supply.egon_scenario_capacities " |
|
102
|
|
|
"WHERE scenario_name = 'eGon100'") |
|
103
|
|
|
|
|
104
|
|
|
# read-in installed capacities |
|
105
|
|
|
target_file = os.path.join( |
|
106
|
|
|
os.path.dirname(__file__), |
|
107
|
|
|
scenario_config('eGon100')['paths']['capacities']) |
|
108
|
|
|
|
|
109
|
|
|
df = pd.read_csv(target_file, skiprows=5) |
|
110
|
|
|
df.columns = ['component', 'country', 'carrier', 'capacity'] |
|
111
|
|
|
df['scenario_name'] = 'eGon100' |
|
112
|
|
|
|
|
113
|
|
|
# Insert data to db |
|
114
|
|
|
df.to_sql('egon_scenario_capacities', |
|
115
|
|
|
engine, |
|
116
|
|
|
schema='supply', |
|
117
|
|
|
if_exists='append', |
|
118
|
|
|
index=df.index) |
|
119
|
|
|
|
|
120
|
|
|
|