Skip to content

Commit df2f554

Browse files
authored
Merge pull request #197 from Baltic-RCC/mr-fix-dangling-references
Starting from 1.7.0 pypowsybl provides its own references to the inte…
2 parents 014b296 + 228af52 commit df2f554

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

emf/loadflow_tool/model_merger/merge_functions.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,17 +656,21 @@ def check_and_fix_dependencies(cgm_sv_data, cgm_ssh_data, original_data):
656656
(cgm_ssh_data['VALUE'].str.contains('SteadyStateHypothesis'))]
657657
dependencies = pandas.concat([tp_file_ids, ssh_file_ids], ignore_index=True, sort=False)
658658
existing_dependencies = cgm_sv_data[cgm_sv_data['KEY'] == 'Model.DependentOn']
659-
if existing_dependencies.empty or len(existing_dependencies.index) < len(dependencies.index):
660-
logger.info(f"Missing dependencies. Adding {len(dependencies.index)} dependencies to SV profile")
659+
dependency_difference = existing_dependencies.merge(dependencies[['ID']].rename(columns={'ID': 'VALUE'}),
660+
on='VALUE', how='outer', indicator=True)
661+
if not dependency_difference.query('_merge == "right_only"').empty:
662+
cgm_sv_data = triplets.rdf_parser.remove_triplet_from_triplet(cgm_sv_data, existing_dependencies)
661663
full_model_id = cgm_sv_data[(cgm_sv_data['KEY'] == 'Type') & (cgm_sv_data['VALUE'] == 'FullModel')]
662-
new_dependencies = dependencies[['ID']].copy().rename(columns={'ID': 'VALUE'}).reset_index(drop=True)
664+
dependencies_to_update = dependency_difference.query('_merge != "left_only"')
665+
logger.info(f"Mismatch of dependencies. Inserting {len(dependencies_to_update.index)} "
666+
f"dependencies to SV profile")
667+
new_dependencies = dependencies_to_update[['VALUE']].copy().reset_index(drop=True)
663668
new_dependencies.loc[:, 'KEY'] = 'Model.DependentOn'
664669
new_dependencies.loc[:, 'ID'] = full_model_id['ID'].iloc[0]
665670
new_dependencies.loc[:, 'INSTANCE_ID'] = full_model_id['INSTANCE_ID'].iloc[0]
666671
cgm_sv_data = triplets.rdf_parser.update_triplet_from_triplet(cgm_sv_data, new_dependencies)
667672
return cgm_sv_data
668673

669-
670674
def remove_small_islands(solved_data, island_size_limit):
671675
small_island = pandas.DataFrame(solved_data.query("KEY == 'TopologicalIsland.TopologicalNodes'").ID.value_counts()).reset_index().query("count <= @island_size_limit")
672676
solved_data = triplets.rdf_parser.remove_triplet_from_triplet(solved_data, small_island, columns=["ID"])

0 commit comments

Comments
 (0)