Skip to content

Commit

Permalink
fixed some small bugs in the CGMES converter and improved its speed
Browse files Browse the repository at this point in the history
  • Loading branch information
mrifraunhofer committed Jul 12, 2024
1 parent 65a3591 commit 8c417ac
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Change Log
- [ADDED] PowerFactory converter: support load types (constI, constZ) and the setting whether to consider voltage dependency of loads
- [FIXED] deprecation of matplotlib.cm.get_cmap(name) -> matplotlib.colormaps[name]
- [FIXED] merge_nets failing if net2 has custom DataFrame that is not present in net1
- [FIXED] fixed some small bugs in the CGMES converter and improved its speed

[2.14.7] - 2024-06-14
-------------------------------
Expand Down
7 changes: 2 additions & 5 deletions pandapower/converter/cim/cim2pp/build_pp_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,9 @@ def copy_to_pp(self, pp_type: str, input_df: pd.DataFrame):
level=LogLevel.WARNING, code=ReportCode.WARNING_CONVERTING,
message="Missing pandapower type %s in the pandapower network!" % pp_type))
return
start_index_pp_net = self.net[pp_type].index.size
self.net[pp_type] = pd.concat([self.net[pp_type], pd.DataFrame(None, index=[list(range(input_df.index.size))])],
self.net[pp_type] = pd.concat([self.net[pp_type],
input_df[list(set(self.net[pp_type].columns).intersection(input_df.columns))]],
ignore_index=True, sort=False)
for one_attr in self.net[pp_type].columns:
if one_attr in input_df.columns:
self.net[pp_type][one_attr][start_index_pp_net:] = input_df[one_attr][:]

# noinspection PyShadowingNames
def convert_to_pp(self, convert_line_to_switch: bool = False, line_r_limit: float = 0.1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def _prepare_connectivity_nodes_cim16(self) -> Tuple[pd.DataFrame, pd.DataFrame]
eqssh_terminals = eqssh_terminals.drop_duplicates(subset=['rdfId', 'TopologicalNode'])
eqssh_terminals_temp = eqssh_terminals[['ConnectivityNode', 'TopologicalNode']]
eqssh_terminals_temp = eqssh_terminals_temp.dropna(subset=['TopologicalNode'])
eqssh_terminals_temp = eqssh_terminals_temp.drop_duplicates()
eqssh_terminals_temp = eqssh_terminals_temp.drop_duplicates(subset=['ConnectivityNode'])
connectivity_nodes_size = connectivity_nodes.index.size
if node_breaker:
connectivity_nodes = pd.merge(connectivity_nodes, eqssh_terminals_temp, how='left', left_on='rdfId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def convert_external_network_injections_cim16(self):
eqssh_eni = self._prepare_external_network_injections_cim16()

# choose the slack
eni_ref_prio_min = eqssh_eni.loc[eqssh_eni['enabled'], 'slack_weight'].min()
eni_ref_prio_min = eqssh_eni.loc[(eqssh_eni['enabled']) & (eqssh_eni['slack_weight'] > 0), 'slack_weight'].min()
# check if the slack is a SynchronousMachine
sync_machines = self.cimConverter.merge_eq_ssh_profile('SynchronousMachine')
sync_machines = self.get_voltage_from_controllers(sync_machines)
Expand Down Expand Up @@ -89,6 +89,7 @@ def _prepare_external_network_injections_cim16(self) -> pd.DataFrame:

# convert pu generators with prio = 0 to pq generators (PowerFactory does it same)
eni['referencePriority'].loc[eni['referencePriority'] == 0] = -1
eni['referencePriority'] = eni['referencePriority'].astype(float)
eni['controlEnabled'].loc[eni['referencePriority'] == -1] = False
eni['p'] = -eni['p']
eni['q'] = -eni['q']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def _prepare_synchronous_machines_cim16(self) -> pd.DataFrame:
synchronous_machines = pd.merge(
synchronous_machines, eqssh_reg_control.rename(columns={'rdfId': 'RegulatingControl'}),
how='left', on='RegulatingControl')
synchronous_machines = pd.merge(synchronous_machines, self.cimConverter.bus_merge, how='left',
on='rdfId')
synchronous_machines = pd.merge(synchronous_machines, self.cimConverter.bus_merge, how='left', on='rdfId')
synchronous_machines = synchronous_machines.drop_duplicates(['rdfId'], keep='first')
synchronous_machines['vm_pu'] = synchronous_machines.targetValue / synchronous_machines.vn_kv
synchronous_machines['vm_pu'] = synchronous_machines['vm_pu'].fillna(1.)
Expand Down Expand Up @@ -137,12 +136,12 @@ def _prepare_synchronous_machines_cim16(self) -> pd.DataFrame:
synchronous_machines['rx'] = synchronous_machines['r2'] / synchronous_machines['x2']
synchronous_machines['scaling'] = 1.
synchronous_machines['generator_type'] = 'current_source'
synchronous_machines.loc[synchronous_machines['referencePriority'] == 0, 'referencePriority'] = float('NaN')
synchronous_machines['referencePriority'] = synchronous_machines['referencePriority'].astype(float)
if 'inService' in synchronous_machines.columns:
synchronous_machines['connected'] = (synchronous_machines['connected']
& synchronous_machines['inService'])
synchronous_machines = synchronous_machines.rename(columns={'rdfId_Terminal': sc['t'], 'rdfId': sc['o_id'],
'connected': 'in_service', 'index_bus': 'bus',
'minOperatingP': 'min_p_mw', 'maxOperatingP': 'max_p_mw',
'minQ': 'min_q_mvar', 'maxQ': 'max_q_mvar',
'ratedPowerFactor': 'cos_phi'})
synchronous_machines['connected'] = (synchronous_machines['connected'] & synchronous_machines['inService'])
synchronous_machines = synchronous_machines.rename(columns={
'rdfId_Terminal': sc['t'], 'rdfId': sc['o_id'], 'connected': 'in_service', 'index_bus': 'bus',
'minOperatingP': 'min_p_mw', 'maxOperatingP': 'max_p_mw', 'minQ': 'min_q_mvar', 'maxQ': 'max_q_mvar',
'ratedPowerFactor': 'cos_phi', 'referencePriority': 'slack_weight'})
return synchronous_machines
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import time
from typing import List

import pandas as pd
Expand All @@ -23,6 +24,8 @@ def create_tap_controller_for_power_transformers(self):
if self.cimConverter.power_trafo2w.index.size > 0:
# create transformer tap controller
self._create_tap_controller(self.cimConverter.power_trafo2w, 'trafo')
time_start = time.time()
self.logger.info("Creating the tap dependent impedance characteristic objects for 2w-trafos.")
# create the characteristic objects for transformers
characteristic_df_temp = \
self.cimConverter.net['characteristic_temp'][['id_characteristic', 'step', 'vk_percent', 'vkr_percent']]
Expand All @@ -31,9 +34,13 @@ def create_tap_controller_for_power_transformers(self):
characteristic_df_temp['id_characteristic'] == trafo_row['id_characteristic']]
self._create_characteristic_object(net=self.cimConverter.net, trafo_type='trafo', trafo_id=[trafo_id],
characteristic_df=characteristic_df)
self.logger.info(f"Finished creating tap dependent impedance characteristic objects for 2w-trafos in "
f"{time.time() - time_start}.")
if self.cimConverter.power_trafo3w.index.size > 0:
# create transformer tap controller
self._create_tap_controller(self.cimConverter.power_trafo3w, 'trafo3w')
time_start = time.time()
self.logger.info("Creating the tap dependent impedance characteristic objects for 3w-trafos.")
# create the characteristic objects for transformers
characteristic_df_temp = \
self.cimConverter.net['characteristic_temp'][
Expand All @@ -44,6 +51,8 @@ def create_tap_controller_for_power_transformers(self):
characteristic_df_temp['id_characteristic'] == trafo_row['id_characteristic']]
self._create_characteristic_object(net=self.cimConverter.net, trafo_type='trafo3w', trafo_id=[trafo_id],
characteristic_df=characteristic_df)
self.logger.info(f"Finished creating tap dependent impedance characteristic objects for 3w-trafos in "
f"{time.time() - time_start}.")

def _create_characteristic_object(self, net, trafo_type: str, trafo_id: List, characteristic_df: pd.DataFrame):
self.logger.info("Adding characteristic object for trafo_type: %s and trafo_id: %s" % (trafo_type, trafo_id))
Expand Down

0 comments on commit 8c417ac

Please sign in to comment.