Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
187 commits
Select commit Hold shift + click to select a range
7cd0258
Adding functions for csv export in pypsa format: mv nodes, generators…
AnyaHe Sep 18, 2019
b4b3504
Merge branch 'dev' into feature/refactoring
AnyaHe Sep 19, 2019
194badb
Merge branch 'dev' into feature/refactoring
AnyaHe Sep 19, 2019
5a12944
add function to fill pypsa dataframes for lv grid
AnyaHe Sep 19, 2019
14e25de
Make ready for next release
birgits Sep 20, 2019
330fef2
Fix version numbers in whats new
birgits Sep 20, 2019
4584b0c
move function to fill pypsa_df to GridDing0, finish function network.…
AnyaHe Sep 22, 2019
523a328
add descriptions of new functions
AnyaHe Sep 22, 2019
d3804cd
move function fill_component_dataframes from GridDing0 to pypsa_io
AnyaHe Sep 25, 2019
4d37b6d
change pypsa_id to pypsa_bus_id and make it uniform
AnyaHe Sep 27, 2019
93af19f
introduce test for function network.to_csv()
AnyaHe Sep 27, 2019
8011b75
fixes for tests
AnyaHe Sep 27, 2019
366471b
fix test local routing
AnyaHe Sep 30, 2019
7d4673c
change test for function network.to_csv() in a way that test grid is …
AnyaHe Sep 30, 2019
ddb48c2
open circuit breakers before export
AnyaHe Sep 30, 2019
073708e
Assign id_db at every transformer instantiation
Sep 30, 2019
3e7405e
Merge branch 'fix/#313-transformers-wo-id_db' into feature/refactoring
AnyaHe Oct 1, 2019
b268c08
change naming of lines in a way that it is composed of 'Branch_' and …
AnyaHe Oct 1, 2019
03a24cf
Introduce type specific generators for aggregeated lv_load_areas, fun…
AnyaHe Oct 1, 2019
99dbef1
fix test_rings_full_data
AnyaHe Oct 1, 2019
53d1225
introduce possibility to only export mv grid with aggregated lv_grids
AnyaHe Oct 1, 2019
21a987e
fix test_rings_full_data plus minor fixes
AnyaHe Oct 1, 2019
945eb02
fix load assignment (retail, industrial), extend of test_to_csv() to …
AnyaHe Oct 1, 2019
dab53b0
change handling of isolated nodes
AnyaHe Oct 1, 2019
256af5a
Recover code from branch "fix/#296-cleaning-table-data/"
Oct 2, 2019
dfb0722
Update gitignore
Oct 2, 2019
8d565da
move slack generator to secondary trafo side
AnyaHe Oct 7, 2019
d707c25
introduction of test for run_powerflow (WIP)
AnyaHe Oct 7, 2019
b88de25
Disaggregrate LV generators in exported load areas
AnyaHe Oct 7, 2019
2497fda
Update load area handling, add annual consumption
AnyaHe Oct 8, 2019
1a2bb3d
replace function in run_powerflow by newly implemented functions.
AnyaHe Oct 10, 2019
81dae65
Add circuit breaker handling
AnyaHe Oct 15, 2019
fc53388
Add circuit breaker handling
AnyaHe Oct 15, 2019
1419df1
Merging changes
AnyaHe Oct 15, 2019
daed234
changed test_run_powerflow
AnyaHe Oct 15, 2019
21ec1c5
changed test_run_powerflow
AnyaHe Oct 15, 2019
60764f5
replace old functions for pypsa export
AnyaHe Oct 15, 2019
45228bf
Merge branch 'feature/refactoring' of https://github.com/openego/ding…
AnyaHe Oct 15, 2019
7e3188f
correct unit handling, test modification to also test power flow on l…
AnyaHe Oct 16, 2019
0e39ec8
edit test
AnyaHe Oct 16, 2019
cb835e2
Add docstrings and apply style code
AnyaHe Oct 17, 2019
be815c5
fixes to ensure networkx compatibility with version 2.4
AnyaHe Oct 17, 2019
74a7314
introduce grid property graph
AnyaHe Oct 21, 2019
2282b31
change relocation of circuit breakers to stations
AnyaHe Oct 21, 2019
275cef2
merge dev into branch
AnyaHe Oct 21, 2019
d8c3f6e
fix export switches, export branch of switch
AnyaHe Oct 21, 2019
2f4ffac
add docstring to relocate_circuit_breaker()
AnyaHe Oct 21, 2019
f8d222e
update docstring set_circuit_breakers()
AnyaHe Oct 21, 2019
e80babf
update naming of branches
AnyaHe Oct 22, 2019
7d0104b
fix circuit breakers and branches use right bus of LVStation
AnyaHe Oct 22, 2019
08c064d
fix LVStation representation when only_export_mv
AnyaHe Oct 22, 2019
b453f8f
fix naming of LVStation buses, update line and bus data power flow
AnyaHe Oct 22, 2019
7393534
update line and bus data for mv/lv power flow
AnyaHe Oct 22, 2019
c8a15c7
change exported file names in a way that pypsa can import them easily
AnyaHe Oct 22, 2019
d824f45
change geom into x, y; change voltage level of LV side LVStation when…
AnyaHe Oct 28, 2019
b639947
fix relocate_circuit_breakers()
AnyaHe Oct 28, 2019
b83c5fc
advancement relocate_circuit_breakers(), choose branch differently
AnyaHe Oct 28, 2019
0858366
change load naming of allocated lvgd
AnyaHe Oct 28, 2019
3078c45
fix problems of test_run_powerflow for python 3.5
AnyaHe Oct 28, 2019
c3bffa9
update transformer handling, introduce type_info
AnyaHe Oct 28, 2019
feee3a3
Fix key errors
Nov 6, 2019
caffb0c
Make LV graph name explicit and remove unnecessary iterations thorugh…
Nov 11, 2019
0de5c62
add kind to export of lines
AnyaHe Nov 18, 2019
3329eb5
change naming to be able to split by _
AnyaHe Nov 19, 2019
31c4106
change naming to be able to split by _, update tests
AnyaHe Nov 19, 2019
f661d89
change export to csv in a way that hvmv_transformers are saved to a d…
AnyaHe Nov 19, 2019
39daa89
update example file
AnyaHe Nov 20, 2019
a0265bc
Unique representative for LVLoadDing0
Nov 25, 2019
4710233
Open circuit breakers at beginning of mvgd_stats
Nov 26, 2019
c239226
Fix key errors
Nov 6, 2019
093ffa3
Remove unwanted print statements
Nov 27, 2019
14e7035
Merge pull request #319 from openego/fix/#318-key-error-stats
gplssm Nov 27, 2019
e4e371c
change naming of loads
AnyaHe Nov 28, 2019
98a5def
adapt saving networks in example-files
AnyaHe Nov 28, 2019
22fef5a
Add test for mv_connect_generators()
Dec 11, 2019
dc4f29f
fix handling of empty LVGrids for csv export
AnyaHe Dec 12, 2019
4619ad1
Add test cases that check MVGD stats for each "run_ding0" step
Dec 17, 2019
55b5203
Add dev (tests and docs) requirements
Dec 17, 2019
f7efd6e
Provide oedb_session to all test modules
Dec 18, 2019
37f5adc
Additionally install dev requirements of Travis
Dec 18, 2019
b0fa818
change handling of aggregated load areas for csv export, add transfor…
AnyaHe Dec 18, 2019
6149532
change handling of in_building generators and loads
AnyaHe Jan 6, 2020
d8331f9
Make test_grid_stats() run again and using assert_frame_equal
Jan 27, 2020
a9c0d5d
Fix TestCalculateStats
Jan 27, 2020
725b683
Remove Python 3.4/3.5 from Travis and list pip packages
Jan 27, 2020
9264ab1
Force travis to use Python 3.6.10
Jan 27, 2020
e9ea1a4
Try with bionic
Jan 27, 2020
405c5c1
Remove print statements
Jan 28, 2020
d15b298
Fix test expected data
Jan 28, 2020
c66fee6
Adapt "nodes" access to updated NetworkX version
Jan 28, 2020
724bb46
Fixes test_local_routing()
Jan 29, 2020
544ef13
Add changes to what's new
Jan 29, 2020
925ff53
Update date in README section LECENSE
Jan 29, 2020
b8e8ca8
Remove Python 3.4 and 3.5 from classifiers
Jan 29, 2020
6fc2268
Merge branch 'dev' into fix/#315-deviating-stats
gplssm Jan 29, 2020
45fb84b
Update pandas version
Jun 8, 2020
53d3a2a
Update pyproj version to >2
Jun 8, 2020
0eaabc3
Merge pull request #328 from openego/fix/#327-installation-fails
gplssm Jun 8, 2020
92b2b7a
Fix #329
Jun 9, 2020
455b469
Merge pull request #330 from openego/fix/#329-pandas-pyproj-version-r…
gplssm Jun 9, 2020
0323e5c
Use updated (unreleased) version of ego.io with fixed type
Jun 9, 2020
24c4d3a
Merge pull request #331 from openego/fix/#326-str-breaks-sum-capacity…
gplssm Jun 9, 2020
0a65bd7
Update requirements
birgits Jul 21, 2020
916ccc4
Fix capacity of transformers, make sure it is a float when imported
AnyaHe Aug 10, 2020
2c415db
fix #332: if lv grids are exported as well, export secondary side bus…
AnyaHe Aug 10, 2020
ca72c4b
Update requirements to resolve dependency conflicts
Feb 8, 2021
aad677b
Formatting
Feb 8, 2021
96c637e
Fix typo in function name
Feb 8, 2021
e568212
Introduce MV/LV transformer station for aggregated LV grid load/gener…
gplssm Feb 8, 2021
c809222
Update LV bus + line comparison data for test_run_powerflow()
Feb 15, 2021
56bf96d
fix routing tests by changing DF index
nesnoj May 7, 2021
eaedd70
fix tests: pandas from_csv -> read_csv
nesnoj May 7, 2021
67b3de4
fix pep8
nesnoj May 7, 2021
eb1fa1b
fix pep8
nesnoj May 7, 2021
da30079
fix pep8
nesnoj May 7, 2021
79707f3
fix pandas' read_csv
nesnoj May 7, 2021
154e124
Merge branch 'feature/refactoring' into fix/#322_in_building_load_and…
nesnoj May 7, 2021
9ea52cb
fix conflicting args in test test_to_csv
nesnoj May 7, 2021
2eba4cb
pep8
nesnoj May 10, 2021
d143ab3
pep8
nesnoj May 10, 2021
6a944e5
update changelog
nesnoj May 10, 2021
5acc1e8
Merge pull request #323 from openego/fix/#322_in_building_load_and_ge…
nesnoj May 10, 2021
48bfbbf
Merge pull request #324 from openego/fix/#315-deviating-stats
nesnoj May 10, 2021
43c7040
Merge branch 'dev' into feature/refactoring
nesnoj May 10, 2021
0dccb4f
pep8
nesnoj May 11, 2021
c72a8b6
fix test: test_local_routing flawed by node renaming
nesnoj May 11, 2021
da26ffc
fix test data due to changed line and bus names
nesnoj May 12, 2021
81868ab
fix graphml test data due to changed line and bus names
nesnoj May 12, 2021
09f087d
add code snippet to export graph for comparison purposes
nesnoj May 13, 2021
03bd0b0
update test data for test_grid_stats
nesnoj May 14, 2021
0fde313
modify result test to comply with changed branch id naming
nesnoj May 17, 2021
95137cf
update docstring
nesnoj May 17, 2021
9349feb
make circuit breaker more failsafe: only open/close if not already op…
nesnoj May 17, 2021
9531bff
fix stats test: remove set branch id test and create new stat files
nesnoj May 17, 2021
bb7e106
rm obsolete pytest dependency
nesnoj May 17, 2021
2b80217
Merge pull request #312 from openego/feature/refactoring
nesnoj May 17, 2021
7f0e28b
migrate from geopy's vincenty() to distance()
nesnoj May 17, 2021
33e7641
add pytest-parallel to dev reqs
nesnoj May 17, 2021
72e0158
fix creation of pandas' DatetimeIndex
nesnoj May 17, 2021
6df9fce
fix graphml test data due to changed file format
nesnoj May 18, 2021
81c0a77
mv snippet
nesnoj May 18, 2021
de83409
fix tests by explicitly adding index name
nesnoj May 18, 2021
a4294ba
test update requirements
nesnoj May 18, 2021
4b19f9d
split matching edge attributes into numerical and catergorical
nesnoj May 19, 2021
35d4d82
Merge pull request #342 from openego/fix/#341_test_for_isomorphism
nesnoj May 19, 2021
9782913
update SPDX classifier
nesnoj May 19, 2021
17694df
change way of CRS transformation method due to pyproj update
nesnoj May 19, 2021
1873d33
fix overlooked parts
nesnoj May 19, 2021
ba3fb10
Merge pull request #344 from openego/fix/#343_update_pyproj_crs_trans…
nesnoj May 19, 2021
ed0e775
rm unused imports
nesnoj May 19, 2021
4977734
replace pandas.util.testing by pandas.testing
nesnoj May 19, 2021
e26e7a6
rm unused import
nesnoj May 19, 2021
3e88d3c
fix literal
nesnoj May 19, 2021
780fa08
fix pandas' FutureWarning: Indexing with multiple keys
nesnoj May 19, 2021
395f3a0
update requirements
nesnoj May 19, 2021
5ffc938
update requirements
nesnoj May 19, 2021
f7477fa
update RTD requirements
nesnoj May 19, 2021
aeeaef5
fix typos
nesnoj May 19, 2021
018d27e
fix whatsnew list
nesnoj May 19, 2021
68008cf
bump version
nesnoj May 19, 2021
e3e1288
update whatsnew
nesnoj May 20, 2021
86dcb0d
rm old release file
nesnoj May 20, 2021
0426b5d
update whatsnew
nesnoj May 28, 2021
831ce7e
Merge pull request #340 from openego/features/#325_add_python3.8_support
nesnoj May 28, 2021
7b0c2db
fix #311
nesnoj May 28, 2021
9590937
update whatsnew
nesnoj May 28, 2021
da2440f
update install notes
nesnoj May 28, 2021
ea7a0ce
update reqs in conda env
nesnoj May 28, 2021
ee8f5de
adjust headings
nesnoj May 28, 2021
01b86be
update getting started
nesnoj May 28, 2021
bc3b7f4
update install notes
nesnoj May 28, 2021
ab8f3b8
Merge pull request #350 from openego/fix/#339_conda_installation
nesnoj May 28, 2021
6762e1a
update install notes
nesnoj May 28, 2021
3d0961d
move tests scripts to subdir
nesnoj May 28, 2021
f99fc22
add warning for install test scripts
nesnoj May 28, 2021
6b701ad
fix typo
nesnoj May 28, 2021
6825099
adjust dev doc
nesnoj May 28, 2021
10575b6
Merge pull request #351 from openego/fix/#348_revise_install_shell_sc…
nesnoj May 28, 2021
f42aa38
add note on tests to dev doc
nesnoj May 28, 2021
cdb4340
update whatsnew
nesnoj May 28, 2021
ee812ee
update author and license short name
nesnoj May 28, 2021
861ebc0
add win to OS classifiers
nesnoj May 28, 2021
a129309
adjust version in doc's conf
nesnoj May 28, 2021
1b8e4e6
set python version to 3.8 in RTD's yml
nesnoj May 28, 2021
4b3db22
fix whatnew
nesnoj May 28, 2021
98da8b4
add blank line to test RTD webhook
nesnoj May 28, 2021
07f86fc
fix whatnew
nesnoj May 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var/
*.egg-info/
.installed.cfg
*.egg
doc/_html/
.idea/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -56,6 +58,9 @@ doc/_build/
# PyBuilder
target/

# Data
.pkl




Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ formats: all

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.6
version: 3.8
install:
- requirements: rtd_requirements.txt
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
dist: bionic
language: python
python:
- "3.4"
- "3.5"
- "3.6"
- "3.6.10"
# - "3.7"
# command to install dependencies
install:
- pip install -r requirements.txt
- pip install -r requirements.txt -r dev_requirements.txt
- pip freeze
# command to run tests
script:
- pytest -vv
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
DING0
=====
DIstribution Network GeneratOr -- A tool to generate synthetic medium and low
voltage power distribution grids based on open (or at least accessible) data.
voltage power distribution grids based on open (or at least publicly available)
data.

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

Ding0 is provided through the package management tool *pip*. Install it by

```
pip3 install ding0
pip install ding0
```

Further details regarding the installation including dependencies are provided
Expand All @@ -24,12 +25,13 @@ in the [documentation](https://dingo.readthedocs.io)
A [set of examples](https://dingo.readthedocs.io/en/dev/usage_details.html#examples)
is provided to show how to use Ding0.

An overview on versions of data already generated [can be found in the wiki](https://github.com/openego/ding0/wiki/Ding0-datasets).
An overview on versions of data already generated
[can be found in the wiki](https://github.com/openego/ding0/wiki/Ding0-datasets).

LICENSE
-------

Copyright (C) 2017 openego project group
Copyright (C) 2017-2021 openego project group

This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License as published by the Free
Expand Down
5 changes: 5 additions & 0 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pytest
pytest-dependency
pytest-parallel
sphinx
sphinx_rtd_theme
164 changes: 118 additions & 46 deletions ding0/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
from ding0.core.network.stations import *
from ding0.core.structure.regions import *
from ding0.core.powerflow import *
from ding0.tools import pypsa_io
from ding0.tools.pypsa_io import initialize_component_dataframes, fill_mvgd_component_dataframes
from ding0.tools.animation import AnimationDing0
from ding0.tools.plots import plot_mv_topology
from ding0.flexopt.reinforce_grid import *
from ding0.tools.logger import get_default_home_dir
from ding0.tools.tools import merge_two_dicts_of_dataframes

import os
import logging
Expand All @@ -38,6 +40,7 @@
from sqlalchemy import func
from geoalchemy2.shape import from_shape
import subprocess
import json
import oedialect

if not 'READTHEDOCS' in os.environ:
Expand Down Expand Up @@ -266,33 +269,28 @@ def run_ding0(self, session, mv_grid_districts_no=None, debug=False, export_figu
Generators are connected to grids, used approach depends on voltage
level.

* STEP 8: Set IDs for all branches in MV and LV grids

While IDs of imported objects can be derived from dataset's ID, branches
are created in steps 5+6 and need unique IDs (e.g. for PF calculation).

* STEP 9: Relocate switch disconnectors in MV grid
* STEP 8: Relocate switch disconnectors in MV grid

Switch disconnectors are set during routing process (step 6) according
to the load distribution within a ring. After further modifications of
the grid within step 6+7 they have to be relocated (note: switch
disconnectors are called circuit breakers in DING0 for historical reasons).

* STEP 10: Open all switch disconnectors in MV grid
* STEP 9: Open all switch disconnectors in MV grid

Under normal conditions, rings are operated in open state (half-rings).
Furthermore, this is required to allow powerflow for MV grid.

* STEP 11: Do power flow analysis of MV grid
* STEP 10: Do power flow analysis of MV grid

The technically working MV grid created in step 6 was extended by satellite
loads and generators. It is finally tested again using powerflow calculation.

* STEP 12: Reinforce MV grid
* STEP 11: Reinforce MV grid

MV grid is eventually reinforced persuant to results from step 11.

STEP 13: Close all switch disconnectors in MV grid
* STEP 12: Close all switch disconnectors in MV grid
The rings are finally closed to hold a complete graph (if the SDs are open,
the edges adjacent to a SD will not be exported!)
"""
Expand Down Expand Up @@ -326,18 +324,15 @@ def run_ding0(self, session, mv_grid_districts_no=None, debug=False, export_figu
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
# STEP 8: 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
# STEP 9: Open all switch disconnectors in MV grid
self.control_circuit_breakers(mode='open')

# STEP 11: Do power flow analysis of MV grid
# STEP 10: 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)',
Expand All @@ -347,10 +342,10 @@ def run_ding0(self, session, mv_grid_districts_no=None, debug=False, export_figu
filename='5_PF_result_feedin.png',
line_color='loading', node_color='voltage', testcase='feedin')

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

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

if export_figures:
Expand Down Expand Up @@ -979,7 +974,7 @@ def import_res_generators():
generator = GeneratorFluctuatingDing0(
id_db=id_db,
mv_grid=mv_grid,
capacity=row['electrical_capacity'],
capacity=float(row['electrical_capacity']),
type=row['generation_type'],
subtype=row['generation_subtype'],
v_level=int(row['voltage_level']),
Expand All @@ -988,7 +983,7 @@ def import_res_generators():
generator = GeneratorDing0(
id_db=id_db,
mv_grid=mv_grid,
capacity=row['electrical_capacity'],
capacity=float(row['electrical_capacity']),
type=row['generation_type'],
subtype=row['generation_subtype'],
v_level=int(row['voltage_level']))
Expand Down Expand Up @@ -1349,7 +1344,7 @@ def validate_grid_districts(self):
for grid_district in self.mv_grid_districts():

# there's only one node (MV station) => grid is empty
if len(grid_district.mv_grid._graph.nodes()) == 1:
if len(grid_district.mv_grid.graph.nodes()) == 1:
invalid_mv_grid_districts.append(grid_district)
msg_invalidity.append('MV Grid District {} seems to be empty ' \
'and ' \
Expand Down Expand Up @@ -1412,7 +1407,7 @@ def export_mv_grid(self, session, mv_grid_districts):
lines = []

# get nodes from grid's graph and append to corresponding array
for node in grid_district.mv_grid._graph.nodes():
for node in grid_district.mv_grid.graph.nodes():
if isinstance(node, LVLoadAreaCentreDing0):
lv_load_area_centres.append((node.geo_data.x, node.geo_data.y))
elif isinstance(node, MVCableDistributorDing0):
Expand Down Expand Up @@ -1527,7 +1522,7 @@ def export_mv_grid_new(self, session, mv_grid_districts):
for grid_district in self.mv_grid_districts():

# get nodes from grid's graph and create datasets
for node in grid_district.mv_grid._graph.nodes():
for node in grid_district.mv_grid.graph.nodes():
if hasattr(node, 'voltage_res'):
node_name = '_'.join(['MV',
str(grid_district.mv_grid.id_db),
Expand Down Expand Up @@ -1610,8 +1605,9 @@ def export_mv_grid_new(self, session, mv_grid_districts):

logger.info('=====> MV Grids exported (NEW)')

def to_dataframe(self):
def to_dataframe_old(self):
"""
Todo: remove? or replace by part of to_csv()
Export grid data to dataframes for statistical analysis.

The export to dataframe is similar to db tables exported by `export_mv_grid_new`.
Expand Down Expand Up @@ -1728,6 +1724,95 @@ def to_dataframe(self):

return nodes_df, edges_df

def to_csv(self, dir = '', only_export_mv = False):
'''
Function to export network to csv. Converts network in dataframes which are adapted to pypsa format.
Respectively saves files for network, buses, lines, transformers, loads and generators.

Parameters
----------
dir: :obj:`str`
Directory to which network is saved.
only_export_mv: bool
When True only mv topology is exported with aggregated lv grid districts
'''

buses_df, generators_df, lines_df, loads_df, transformer_df = initialize_component_dataframes()
if (dir == ''):
dir = get_default_home_dir() # eventuell ändern
# open all switch connectors
self.control_circuit_breakers(mode='open')
# start filling component dataframes
for grid_district in self.mv_grid_districts():
gd_components, network_df, _ = fill_mvgd_component_dataframes(
grid_district, buses_df, generators_df,
lines_df, loads_df,transformer_df, only_export_mv)
# save network and components to csv
path = os.path.join(dir, str(grid_district.id_db))
if not os.path.exists(path):
os.makedirs(path)
network_df.to_csv(os.path.join(path, 'network.csv'))
gd_components['HVMV_Transformer'].to_csv(
os.path.join(path, 'transformers_hvmv.csv'))
gd_components['Transformer'].to_csv(
os.path.join(path, 'transformers.csv'))
gd_components['Bus'].to_csv(
os.path.join(path, 'buses.csv'))
gd_components['Line'].to_csv(
os.path.join(path, 'lines.csv'))
gd_components['Load'].to_csv(
os.path.join(path, 'loads.csv'))
gd_components['Generator'].to_csv(
os.path.join(path, 'generators.csv'))
gd_components['Switch'].to_csv(
os.path.join(path, 'switches.csv'))

# Merge metadata of multiple runs
if 'metadata' not in locals():
metadata = self.metadata

else:
if isinstance(grid_district, list):
metadata['mv_grid_districts'].extend(grid_district)
else:
metadata['mv_grid_districts'].append(grid_district)

# Save metadata to disk
with open(os.path.join(path, 'Ding0_{}.meta'.format(metadata['run_id'])),
'w') as f:
json.dump(metadata, f)


def to_dataframe(self, only_export_mv = False):
'''
Function to export network to csv. Converts network in dataframes which are adapted to pypsa format.
Respectively saves files for network, buses, lines, transformers, loads and generators.

Parameters
----------
only_export_mv: bool
When True only mv topology is exported with aggregated lv grid districts
'''
buses_df, generators_df, lines_df, loads_df, transformer_df = initialize_component_dataframes()
components = {}
networks = pd.DataFrame()
# open all switch connectors
self.control_circuit_breakers(mode='open')
# start filling component dataframes
for grid_district in self.mv_grid_districts():
gd_components, network_df, _ = fill_mvgd_component_dataframes(grid_district, buses_df, generators_df,
lines_df, loads_df, transformer_df, only_export_mv)
if len(components) == 0:
components = gd_components
networks = network_df
else:
components = merge_two_dicts_of_dataframes(components, gd_components)
networks = networks.append(network_df)

components['Network'] = network_df
return components


def mv_routing(self, debug=False, animation=False):
"""
Performs routing on all MV grids.
Expand Down Expand Up @@ -1825,21 +1910,6 @@ def mv_parametrize_grid(self, debug=False):

logger.info('=====> MV Grids parametrized')

def set_branch_ids(self):
"""
Performs generation and setting of ids
of branches for all MV and underlying LV grids.

See Also
--------
ding0.core.network.grids.MVGridDing0.set_branch_ids
"""

for grid_district in self.mv_grid_districts():
grid_district.mv_grid.set_branch_ids()

logger.info('=====> Branch IDs set')

def set_circuit_breakers(self, debug=False):
"""
Calculates the optimal position of the existing circuit breakers
Expand Down Expand Up @@ -1884,7 +1954,7 @@ def control_circuit_breakers(self, mode=None):
elif mode == 'close':
logger.info('=====> MV Circuit Breakers closed')

def run_powerflow(self, session, method='onthefly', export_pypsa=False, debug=False):
def run_powerflow(self, session = None, method='onthefly', only_calc_mv = True, export_pypsa=False, debug=False, export_result_dir=None):
"""
Performs power flow calculation for all MV grids

Expand Down Expand Up @@ -1915,20 +1985,22 @@ def run_powerflow(self, session, method='onthefly', export_pypsa=False, debug=Fa
export_pypsa_dir = repr(grid_district.mv_grid)
else:
export_pypsa_dir = None
grid_district.mv_grid.run_powerflow(session, method='db',
grid_district.mv_grid.run_powerflow(method='db',
export_pypsa_dir=export_pypsa_dir,
debug=debug)
debug=debug,
export_result_dir=export_result_dir)

elif method == 'onthefly':
for grid_district in self.mv_grid_districts():
if export_pypsa:
export_pypsa_dir = repr(grid_district.mv_grid)
else:
export_pypsa_dir = None
grid_district.mv_grid.run_powerflow(session,
method='onthefly',
grid_district.mv_grid.run_powerflow(method='onthefly',
only_calc_mv = only_calc_mv,
export_pypsa_dir=export_pypsa_dir,
debug=debug)
debug=debug,
export_result_dir=export_result_dir)

def reinforce_grid(self):
"""
Expand Down
Loading