From 8f90a1c16a122272545ea72be3cf403c8333fc8a Mon Sep 17 00:00:00 2001 From: nesnoj Date: Fri, 6 Oct 2017 14:47:02 +0200 Subject: [PATCH] merge dev into features/#21-import-connect-genos --- doc/eDisGo_UML.graphml | 2 +- edisgo/data/import_data.py | 6 ++--- edisgo/flex_opt/check_tech_constraints.py | 32 +++++++++-------------- edisgo/grid/grids.py | 4 +-- edisgo/tools/pypsa_io.py | 4 +-- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/doc/eDisGo_UML.graphml b/doc/eDisGo_UML.graphml index 0497f0864..1a066634b 100644 --- a/doc/eDisGo_UML.graphml +++ b/doc/eDisGo_UML.graphml @@ -247,7 +247,7 @@ length: float add_edge() nodes_from_line() nodes_by_attribute() -graph_edges() +lines() diff --git a/edisgo/data/import_data.py b/edisgo/data/import_data.py index 472f84dd0..b358981af 100644 --- a/edisgo/data/import_data.py +++ b/edisgo/data/import_data.py @@ -671,13 +671,13 @@ def _validate_ding0_mv_grid_import(grid, ding0_grid): not _.grid.grid_district.lv_load_area.is_aggregated)]) # Check number of lines outside aggregated LA - # edges_w_la = grid.graph.graph_edges() + # edges_w_la = grid.graph.lines() # data_integrity['line']['edisgo'] = len([_ for _ in edges_w_la # if not (_['adj_nodes'][0] == grid.station or # _['adj_nodes'][1] == grid.station) and # _['line']._length > .5]) # data_integrity['line']['ding0'] = len( - # [_ for _ in ding0_grid.graph_edges() + # [_ for _ in ding0_grid.lines() # if not _['branch'].connects_aggregated]) # raise an error if data does not match @@ -753,7 +753,7 @@ def _validate_ding0_lv_grid_import(grids, ding0_grid, lv_grid_mapping): # Check number of lines outside aggregated LA data_integrity[grid]['line']['edisgo'] = len( - list(grid.graph.graph_edges())) + list(grid.graph.lines())) data_integrity[grid]['line']['ding0'] = len( [_ for _ in lv_grid_mapping[grid].graph_edges() if not _['branch'].connects_aggregated]) diff --git a/edisgo/flex_opt/check_tech_constraints.py b/edisgo/flex_opt/check_tech_constraints.py index 3b2b0610e..31061531b 100644 --- a/edisgo/flex_opt/check_tech_constraints.py +++ b/edisgo/flex_opt/check_tech_constraints.py @@ -30,17 +30,15 @@ def mv_line_load(network): crit_lines = {} - load_factor_mv_line = float(network.config['grid_expansion'][ - 'load_factor_mv_line']) + load_factor_mv_line = network.scenario.parameters.load_factor_mv_line - # ToDo: Add getter for i_res - for line in list(network.mv_grid.graph.graph_edges()): + for line in list(network.mv_grid.graph.lines()): i_line_max = line['line'].type['I_max_th'] * \ load_factor_mv_line * line['line'].quantity try: # check if maximum current from power flow analysis exceeds # allowed maximum current - i_line_pfa = max(network.results._i_res[repr(line['line'])]) + i_line_pfa = max(network.results.i_res[repr(line['line'])]) if i_line_pfa > i_line_max: crit_lines[line['line']] = i_line_pfa / i_line_max except KeyError: @@ -83,18 +81,16 @@ def lv_line_load(network): crit_lines = {} - load_factor_lv_line = float(network.config['grid_expansion'][ - 'load_factor_lv_line']) + load_factor_lv_line = network.scenario.parameters.load_factor_lv_line - # ToDo: Add getter for i_res for lv_grid in network.mv_grid.lv_grids: - for line in list(lv_grid.graph.graph_edges()): + for line in list(lv_grid.graph.lines()): i_line_max = line['line'].type['I_max_th'] * \ load_factor_lv_line * line['line'].quantity try: # check if maximum current from power flow analysis exceeds # allowed maximum current - i_line_pfa = max(network.results._i_res[repr(line['line'])]) + i_line_pfa = max(network.results.i_res[repr(line['line'])]) if i_line_pfa > i_line_max: crit_lines[line['line']] = i_line_pfa / i_line_max except KeyError: @@ -138,14 +134,14 @@ def mv_lv_station_load(network): crit_stations = {} - load_factor_mv_lv_transformer = float(network.config['grid_expansion'][ - 'load_factor_mv_lv_transformer']) + load_factor_mv_lv_transformer = \ + network.scenario.parameters.load_factor_mv_lv_transformer for lv_grid in network.mv_grid.lv_grids: station = lv_grid.station # maximum allowed apparent power of station - s_station_max = sum([_.type.S_nom for _ in station.transformers]) * \ - load_factor_mv_lv_transformer + s_station_max = (sum([_.type.S_nom for _ in station.transformers]) * + load_factor_mv_lv_transformer) try: # check if maximum allowed apparent power of station exceeds # apparent power from power flow analysis @@ -190,8 +186,7 @@ def mv_voltage_deviation(network): crit_nodes = {} # load max. voltage deviation - mv_max_v_deviation = float( - network.config['grid_expansion']['mv_max_v_deviation']) + mv_max_v_deviation = network.scenario.parameters.mv_max_v_deviation v_mag_pu_pfa = network.results.v_res(nodes=network.mv_grid.graph.nodes(), level='mv') @@ -212,7 +207,7 @@ def mv_voltage_deviation(network): len(crit_nodes[network.mv_grid]))) else: crit_nodes = None - logger.debug('==> {} No voltage issues in MV grid.') + logger.debug('==> No voltage issues in MV grid.') return crit_nodes @@ -241,8 +236,7 @@ def lv_voltage_deviation(network): crit_nodes = {} # load max. voltage deviation - lv_max_v_deviation = float( - network.config['grid_expansion']['lv_max_v_deviation']) + lv_max_v_deviation = network.scenario.parameters.lv_max_v_deviation for lv_grid in network.mv_grid.lv_grids: v_mag_pu_pfa = network.results.v_res(nodes=lv_grid.graph.nodes(), diff --git a/edisgo/grid/grids.py b/edisgo/grid/grids.py index a619b4f0e..9856667bf 100644 --- a/edisgo/grid/grids.py +++ b/edisgo/grid/grids.py @@ -228,7 +228,7 @@ def lines_by_attribute(self, attr_val, attr='type'): return lines - def graph_edges(self): + def lines(self): """ Returns a generator for iterating over graph edges The edge of a graph is described by the two adjacent node and the branch @@ -240,7 +240,7 @@ def graph_edges(self): There are generator functions for nodes (`Graph.nodes()`) and edges (`Graph.edges()`) in NetworkX but unlike graph nodes, which can be represented by objects, branch objects can only be accessed by using an - edge attribute ('branch' is used here) + edge attribute ('branch' is ugraph_edgessed here) To make access to attributes of the branch objects simpler and more intuitive for the user, this generator yields a dictionary for each edge diff --git a/edisgo/tools/pypsa_io.py b/edisgo/tools/pypsa_io.py index b1fb2474c..df3c5737b 100644 --- a/edisgo/tools/pypsa_io.py +++ b/edisgo/tools/pypsa_io.py @@ -217,7 +217,7 @@ def mv_to_pypsa(network): generators = network.mv_grid.graph.nodes_by_attribute('generator') loads = network.mv_grid.graph.nodes_by_attribute('load') branch_tees = network.mv_grid.graph.nodes_by_attribute('branch_tee') - lines = network.mv_grid.graph.graph_edges() + lines = network.mv_grid.graph.lines() lv_stations = network.mv_grid.graph.nodes_by_attribute('lv_station') mv_stations = network.mv_grid.graph.nodes_by_attribute('mv_station') @@ -394,7 +394,7 @@ def lv_to_pypsa(network): generators.extend(lv_grid.graph.nodes_by_attribute('generator')) loads.extend(lv_grid.graph.nodes_by_attribute('load')) branch_tees.extend(lv_grid.graph.nodes_by_attribute('branch_tee')) - lines.extend(lv_grid.graph.graph_edges()) + lines.extend(lv_grid.graph.lines()) lv_stations.extend(lv_grid.graph.nodes_by_attribute('lv_station')) omega = 2 * pi * 50