Skip to content

Commit e5e31bd

Browse files
author
wolfbunke
committed
add py scripts to pre dp
1 parent 334d438 commit e5e31bd

14 files changed

Lines changed: 1391 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
""" checkseq
2+
3+
Usage:
4+
checkseq.py SEQ_DATA LABEL
5+
checkseq.py -h | --help
6+
7+
Examples:
8+
9+
python3 checkseq.py path/to/scenario-seq.csv solar
10+
11+
Arguments:
12+
13+
SEQ_DATA CSV-file with data for sequences.
14+
LABEL Label to search for in components.
15+
16+
Options:
17+
18+
-h --help Show this screen and exit
19+
20+
"""
21+
22+
__copyright__ = "ZNES"
23+
__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)"
24+
__url__ = "https://github.com/openego/data_processing/blob/master/LICENSE"
25+
__author__ = "s3pp"
26+
27+
28+
import pandas as pd
29+
from docopt import docopt
30+
31+
32+
def read_csv(**kwargs):
33+
""" Read and handle CSV-file.
34+
35+
Parameters
36+
----------
37+
**kwargs : key word arguments
38+
Arguments passed from command line
39+
40+
Returns
41+
-------
42+
df : pd.DataFrame
43+
DataFrame with data for sequences.
44+
45+
"""
46+
47+
df = pd.read_csv(kwargs['SEQ_DATA'], header=[1, 2, 3, 4], sep=',')
48+
df.dropna(axis=0, how='all', inplace=True)
49+
df.sort_index(inplace=True)
50+
df.drop('label', axis=1, inplace=True)
51+
df = df.astype(float)
52+
df.columns.names = ['label', 'source', 'target', 'value']
53+
return df
54+
55+
56+
def main(**arguments):
57+
58+
print("Reading CSV-file %s" % arguments['SEQ_DATA'])
59+
df = read_csv(**arguments)
60+
61+
# select for label
62+
idx = df.columns.get_level_values('label').str.contains(arguments['LABEL'])
63+
df = df.loc[:, idx]
64+
65+
print("\n\nMaximum value in each sequence with %s." % arguments['LABEL'])
66+
print("------------------------------------------------------")
67+
print(df.max())
68+
69+
print("\n\nSummed up each sequence representing full-loadhours.")
70+
print("------------------------------------------------------")
71+
print(df.sum())
72+
73+
print("Done.")
74+
75+
if __name__ == '__main__':
76+
arguments = docopt(__doc__)
77+
main(**arguments)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/python
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Database dump CSV-file with lon/lat is converted to a git compatible geojson
5+
format.
6+
7+
Attributes
8+
----------
9+
infile : str
10+
File path to database dump.
11+
outfile : str
12+
File path to geojson file.
13+
14+
Notes
15+
-----
16+
Dump has to match geojson keys title, description, lon and lat.
17+
18+
"""
19+
20+
21+
__copyright__ = "ZNES"
22+
__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)"
23+
__url__ = "https://github.com/openego/data_processing/blob/master/LICENSE"
24+
__author__ = "s3pp"
25+
26+
27+
import pandas as pd
28+
import json
29+
from os.path import expanduser
30+
31+
infile = '~/open_eGo/scenario/modelpowerplants.csv'
32+
outfile = expanduser("")
33+
34+
df = pd.read_csv(infile, sep=";")
35+
features = []
36+
for ix, row in df.iterrows():
37+
38+
# properties section
39+
properties = {"title": row['title'],
40+
"description": row['description'],
41+
"marker-size": "medium",
42+
"marker-symbol": "triangle",
43+
"stroke": "#555555"}
44+
45+
# geometry section
46+
geometry = {"type": "Point",
47+
"coordinates": [row['lon'], row['lat']]}
48+
49+
# concat to feature
50+
feature = {"type": "Feature",
51+
"geometry": geometry,
52+
"properties": properties}
53+
54+
features.append(feature)
55+
56+
feature_collection = {"type": "FeatureCollection",
57+
"features": features}
58+
59+
with open(outfile, 'w') as out:
60+
json.dump(feature_collection, out)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
""" checkseq
2+
3+
Usage:
4+
checkseq.py SEQ_DATA LABEL
5+
checkseq.py -h | --help
6+
7+
Examples:
8+
9+
python3 checkseq.py path/to/scenario-seq.csv solar
10+
11+
Arguments:
12+
13+
SEQ_DATA CSV-file with data for sequences.
14+
LABEL Label to search for in components.
15+
16+
Options:
17+
18+
-h --help Show this screen and exit
19+
20+
"""
21+
22+
__copyright__ = "ZNES"
23+
__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)"
24+
__url__ = "https://github.com/openego/data_processing/blob/master/LICENSE"
25+
__author__ = "s3pp"
26+
27+
28+
import pandas as pd
29+
from docopt import docopt
30+
31+
32+
def read_csv(**kwargs):
33+
""" Read and handle CSV-file.
34+
35+
Parameters
36+
----------
37+
**kwargs : key word arguments
38+
Arguments passed from command line
39+
40+
Returns
41+
-------
42+
df : pd.DataFrame
43+
DataFrame with data for sequences.
44+
45+
"""
46+
47+
df = pd.read_csv(kwargs['SEQ_DATA'], header=[1, 2, 3, 4], sep=',')
48+
df.dropna(axis=0, how='all', inplace=True)
49+
df.sort_index(inplace=True)
50+
df.drop('label', axis=1, inplace=True)
51+
df = df.astype(float)
52+
df.columns.names = ['label', 'source', 'target', 'value']
53+
return df
54+
55+
56+
def main(**arguments):
57+
58+
print("Reading CSV-file %s" % arguments['SEQ_DATA'])
59+
df = read_csv(**arguments)
60+
61+
# select for label
62+
idx = df.columns.get_level_values('label').str.contains(arguments['LABEL'])
63+
df = df.loc[:, idx]
64+
65+
print("\n\nMaximum value in each sequence with %s." % arguments['LABEL'])
66+
print("------------------------------------------------------")
67+
print(df.max())
68+
69+
print("\n\nSummed up each sequence representing full-loadhours.")
70+
print("------------------------------------------------------")
71+
print(df.sum())
72+
73+
print("Done.")
74+
75+
if __name__ == '__main__':
76+
arguments = docopt(__doc__)
77+
main(**arguments)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/python
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Database dump CSV-file with lon/lat is converted to a git compatible geojson
5+
format.
6+
7+
Attributes
8+
----------
9+
infile : str
10+
File path to database dump.
11+
outfile : str
12+
File path to geojson file.
13+
14+
Notes
15+
-----
16+
Dump has to match geojson keys title, description, lon and lat.
17+
18+
"""
19+
20+
21+
__copyright__ = "ZNES"
22+
__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)"
23+
__url__ = "https://github.com/openego/data_processing/blob/master/LICENSE"
24+
__author__ = "s3pp"
25+
26+
27+
import pandas as pd
28+
import json
29+
from os.path import expanduser
30+
31+
infile = '~/open_eGo/scenario/modelpowerplants.csv'
32+
outfile = expanduser("")
33+
34+
df = pd.read_csv(infile, sep=";")
35+
features = []
36+
for ix, row in df.iterrows():
37+
38+
# properties section
39+
properties = {"title": row['title'],
40+
"description": row['description'],
41+
"marker-size": "medium",
42+
"marker-symbol": "triangle",
43+
"stroke": "#555555"}
44+
45+
# geometry section
46+
geometry = {"type": "Point",
47+
"coordinates": [row['lon'], row['lat']]}
48+
49+
# concat to feature
50+
feature = {"type": "Feature",
51+
"geometry": geometry,
52+
"properties": properties}
53+
54+
features.append(feature)
55+
56+
feature_collection = {"type": "FeatureCollection",
57+
"features": features}
58+
59+
with open(outfile, 'w') as out:
60+
json.dump(feature_collection, out)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# -*- coding: utf-8 -*-
2+
"""SQLA ORM
3+
"""
4+
5+
6+
__copyright__ = "ZNES"
7+
__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)"
8+
__url__ = "https://github.com/openego/data_processing/blob/master/LICENSE"
9+
__author__ = "s3pp"
10+
11+
12+
from sqlalchemy import MetaData, create_engine
13+
from sqlalchemy.orm import sessionmaker
14+
from sqlalchemy.ext.automap import automap_base
15+
import configparser as cp
16+
import os.path as path
17+
18+
# read configuration file
19+
FILENAME = 'config.ini'
20+
FILE = path.join(path.expanduser("~"), '.open_eGo', FILENAME)
21+
cfg = cp.ConfigParser()
22+
cfg.read(FILE)
23+
24+
# establish db connection
25+
section = 'oedb'
26+
conn = create_engine(
27+
"postgresql+psycopg2://{user}:{password}@{host}:{port}/{db}".format(
28+
user=cfg.get(section, 'username'),
29+
password=cfg.get(section, 'password'),
30+
host=cfg.get(section, 'host'),
31+
port=cfg.get(section, 'port'),
32+
db=cfg.get(section, 'db')))
33+
34+
print("Connected to database.")
35+
36+
# map schema
37+
session = sessionmaker(bind=conn)()
38+
39+
meta = MetaData()
40+
meta.bind = conn
41+
meta.reflect(bind=conn, schema='calc_renpass_gis',
42+
only=['renpass_gis_scenario',
43+
'renpass_gis_linear_transformer',
44+
'renpass_gis_source',
45+
'renpass_gis_sink',
46+
'renpass_gis_storage',
47+
'renpass_gis_results'])
48+
49+
# map to classes
50+
Base = automap_base(metadata=meta)
51+
Base.prepare()
52+
53+
Scenario, LinearTransformer, Source, Sink, Storage, Results = \
54+
Base.classes.renpass_gis_scenario,\
55+
Base.classes.renpass_gis_linear_transformer,\
56+
Base.classes.renpass_gis_source,\
57+
Base.classes.renpass_gis_sink,\
58+
Base.classes.renpass_gis_storage,\
59+
Base.classes.renpass_gis_results

0 commit comments

Comments
 (0)