Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
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
1 change: 1 addition & 0 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pytest
pytest-dependency
pytest-parallel
sphinx
sphinx_rtd_theme
16 changes: 6 additions & 10 deletions ding0/core/network/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@
from ding0.grid.mv_grid import mv_routing, mv_connect
from ding0.grid.lv_grid import build_grid, lv_connect
from ding0.tools import config as cfg_ding0, pypsa_io, tools
from ding0.tools.geo import calc_geo_dist_vincenty
from ding0.tools.geo import calc_geo_dist
from ding0.grid.mv_grid.tools import set_circuit_breakers
from ding0.flexopt.reinforce_grid import *
from ding0.core.structure.regions import LVLoadAreaCentreDing0
from ding0.tools.pypsa_io import initialize_component_dataframes, fill_mvgd_component_dataframes

import os
import logging
import networkx as nx
from datetime import datetime
import pyproj
from functools import partial
import logging
from pyproj import Transformer

if not 'READTHEDOCS' in os.environ:
from shapely.ops import transform
Expand Down Expand Up @@ -207,7 +206,7 @@ def rings_nodes(self, include_root_node=False, include_satellites=False):
Circuit breakers must be closed to find rings, this is done automatically.
"""
for circ_breaker in self.circuit_breakers():
if circ_breaker.status is 'open':
if circ_breaker.status == 'open':
circ_breaker.close()
logger.info('Circuit breakers were closed in order to find MV '
'rings')
Expand Down Expand Up @@ -469,10 +468,7 @@ def set_voltage_level(self, mode='distance'):

# transform MVGD's area to epsg 3035
# to achieve correct area calculation
projection = partial(
pyproj.transform,
pyproj.Proj(init='epsg:4326'), # source coordinate system
pyproj.Proj(init='epsg:3035')) # destination coordinate system
projection = Transformer.from_crs("epsg:4326", "epsg:3035", always_xy=True).transform

# calculate load density
kw2mw = 1e-3
Expand Down Expand Up @@ -501,7 +497,7 @@ def set_voltage_level(self, mode='distance'):
for node in self.graph_nodes_sorted():
if isinstance(node, LVLoadAreaCentreDing0):
# calc distance from MV-LV station to LA centre
dist_node = calc_geo_dist_vincenty(self.station(), node) / 1e3
dist_node = calc_geo_dist(self.station(), node) / 1e3
if dist_node > dist_max:
dist_max = dist_node

Expand Down
8 changes: 4 additions & 4 deletions ding0/core/powerflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


from datetime import datetime
from pandas import DatetimeIndex
from pandas import DatetimeIndex, date_range


class PFConfigDing0:
Expand Down Expand Up @@ -74,9 +74,9 @@ def __init__(self, **kwargs):
# create pandas DatetimeIndex object for given values
self._timeranges = []
for _ in enumerate(self._scenarios):
self._timeranges.append(DatetimeIndex(freq=self._resolution,
periods=timesteps_count,
start=timestep_start))
self._timeranges.append(date_range(freq=self._resolution,
periods=timesteps_count,
start=timestep_start))

elif len(self._scenarios) != len(self._timeranges):
raise ValueError('PF config: Count of scenarios has to equal count of timeranges.')
Expand Down
4 changes: 2 additions & 2 deletions ding0/grid/lv_grid/lv_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ding0.core.network import BranchDing0

from ding0.tools import config as cfg_ding0
from ding0.tools.geo import calc_geo_dist_vincenty
from ding0.tools.geo import calc_geo_dist
from ding0.grid.tools import cable_type
import logging
import random
Expand Down Expand Up @@ -78,7 +78,7 @@ def lv_connect_generators(lv_grid_district, graph, debug=False):
if generator.v_level == 6:
lv_station = lv_grid_district.lv_grid.station()

branch_length = calc_geo_dist_vincenty(generator, lv_station)
branch_length = calc_geo_dist(generator, lv_station)
branch_type = cable_type(
generator.capacity / (cable_lf * cos_phi_gen),
v_nom,
Expand Down
58 changes: 18 additions & 40 deletions ding0/grid/mv_grid/mv_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@


import os
import pyproj
from functools import partial
import time
import logging
from pyproj import Transformer

from ding0.core.network.stations import *
from ding0.core.network import BranchDing0, GeneratorDing0
from ding0.core import MVCableDistributorDing0
from ding0.core.structure.groups import LoadAreaGroupDing0
from ding0.core.structure.regions import LVLoadAreaCentreDing0
from ding0.tools import config as cfg_ding0
from ding0.tools.geo import calc_geo_branches_in_buffer,calc_geo_dist_vincenty,\
from ding0.tools.geo import calc_geo_branches_in_buffer,calc_geo_dist,\
calc_geo_centre_point, calc_geo_branches_in_polygon

if not 'READTHEDOCS' in os.environ:
Expand Down Expand Up @@ -407,7 +406,7 @@ def connect_node(node, node_shp, mv_grid, target_obj, proj, graph, conn_dist_rin
# along node)
graph.remove_edge(adj_node1, adj_node2)

branch_length = calc_geo_dist_vincenty(adj_node1, node)
branch_length = calc_geo_dist(adj_node1, node)
branch = BranchDing0(length=branch_length,
circuit_breaker=circ_breaker,
kind=branch_kind,
Expand All @@ -418,7 +417,7 @@ def connect_node(node, node_shp, mv_grid, target_obj, proj, graph, conn_dist_rin
circ_breaker.branch = branch
graph.add_edge(adj_node1, node, branch=branch)

branch_length = calc_geo_dist_vincenty(adj_node2, node)
branch_length = calc_geo_dist(adj_node2, node)
graph.add_edge(adj_node2, node, branch=BranchDing0(length=branch_length,
kind=branch_kind,
grid=mv_grid,
Expand Down Expand Up @@ -456,7 +455,7 @@ def connect_node(node, node_shp, mv_grid, target_obj, proj, graph, conn_dist_rin

graph.remove_edge(adj_node1, adj_node2)

branch_length = calc_geo_dist_vincenty(adj_node1, cable_dist)
branch_length = calc_geo_dist(adj_node1, cable_dist)
branch = BranchDing0(length=branch_length,
circuit_breaker=circ_breaker,
kind=branch_kind,
Expand All @@ -467,7 +466,7 @@ def connect_node(node, node_shp, mv_grid, target_obj, proj, graph, conn_dist_rin
circ_breaker.branch = branch
graph.add_edge(adj_node1, cable_dist, branch=branch)

branch_length = calc_geo_dist_vincenty(adj_node2, cable_dist)
branch_length = calc_geo_dist(adj_node2, cable_dist)
graph.add_edge(adj_node2, cable_dist, branch=BranchDing0(length=branch_length,
kind=branch_kind,
grid=mv_grid,
Expand All @@ -481,7 +480,7 @@ def connect_node(node, node_shp, mv_grid, target_obj, proj, graph, conn_dist_rin
branch_kind = mv_grid.default_branch_kind
branch_type = mv_grid.default_branch_type

branch_length = calc_geo_dist_vincenty(node, cable_dist)
branch_length = calc_geo_dist(node, cable_dist)
graph.add_edge(node, cable_dist, branch=BranchDing0(length=branch_length,
kind=branch_kind,
grid=mv_grid,
Expand Down Expand Up @@ -529,7 +528,7 @@ def connect_node(node, node_shp, mv_grid, target_obj, proj, graph, conn_dist_rin
branch_ring = mv_grid.get_ring_from_node(target_obj['obj'])

# add new branch for satellite (station to station)
branch_length = calc_geo_dist_vincenty(node, target_obj['obj'])
branch_length = calc_geo_dist(node, target_obj['obj'])
graph.add_edge(node, target_obj['obj'], branch=BranchDing0(length=branch_length,
kind=branch_kind,
grid=mv_grid,
Expand Down Expand Up @@ -576,7 +575,7 @@ def disconnect_node(node, target_obj_result, graph, debug):
if len(neighbor_nodes) == 2:
node.grid.remove_cable_distributor(target_obj_result)

branch_length = calc_geo_dist_vincenty(neighbor_nodes[0], neighbor_nodes[1])
branch_length = calc_geo_dist(neighbor_nodes[0], neighbor_nodes[1])
graph.add_edge(neighbor_nodes[0], neighbor_nodes[1], branch=BranchDing0(length=branch_length,
kind=branch_kind,
grid=node.grid,
Expand Down Expand Up @@ -663,16 +662,9 @@ def mv_connect_satellites(mv_grid, graph, mode='normal', debug=False):
start = time.time()

# WGS84 (conformal) to ETRS (equidistant) projection
proj1 = partial(
pyproj.transform,
pyproj.Proj(init='epsg:4326'), # source coordinate system
pyproj.Proj(init='epsg:3035')) # destination coordinate system

proj1 = Transformer.from_crs("epsg:4326", "epsg:3035", always_xy=True).transform
# ETRS (equidistant) to WGS84 (conformal) projection
proj2 = partial(
pyproj.transform,
pyproj.Proj(init='epsg:3035'), # source coordinate system
pyproj.Proj(init='epsg:4326')) # destination coordinate system
proj2 = Transformer.from_crs("epsg:3035", "epsg:4326", always_xy=True).transform

# check all nodes
if mode == 'normal':
Expand Down Expand Up @@ -748,16 +740,9 @@ def mv_connect_stations(mv_grid_district, graph, debug=False):
"""

# WGS84 (conformal) to ETRS (equidistant) projection
proj1 = partial(
pyproj.transform,
pyproj.Proj(init='epsg:4326'), # source coordinate system
pyproj.Proj(init='epsg:3035')) # destination coordinate system

proj1 = Transformer.from_crs("epsg:4326", "epsg:3035", always_xy=True).transform
# ETRS (equidistant) to WGS84 (conformal) projection
proj2 = partial(
pyproj.transform,
pyproj.Proj(init='epsg:3035'), # source coordinate system
pyproj.Proj(init='epsg:4326')) # destination coordinate system
proj2 = Transformer.from_crs("epsg:3035", "epsg:4326", always_xy=True).transform

conn_dist_weight = cfg_ding0.get('mv_connect', 'load_area_sat_conn_dist_weight')
conn_dist_ring_mod = cfg_ding0.get('mv_connect', 'load_area_stat_conn_dist_ring_mod')
Expand Down Expand Up @@ -793,7 +778,7 @@ def mv_connect_stations(mv_grid_district, graph, debug=False):
# delete old branch to Load Area centre and create a new one to LV station
graph.remove_edge(lv_load_area_centre, node)

branch_length = calc_geo_dist_vincenty(lv_station, node)
branch_length = calc_geo_dist(lv_station, node)
branch = BranchDing0(length=branch_length,
circuit_breaker=circ_breaker,
kind=branch_kind,
Expand Down Expand Up @@ -876,7 +861,7 @@ def mv_connect_stations(mv_grid_district, graph, debug=False):
# delete old branch to Load Area centre and create a new one to LV station
graph.remove_edge(lv_load_area_centre, node)

branch_length = calc_geo_dist_vincenty(cable_dist, node)
branch_length = calc_geo_dist(cable_dist, node)
branch = BranchDing0(length=branch_length,
circuit_breaker=circ_breaker,
kind=branch_kind,
Expand Down Expand Up @@ -930,24 +915,17 @@ def mv_connect_generators(mv_grid_district, graph, debug=False):
generator_buffer_radius_inc = cfg_ding0.get('mv_connect', 'generator_buffer_radius_inc')

# WGS84 (conformal) to ETRS (equidistant) projection
proj1 = partial(
pyproj.transform,
pyproj.Proj(init='epsg:4326'), # source coordinate system
pyproj.Proj(init='epsg:3035')) # destination coordinate system

proj1 = Transformer.from_crs("epsg:4326", "epsg:3035", always_xy=True).transform
# ETRS (equidistant) to WGS84 (conformal) projection
proj2 = partial(
pyproj.transform,
pyproj.Proj(init='epsg:3035'), # source coordinate system
pyproj.Proj(init='epsg:4326')) # destination coordinate system
proj2 = Transformer.from_crs("epsg:3035", "epsg:4326", always_xy=True).transform

for generator in sorted(mv_grid_district.mv_grid.generators(), key=lambda x: repr(x)):

# ===== voltage level 4: generator has to be connected to MV station =====
if generator.v_level == 4:
mv_station = mv_grid_district.mv_grid.station()

branch_length = calc_geo_dist_vincenty(generator, mv_station)
branch_length = calc_geo_dist(generator, mv_station)

# TODO: set branch type to something reasonable (to be calculated)
branch_kind = mv_grid_district.mv_grid.default_branch_kind
Expand Down
6 changes: 3 additions & 3 deletions ding0/grid/mv_grid/mv_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ding0.grid.mv_grid.models.models import Graph, Node
from ding0.grid.mv_grid.util import util, data_input
from ding0.grid.mv_grid.solvers import savings, local_search
from ding0.tools.geo import calc_geo_dist_vincenty, calc_geo_dist_matrix_vincenty, calc_geo_centre_point
from ding0.tools.geo import calc_geo_dist, calc_geo_dist_matrix, calc_geo_centre_point
from ding0.tools import config as cfg_ding0
from ding0.core.network.stations import *
from ding0.core.structure.regions import LVLoadAreaCentreDing0
Expand Down Expand Up @@ -93,7 +93,7 @@ def ding0_graph_to_routing_specs(graph):

specs['NODE_COORD_SECTION'] = nodes_pos
specs['DEMAND'] = nodes_demands
specs['MATRIX'] = calc_geo_dist_matrix_vincenty(nodes_pos)
specs['MATRIX'] = calc_geo_dist_matrix(nodes_pos)
specs['IS_AGGREGATED'] = nodes_agg

return specs
Expand Down Expand Up @@ -204,7 +204,7 @@ def routing_solution_to_ding0_graph(graph, solution):
node1.lv_load_area.ring = ring

# set branch length
b.length = calc_geo_dist_vincenty(node1, node2)
b.length = calc_geo_dist(node1, node2)

# set branch kind and type
# 1) default
Expand Down
36 changes: 14 additions & 22 deletions ding0/tools/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@


import os
from geopy.distance import vincenty
import pyproj
from functools import partial
from geopy.distance import geodesic
from pyproj import Transformer

from ding0.tools import config as cfg_ding0
import logging
Expand Down Expand Up @@ -116,7 +115,7 @@ def calc_geo_branches_in_buffer(node, mv_grid, radius, radius_inc, proj):
return branches


def calc_geo_dist_vincenty(node_source, node_target):
def calc_geo_dist(node_source, node_target):
""" Calculates the geodesic distance between `node_source` and `node_target`
incorporating the detour factor specified in :file:`ding0/ding0/config/config_calc.cfg`.

Expand All @@ -135,8 +134,8 @@ def calc_geo_dist_vincenty(node_source, node_target):

branch_detour_factor = cfg_ding0.get('assumptions', 'branch_detour_factor')

# notice: vincenty takes (lat,lon)
branch_length = branch_detour_factor * vincenty((node_source.geo_data.y, node_source.geo_data.x),
# notice: geodesic takes (lat,lon)
branch_length = branch_detour_factor * geodesic((node_source.geo_data.y, node_source.geo_data.x),
(node_target.geo_data.y, node_target.geo_data.x)).m

# ========= BUG: LINE LENGTH=0 WHEN CONNECTING GENERATORS ===========
Expand All @@ -152,14 +151,13 @@ def calc_geo_dist_vincenty(node_source, node_target):
return branch_length


def calc_geo_dist_matrix_vincenty(nodes_pos):
def calc_geo_dist_matrix(nodes_pos):
""" Calculates the geodesic distance between all nodes in `nodes_pos` incorporating the detour factor in config_calc.cfg.

For every two points/coord it uses geopy's vincenty function (formula devised by Thaddeus Vincenty,
with an accurate ellipsoidal model of the earth). As default ellipsoidal model of the earth WGS-84 is used.
For every two points/coord it uses geopy's geodesic function. As default ellipsoidal model of the earth WGS-84 is used.
For more options see

https://geopy.readthedocs.org/en/1.10.0/index.html?highlight=vincenty#geopy.distance.vincenty
https://geopy.readthedocs.io/en/stable/index.html?highlight=geodesic#geopy.distance.geodesic

Parameters
----------
Expand Down Expand Up @@ -196,8 +194,8 @@ def calc_geo_dist_matrix_vincenty(nodes_pos):

for j in nodes_pos:
pos_dest = tuple(nodes_pos[j])
# notice: vincenty takes (lat,lon), thus the (x,y)/(lon,lat) tuple is reversed
distance = branch_detour_factor * vincenty(tuple(reversed(pos_origin)), tuple(reversed(pos_dest))).km
# notice: geodesic takes (lat,lon), thus the (x,y)/(lon,lat) tuple is reversed
distance = branch_detour_factor * geodesic(tuple(reversed(pos_origin)), tuple(reversed(pos_dest))).km
matrix[i][j] = distance

return matrix
Expand All @@ -220,20 +218,14 @@ def calc_geo_centre_point(node_source, node_target):
Distance in m.
"""

proj_source = partial(
pyproj.transform,
pyproj.Proj(init='epsg:4326'), # source coordinate system
pyproj.Proj(init='epsg:3035')) # destination coordinate system

# WGS84 (conformal) to ETRS (equidistant) projection
proj_source = Transformer.from_crs("epsg:4326", "epsg:3035", always_xy=True).transform
# ETRS (equidistant) to WGS84 (conformal) projection
proj_target = partial(
pyproj.transform,
pyproj.Proj(init='epsg:3035'), # source coordinate system
pyproj.Proj(init='epsg:4326')) # destination coordinate system
proj_target = Transformer.from_crs("epsg:3035", "epsg:4326", always_xy=True).transform

branch_shp = transform(proj_source, LineString([node_source.geo_data, node_target.geo_data]))

distance = vincenty((node_source.geo_data.y, node_source.geo_data.x),
distance = geodesic((node_source.geo_data.y, node_source.geo_data.x),
(node_target.geo_data.y, node_target.geo_data.x)).m

centre_point_shp = transform(proj_target, branch_shp.interpolate(distance/2))
Expand Down
Loading