Skip to content

Commit

Permalink
Merge branch 'dev' into fix/#266-provide_powerfactor_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Boltbeard authored and Boltbeard committed Mar 7, 2019
2 parents 94781a5 + 2ecb90a commit 06e6aeb
Show file tree
Hide file tree
Showing 49 changed files with 767 additions and 360 deletions.
7 changes: 1 addition & 6 deletions README.md
@@ -1,18 +1,13 @@
<img align="right" width="300" height="300" src="https://github.com/openego/ding0/blob/dev/doc/images/DING0_Logo_300px.png">

[![Documentation Status](https://readthedocs.org/projects/ding0/badge/?version=dev)](http://ding0.readthedocs.io/en/dev/?badge=dev)
[![Documentation Status](https://readthedocs.org/projects/ding0/badge/?version=dev)](http://dingo.readthedocs.io/en/dev)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.834751.svg)](https://doi.org/10.5281/zenodo.834751)

DING0
=====
DIstribution Network GeneratOr -- A tool to generate synthetic medium and low
voltage power distribution grids based on open (or at least accessible) data.

WARNING: Note, currently the data source Ding0 relies on - the
[Open Energy Database](http://oep.iks.cs.ovgu.de/dataedit/) - has no public
accessible API, yet. Thus, currently you won't be able to run Ding0 without
modifications.

Installation and usage
----------------------

Expand Down
2 changes: 1 addition & 1 deletion ding0/config/config_db_tables.cfg
Expand Up @@ -24,7 +24,7 @@ mv_stations = EgoDpHvmvSubstation
lv_stations = EgoDpMvlvSubstation
re_generators = t_ego_dp_res_powerplant_sq_mview
conv_generators = t_ego_dp_conv_powerplant_sq_mview
version = v0.4.2
version = v0.4.5

[input_data_source]
input_data = versioned
39 changes: 33 additions & 6 deletions ding0/core/__init__.py
Expand Up @@ -24,6 +24,7 @@
from ding0.core.powerflow import *
from ding0.tools import pypsa_io
from ding0.tools.animation import AnimationDing0
from ding0.tools.plots import plot_mv_topology
from ding0.flexopt.reinforce_grid import *

import os
Expand All @@ -36,12 +37,15 @@
from sqlalchemy.orm import sessionmaker
from sqlalchemy import func
from geoalchemy2.shape import from_shape
from shapely.wkt import loads as wkt_loads
from shapely.geometry import Point, MultiPoint, MultiLineString, LineString
from shapely.geometry import shape, mapping
import subprocess
import oedialect

if not 'READTHEDOCS' in os.environ:
from shapely.wkt import loads as wkt_loads
from shapely.geometry import Point, MultiPoint, MultiLineString, LineString
from shapely.geometry import shape, mapping
from shapely.wkt import dumps as wkt_dumps

logger = logging.getLogger('ding0')

package_path = ding0.__path__[0]
Expand Down Expand Up @@ -99,7 +103,7 @@ def orm(self):
"""Returns ORM data"""
return self._orm

def run_ding0(self, session, mv_grid_districts_no=None, debug=False):
def run_ding0(self, session, mv_grid_districts_no=None, debug=False, export_figures=False):
""" Let DING0 run by shouting at this method (or just call
it from NetworkDing0 instance). This method is a wrapper
for the main functionality of DING0.
Expand All @@ -113,6 +117,8 @@ def run_ding0(self, session, mv_grid_districts_no=None, debug=False):
all grid_districts & stations are imported)
debug : bool, defaults to False
If True, information is printed during process
export_figures : bool, defaults to False
If True, figures are shown or exported (default path: ~/.ding0/) during run.
Returns
-------
Expand Down Expand Up @@ -210,29 +216,51 @@ def run_ding0(self, session, mv_grid_districts_no=None, debug=False):
self.build_lv_grids()

# STEP 6: Build MV grids
self.mv_routing(debug=False, animation=False)
self.mv_routing(debug=False)
if export_figures:
grid = self._mv_grid_districts[0].mv_grid
plot_mv_topology(grid, subtitle='Routing completed', filename='1_routing_completed.png')

# STEP 7: Connect MV and LV generators
self.connect_generators(debug=False)
if export_figures:
plot_mv_topology(grid, subtitle='Generators connected', filename='2_generators_connected.png')

# STEP 8: Set IDs for all branches in MV and LV grids
self.set_branch_ids()

# STEP 9: Relocate switch disconnectors in MV grid
self.set_circuit_breakers(debug=debug)
if export_figures:
plot_mv_topology(grid, subtitle='Circuit breakers relocated', filename='3_circuit_breakers_relocated.png')

# STEP 10: Open all switch disconnectors in MV grid
self.control_circuit_breakers(mode='open')

# STEP 11: Do power flow analysis of MV grid
self.run_powerflow(session, method='onthefly', export_pypsa=False, debug=debug)
if export_figures:
plot_mv_topology(grid, subtitle='PF result (load case)',
filename='4_PF_result_load.png',
line_color='loading', node_color='voltage', testcase='load')
plot_mv_topology(grid, subtitle='PF result (feedin case)',
filename='5_PF_result_feedin.png',
line_color='loading', node_color='voltage', testcase='feedin')

# STEP 12: Reinforce MV grid
self.reinforce_grid()

# STEP 13: Close all switch disconnectors in MV grid
self.control_circuit_breakers(mode='close')

if export_figures:
plot_mv_topology(grid, subtitle='Final grid PF result (load case)',
filename='6_final_grid_PF_result_load.png',
line_color='loading', node_color='voltage', testcase='load')
plot_mv_topology(grid, subtitle='Final grid PF result (feedin case)',
filename='7_final_grid_PF_result_feedin.png',
line_color='loading', node_color='voltage', testcase='feedin')

if debug:
logger.info('Elapsed time for {0} MV Grid Districts (seconds): {1}'.format(
str(len(mv_grid_districts_no)), time.time() - start))
Expand Down Expand Up @@ -359,7 +387,6 @@ def build_lv_grid_district(self,
# raise ValueError(
# 'Load Area {} has no LVGD - please re-open #155'.format(
# repr(lv_load_area)))
from shapely.wkt import dumps as wkt_dumps
geom = wkt_dumps(lv_load_area.geo_area)

lv_grid_districts = \
Expand Down
5 changes: 4 additions & 1 deletion ding0/core/network/__init__.py
Expand Up @@ -131,10 +131,13 @@ def graph_add_node(self, node_object):
def graph_draw(self, mode):
""" Draws grid graph using networkx
This method is for debugging purposes only.
Use ding0.tools.plots.plot_mv_topology() for advanced plotting.
Parameters
----------
mode : str
Mode selection 'MV' or 'LV'. #TODO: check
Mode selection 'MV' or 'LV'.
Notes
-----
Expand Down
6 changes: 4 additions & 2 deletions ding0/core/network/grids.py
Expand Up @@ -16,7 +16,7 @@
# from ding0.core.network import GridDing0
from . import GridDing0
from ding0.core.network.stations import *
from ding0.core.network import RingDing0, BranchDing0, CircuitBreakerDing0
from ding0.core.network import RingDing0, CircuitBreakerDing0
from ding0.core.network.loads import *
from ding0.core.network.cable_distributors import MVCableDistributorDing0, LVCableDistributorDing0
from ding0.grid.mv_grid import mv_routing, mv_connect
Expand All @@ -27,13 +27,15 @@
from ding0.flexopt.reinforce_grid import *
from ding0.core.structure.regions import LVLoadAreaCentreDing0

import os
import networkx as nx
from datetime import datetime
from shapely.ops import transform
import pyproj
from functools import partial
import logging

if not 'READTHEDOCS' in os.environ:
from shapely.ops import transform

logger = logging.getLogger('ding0')

Expand Down
4 changes: 3 additions & 1 deletion ding0/core/structure/regions.py
Expand Up @@ -13,10 +13,12 @@
__author__ = "nesnoj, gplssm"


import os
from . import RegionDing0
from ding0.tools import config as cfg_ding0

from shapely.wkt import loads as wkt_loads
if not 'READTHEDOCS' in os.environ:
from shapely.wkt import loads as wkt_loads


class MVGridDistrictDing0(RegionDing0):
Expand Down
51 changes: 27 additions & 24 deletions ding0/examples/example_analyze_multiple_grid_districts.py
Expand Up @@ -12,30 +12,31 @@
Notes
-----
This example file assumes you have already run the example file
`example_multiple_grid_districts.py` and use the option to save the `nd` object to
disc. If the example script was executed in PWD, do not change `base_path`
below.
"""
This example file creates some statistics of the specified ding0 grids that are
saved to `BASEPATH/results/` and some plots that are shown and saved to
`BASEPATH/plots/`. The example assumes you have already run the example file
`example_multiple_grid_districts.py` and use the option to save the `nd` object
to disc. Make sure to use the same BASEPATH here as in
`example_multiple_grid_districts.py`.
__copyright__ = "Reiner Lemoine Institut gGmbH"
__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)"
__url__ = "https://github.com/openego/ding0/blob/master/LICENSE"
__author__ = "nesnoj, gplssm"
"""

__copyright__ = "Reiner Lemoine Institut gGmbH"
__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)"
__url__ = "https://github.com/openego/ding0/blob/master/LICENSE"
__author__ = "nesnoj, gplssm"

from ding0.tools import results
from ding0.tools.logger import get_default_home_dir
import os
import pandas as pd
from matplotlib import pyplot as plt


BASEPATH = get_default_home_dir()


def ding0_exemplary_plots(stats, base_path=BASEPATH):
"""
Analyze multiple grid district data generated with Ding0
Analyze multiple grid district data generated with Ding0.
Parameters
----------
Expand All @@ -44,13 +45,15 @@ def ding0_exemplary_plots(stats, base_path=BASEPATH):
base_path : str
Root directory of Ding0 data structure, i.e. '~/.ding0' (which is
default).
"""

# make some plot
plotpath = os.path.join(base_path, 'plots')
results.plot_cable_length(stats, plotpath)
plt.show()
results.plot_generation_over_load(stats, plotpath)
results.plot_km_cable_vs_line(stats, plotpath)
plt.show()


def nd_load_and_stats(filenames, base_path=BASEPATH):
Expand All @@ -59,8 +62,8 @@ def nd_load_and_stats(filenames, base_path=BASEPATH):
Passes the list of files assuming the ding0 data structure as default in
:code:`~/.ding0`.
Data will concatenated and key indicators for each grid district are
returned in table and graphic format
Data will be concatenated and key indicators for each grid district are
returned in table and graphic format.
Parameters
----------
Expand All @@ -69,20 +72,22 @@ def nd_load_and_stats(filenames, base_path=BASEPATH):
base_path : str
Root directory of Ding0 data structure, i.e. '~/.ding0' (which is
default).
Returns
-------
stats : pandas.DataFrame
Statistics of each MV grid districts
"""

# load Ding0 data
nds = []
for filename in filenames:
try:
nd_load = results.load_nd_from_pickle(filename=
os.path.join(base_path,
'results',
filename))
os.path.join(base_path,
'grids',
filename))

nds.append(nd_load)
except:
Expand All @@ -94,18 +99,16 @@ def nd_load_and_stats(filenames, base_path=BASEPATH):
for n in nds[1:]:
nd.add_mv_grid_district(n._mv_grid_districts[0])

nodes_df, edges_df = nd.to_dataframe()

# get statistical numbers about grid
stats = results.calculate_mvgd_stats(nodes_df, edges_df)
stats = results.calculate_mvgd_stats(nd)

# TODO: correct LV peak load/ generation capacity. Same in all LV GD
return stats


if __name__ == '__main__':
base_path = BASEPATH

mv_grid_districts = list(range(1, 20))
mv_grid_districts = list(range(1729, 1732))

filenames = ["ding0_grids__{ext}.pkl".format(ext=_)
for _ in mv_grid_districts]
Expand All @@ -115,7 +118,7 @@ def nd_load_and_stats(filenames, base_path=BASEPATH):

# save stats file to disc
stats.to_csv(os.path.join(base_path, 'results',
'ding0_grids_stats_{first}-{last}'.format(
'ding0_grids_stats_{first}-{last}.csv'.format(
first=mv_grid_districts[0],
last=mv_grid_districts[-1])))

Expand Down

0 comments on commit 06e6aeb

Please sign in to comment.