Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mr open nonretained switches connecting tns #181

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 50 additions & 0 deletions emf/loadflow_tool/model_merger/merge_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,56 @@ def remove_small_islands(solved_data, island_size_limit):
return solved_data


def check_switch_terminals(input_data: pandas.DataFrame, column_name: str):
"""
Checks if column of a dataframe contains only one value
:param input_data: input data frame
:param column_name: name of the column to check
return True if different values are in column, false otherwise
"""
data_slice = (input_data.reset_index())[column_name]
return not pandas.Series(data_slice[0] == data_slice).all()


def handle_not_retained_switches_between_nodes(original_data, open_not_retained_switches: bool = False):
"""
For the loadflow open all the non-retained switches that connect different topological nodes
Currently it is seen to help around 9 to 10 Kirchhoff 1st law errors from 2 TSOs
:param original_data: original models in triplets format
:param open_not_retained_switches: if true then found switches are set to open, else it only checks and reports
:return: updated original data
"""
updated_switches = False
original_models = get_opdm_data_from_models(original_data)
not_retained_switches = original_models[(original_models['KEY'] == 'Switch.retained')
& (original_models['VALUE'] == "false")][['ID']]
closed_switches = original_models[(original_models['KEY'] == 'Switch.open')
& (original_models['VALUE'] == 'false')]
not_retained_closed = not_retained_switches.merge(closed_switches[['ID']], on='ID')
terminals = original_models.type_tableview('Terminal').rename_axis('Terminal').reset_index()
terminals = terminals[['Terminal',
# 'ACDCTerminal.connected',
'Terminal.ConductingEquipment',
'Terminal.TopologicalNode']]
not_retained_terminals = (terminals.rename(columns={'Terminal.ConductingEquipment': 'ID'})
.merge(not_retained_closed, on='ID'))
if not_retained_terminals.empty:
return original_data, updated_switches
between_tn = ((not_retained_terminals.groupby('ID')[['Terminal.TopologicalNode']]
.apply(lambda x: check_switch_terminals(x, 'Terminal.TopologicalNode')))
.reset_index(name='same_TN'))
between_tn = between_tn[between_tn['same_TN']]
if not between_tn.empty:
updated_switches = True
logger.warning(f"Found {len(between_tn.index)} not retained switches between topological nodes")
if open_not_retained_switches:
logger.warning(f"Opening not retained switches")
open_switches = closed_switches.merge(between_tn[['ID']], on='ID')
open_switches.loc[:, 'VALUE'] = 'true'
original_data = triplets.rdf_parser.update_triplet_from_triplet(original_data, open_switches)
return original_data, updated_switches


def disconnect_equipment_if_flow_sum_not_zero(cgm_sv_data,
cgm_ssh_data,
original_data,
Expand Down
9 changes: 9 additions & 0 deletions emf/loadflow_tool/model_validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from emf.common.logging import custom_logger
from emf.common.config_parser import parse_app_properties
from emf.common.integrations import elastic
from emf.loadflow_tool.model_merger.merge_functions import handle_not_retained_switches_between_nodes

# Initialize custom logger
# custom_logger.initialize_custom_logger(extra={'worker': 'model-retriever', 'worker_uuid': str(uuid.uuid4())})
Expand All @@ -24,6 +25,8 @@ def validate_model(opdm_objects, loadflow_parameters=getattr(loadflow_settings,
# Load data
start_time = time.time()
model_data = load_model(opdm_objects=opdm_objects)
# Check for switches that are not retained, are closed and connect different TNs
not_retained_switches_present = handle_not_retained_switches_between_nodes(opdm_objects)[1]
network = model_data["network"]

# Run all validations
Expand Down Expand Up @@ -65,6 +68,12 @@ def validate_model(opdm_objects, loadflow_parameters=getattr(loadflow_settings,
# Validation status and duration
# TODO check only main island component 0?
model_valid = any([True if val["status"] == "CONVERGED" else False for key, val in loadflow_result_dict.items()])
# Do something useful with these non retained switches
# Ver 1 call model invalid if they are present
# model_valid = model_valid and (not not_retained_switches_present)
# Ver 2 save it as additional parameter to elastic report
model_data["non_retained_switches_between_tn"] = not_retained_switches_present

model_data["valid"] = model_valid
model_data["validation_duration_s"] = round(time.time() - start_time, 3)
logger.info(f"Load flow validation status: {model_valid} [duration {model_data['validation_duration_s']}s]")
Expand Down
Loading