Skip to content

Commit 573b049

Browse files
author
WolfBunke
authored
Merge pull request #31 from openego/dev
Release 0.1.0
2 parents 9dc2a58 + 03378ba commit 573b049

File tree

19 files changed

+1119
-351
lines changed

19 files changed

+1119
-351
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ __pycache__/
44
results
55
*.egg-info
66
ego/scenario_setting.json
7+
.spyproject/
8+
ego/noise_values.csv
9+
.idea/
10+
noise_values.csv
11+

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ A speciality in this context is that transmission grids are described by the 380
1616
Installing Developer Version
1717
============================
1818

19-
Create a virtualenvironment (where you like it) and activate it:
19+
Create a virtualenvironment (where you like it) and activate it:
2020

2121
.. code-block::
2222
2323
$ virtualenv eGo --clear -p python3.5
2424
$ source venv/bin/activate
2525
26-
$ pip install -e git+https://github.com/openego/eGo@dev#egg=eGo
26+
$ pip3 install -e git+https://github.com/openego/eGo@dev#egg=eGo --process-dependency-links --allow-all-external
2727
2828
2929
Copyleft

doc/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
.. toctree::
44
:maxdepth: 7
5+
:glob:
56
:titlesonly:
67

78
API <api/modules>

doc/conf.py

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This file is part of
1+
"""This file is part of
22
33
It is developed in the project open_eGo: https://openegoproject.wordpress.com
44
@@ -37,6 +37,10 @@
3737
#sys.path.insert(0, os.path.abspath('.'))
3838
sys.path.insert(0, os.path.abspath('../'))
3939

40+
41+
sys.path
42+
43+
4044
# -- General configuration ------------------------------------------------
4145

4246
# If your documentation needs a minimal Sphinx version, state it here.
@@ -52,14 +56,18 @@
5256
'sphinx.ext.coverage',
5357
'sphinx.ext.imgmath' ,
5458
'sphinx.ext.viewcode',
55-
# 'sphinx.ext.autosummary',
59+
'sphinx.ext.autosummary',
5660
# 'sphinxcontrib.napoleon',#enable Napoleon interpreter of docstrings Sphinx v<=1.2
5761
'sphinx.ext.napoleon', #enable Napoleon Sphinx v>1.3
5862
# 'sphinx_paramlinks',#to have links to the types of the parameters of the functions
5963
'numpydoc',
64+
'sphinxcontrib.httpdomain', # for restfull API
65+
'sphinxcontrib.autohttp.flask',
6066
'sphinx.ext.extlinks' # enables external links with a key
6167
]
6268

69+
70+
6371
# Napoleon settings
6472
napoleon_google_docstring = True
6573
napoleon_numpy_docstring = True
@@ -84,8 +92,51 @@
8492
'Shapely object')
8593
}
8694

95+
# test oedb implementation
96+
def rstjinja(app, docname, source):
97+
"""
98+
Render our pages as a jinja template for fancy templating goodness.
99+
"""
100+
# Make sure we're outputting HTML
101+
if app.builder.format != 'html':
102+
return
103+
src = source[0]
104+
rendered = app.builder.templates.render_string(
105+
src, app.config.html_context
106+
)
107+
source[0] = rendered
108+
109+
def setup(app):
110+
app.connect("source-read", rstjinja)
87111

112+
import requests
88113

114+
oep_url= 'http://oep.iks.cs.ovgu.de/'
115+
116+
# get data from oedb test
117+
power_class = requests.get(oep_url+'/api/v0/schema/model_draft/tables/ego_power_class/rows/', ).json()
118+
119+
import json
120+
path = os.getcwd()
121+
json_file ='../ego/scenario_setting.json'
122+
123+
with open(path +'/'+json_file) as f:
124+
scn_set = json.load(f)
125+
126+
127+
128+
html_context = {
129+
'power_class': power_class,
130+
'scn_setting': scn_set
131+
}
132+
133+
134+
135+
136+
137+
138+
# add RestFull API
139+
httpexample_scheme = 'https'
89140

90141

91142
# Add any paths that contain templates here, relative to this directory.
@@ -104,7 +155,7 @@
104155

105156
# General information about the project.
106157
project = u'eGo'
107-
copyright = u'2015-2017, open_eGo-Team'
158+
copyright = u'2015-2018, open_eGo-Team'
108159
author = u'open_eGo-Team'
109160

110161

@@ -113,7 +164,7 @@
113164
# built documents.
114165
#
115166
# The short X.Y version.
116-
version = '0.0.1'
167+
version = '0.1.0'
117168
# The full version, including alpha/beta/rc tags.
118169
release = '0.0.1dev'
119170

@@ -175,11 +226,11 @@ def __getattr__(cls, name):
175226

176227
MOCK_MODULES = ['ding0', 'ding0.results', 'shapely']
177228
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
178-
179-
MOCK_MODULES = ['libgeos', 'geos', 'libgeos_c', 'geos_c','libgeos_c.so.1',
229+
230+
MOCK_MODULES = ['libgeos', 'geos', 'libgeos_c', 'geos_c','libgeos_c.so.1',
180231
'libgeos_c.so', 'shapely', 'geoalchemy2', 'geoalchemy2.shape ']
181232

182-
233+
183234

184235
# -- Options for HTML output ----------------------------------------------
185236

doc/developer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ eDisGo units
2828
------------
2929

3030
.. csv-table:: List of variables and units
31-
:file: https://raw.githubusercontent.com/openego/eDisGo/dev/doc/units_table.csv
31+
:url: https://raw.githubusercontent.com/openego/eDisGo/dev/doc/units_table.csv
3232
:delim: ;
3333
:header-rows: 1
3434
:widths: 5, 1, 1, 5

doc/getting_started.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Installation
2727
```
2828

2929
With your activated environment `cd` to the cloned directory and run
30-
``pip3 install -e eGo`` . This will install all needed packages into your environment.
30+
``pip3 install -e eGo --process-dependency-links --allow-all-external`` . This will install all needed packages into your environment.
3131

3232
.. warning::
3333

@@ -42,14 +42,16 @@ With your activated environment `cd` to the cloned directory and run
4242
``pip3 install -e git+https://github.com/openego/PyPSA.git@dev#egg=PyPSA``
4343
and Folium for an web based ploting with
4444
``pip3 install -e git+git@github.com:python-visualization/folium.git@5739244acb9868d001032df288500a047b232857#egg=folium``
45-
46-
Check if the `config.json <https://github.com/openego/eTraGo/blob/dev/etrago/tools/config.json>`_
45+
46+
Check if the `config.json <https://github.com/openego/eTraGo/blob/dev/etrago/tools/config.json>`_
4747
file from eTraGo is installed in your libary ``/lib/python3.5/site-packages/etrago/tools`` .
48-
If not copy and paste this file into this folder.
48+
If not copy and paste this file into this folder.
49+
50+
If Database connection or table erros appears use: ``pip3 install -e git+git@github.com:openego/ego.io.git@3b76dfddea14d67eb4421b6223bf981d8851e4e6#egg=ego.io``
51+
4952

5053
Using eGo:
5154
==========
5255

5356
1. check and prepare your eGo setting in ``ego/scenario_setting.json``
54-
2. Start your calculation with in the directory of ``eGo/ego`` with
55-
``python3 ego_main.py``
57+
2. Start your calculation with in the directory of ``eGo/ego`` with ``python3 ego_main.py``

doc/whatsnew.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ See what's new as per release!
99
:backlinks: top
1010

1111

12+
.. include:: whatsnew/v0-1-0.rst
1213
.. include:: whatsnew/v0-0-1.rst

doc/whatsnew/v0-1-0.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Release v0.1.0 (March 29, 2018)
2+
+++++++++++++++++++++++++++++++
3+
4+
As this is the second release of eGo. This Release introduce the resulte class
5+
and is still under construction and not ready for a normal use.
6+
7+
8+
9+
10+
Added features
11+
--------------
12+
13+
* Update of Interface between eTraGo and eDisGo (specs)
14+
* New structure of eGo module / resulte class
15+
* Restructuring of functions
16+
* Add import function of eTraGo results form oedb
17+
18+
Notes
19+
-----
20+
21+
* The 'direct_specs' function is not working and needs to be set to ``false``
705 KB
Binary file not shown.

ego/ego_main.py

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
from tools.plots import (make_all_plots,plot_line_loading, plot_stacked_gen,
2222
add_coordinates, curtailment, gen_dist,
2323
storage_distribution, igeoplot)
24+
# For importing geopandas you need to install spatialindex on your system http://github.com/libspatialindex/libspatialindex/wiki/1.-Getting-Started
2425
from tools.utilities import get_scenario_setting, get_time_steps
2526
from tools.io import geolocation_buses, etrago_from_oedb
26-
from tools.results import total_storage_charges
27+
from tools.results import eGo
2728
from sqlalchemy.orm import sessionmaker
2829
from egoio.tools import db
2930
from etrago.tools.io import results_to_oedb
@@ -33,10 +34,25 @@
3334
logging.basicConfig(level=logging.INFO)
3435
logger = logging.getLogger(__name__)
3536

37+
## Logging
38+
logging.basicConfig(format='%(asctime)s %(message)s',level=logging.INFO)
39+
40+
logger = logging.getLogger(__name__)
41+
ego_logger = logging.getLogger('ego')
42+
43+
fh = logging.FileHandler('ego.log', mode='w')
44+
fh.setLevel(logging.INFO)
45+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
46+
fh.setFormatter(formatter)
47+
48+
logger.addHandler(fh)
49+
ego_logger.addHandler(fh)
50+
3651

3752
if __name__ == '__main__':
3853
# import scenario settings **args of eTraGo
3954
args = get_scenario_setting(json_file='scenario_setting.json')
55+
print (args)
4056

4157
try:
4258
conn = db.connection(section=args['global']['db'])
@@ -50,91 +66,58 @@
5066
# start eTraGo calculation
5167
eTraGo = etrago(args['eTraGo'])
5268

53-
#ToDo save result to db
54-
# Does not work wait for eTraGo release 0.5.1
55-
#results_to_oedb(session, eTraGo, args['eTraGo'], grid='hv')
69+
eGo = eGo(eTraGo=eTraGo, scn_name='Status Quo')
5670

5771
# add country code to bus and geometry (shapely)
5872
# eTraGo.buses = eTraGo.buses.drop(['country_code','geometry'], axis=1)
5973
#test = geolocation_buses(network = eTraGo, session)
6074

61-
# other plots based on matplotlib
62-
make_all_plots(eTraGo)
6375
# make a line loading plot
64-
plot_line_loading(eTraGo)
76+
eGo.eTraGo.plot_line_loading(eTraGo)
6577

66-
# plot stacked sum of nominal power for each generator type and timestep
67-
plot_stacked_gen(eTraGo, resolution="MW")
68-
69-
# plot to show extendable storages
70-
storage_distribution(eTraGo)
71-
72-
# plot storage total charges and discharge
73-
total_storage_charges(eTraGo, plot=True)
7478

7579
# get eTraGo results form db
76-
if args['global']['result_id']:
80+
if args['global']['recover']:
7781
eTraGo = etrago_from_oedb(session,args)
7882

79-
8083
# use eTraGo results from ego calculations if true
8184
# ToDo make function edisgo_direct_specs()
8285

83-
if args['eDisGo']['direct_specs']:
84-
# ToDo: add this to utilities.py
85-
bus_id = 27334
86-
specs_meta_data = {}
87-
specs_meta_data.update({'TG Bus ID':bus_id})
8886

89-
# Retrieve all Data
90-
### Snapshot Range
91-
#snap_idx = eTraGo_network.snapshots
9287

93-
## Bus Power
94-
95-
try:
96-
active_power_kW = eTraGo_network.buses_t.p[str(bus_id)] * 1000 # PyPSA result is in MW
97-
except:
98-
logger.warning('No active power series')
99-
active_power_kW = None
88+
if args['eDisGo']['direct_specs']:
89+
# ToDo: add this to utilities.py
10090

101-
try:
102-
reactive_power_kvar = eTraGo_network.buses_t.q[str(bus_id)] * 1000 # PyPSA result is in Mvar
103-
except:
104-
logger.warning('No reactive power series')
105-
reactive_power_kvar = None
91+
logging.info('Retrieving Specs')
10692

93+
bus_id = 27574 #23971
10794

108-
## Gens
109-
all_gens = eTraGo_network.generators.bus
110-
bus_gens = all_gens.index[all_gens == str(bus_id)]
111-
p_nom = eTraGo_network.generators.p_nom[bus_gens]
112-
gen_type = eTraGo_network.generators.carrier[bus_gens]
95+
from ego.tools.specs import get_etragospecs_direct, get_mvgrid_from_bus_id
96+
from egoio.db_tables import model_draft
97+
specs = get_etragospecs_direct(session, bus_id, eTraGo, args)
11398

114-
gen_df = pd.DataFrame({'p_nom': p_nom,'gen_type':gen_type})
115-
capacity = gen_df[['p_nom','gen_type']].groupby('gen_type').sum().T
11699

117-
gens = eTraGo_network.generators
118-
for key, value in gens.items():
119-
print (key)
120100

121101
# ToDo make loop for all bus ids
122102
# make function which links bus_id (subst_id)
123103
if args['eDisGo']['specs']:
124104

105+
125106
logging.info('Retrieving Specs')
126107
# ToDo make it more generic
127108
# ToDo iteration of grids
128109
# ToDo move part as function to utilities or specs
129-
bus_id = 23971
110+
bus_id = 27574 #23971
130111
result_id = args['global']['result_id']
131-
scn_name = args['global']['scn_name'] # Six is Germany for 2 Snaps with minimal residual load
132112

133-
from ego.tools.specs import get_etragospecs_from_db
113+
from ego.tools.specs import get_etragospecs_from_db, get_mvgrid_from_bus_id
134114
from egoio.db_tables import model_draft
135-
specs = get_etragospecs_from_db(session, bus_id, result_id, scn_name)
115+
specs = get_etragospecs_from_db(session, bus_id, result_id)
116+
117+
mv_grid = get_mvgrid_from_bus_id(session, bus_id) # This function can be used to call the correct MV grid
136118

137119
if args['global']['eDisGo']:
120+
138121
logging.info('Starting eDisGo')
139122

140123
# ToDo move part as function to utilities or specs
@@ -145,7 +128,7 @@
145128

146129
# ToDo get ding0 grids over db
147130
# ToDo implemente iteration
148-
file_path = '/home/dozeumbuw/ego_dev/src/ding0_grids__1802.pkl'
131+
file_path = 'data/ding0_grids/ding0_grids__1802.pkl'
149132

150133
#mv_grid = open(file_path)
151134

@@ -157,7 +140,7 @@
157140
scenario = Scenario(etrago_specs=specs,
158141
power_flow=(),
159142
mv_grid_id=mv_grid_id,
160-
scenario_name= args['global']['scn_name'])
143+
scenario_name= args['eTraGo']['scn_name'])
161144

162145
network = Network.import_from_ding0(file_path,
163146
id=mv_grid_id,
@@ -182,6 +165,7 @@
182165
print(costs)
183166

184167

168+
185169
# make interactive plot with folium
186170
#logging.info('Starting interactive plot')
187171
#igeoplot(network=eTraGo, session=session, args=args) # ToDo: add eDisGo results

0 commit comments

Comments
 (0)