Skip to content

Commit

Permalink
Merge pull request #142 from Energinet-AIG/patch-1309
Browse files Browse the repository at this point in the history
Patch 1309
  • Loading branch information
matbkri authored Sep 15, 2024
2 parents a163b56 + c1c9f4c commit 222c4ef
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 214 deletions.
Binary file modified MTB.pfd
Binary file not shown.
34 changes: 17 additions & 17 deletions MTB.pslx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<param name="Warn" value="0" />
<param name="Check" value="0" />
<param name="description" value="" />
<param name="revisor" value="MKT, 1725879966" />
<param name="revisor" value="MKT, 1726239347" />
<param name="Debug" value="0" />
<param name="labels" value="" />
<param name="Preprocessor" value="" />
Expand Down Expand Up @@ -37998,7 +37998,7 @@ if ($type > 0) then
endif]]></segment>
</script>
</Definition>
<Definition classid="UserCmpDefn" name="Fault" build="" crc="120739387" view="false" instances="0" date="1725879195" id="1641883939" w="320" h="400">
<Definition classid="UserCmpDefn" name="Fault" build="" crc="106385396" view="false" instances="0" date="1726239157" id="1641883939" w="320" h="400">
<paramlist>
<param name="Description" value="" />
</paramlist>
Expand Down Expand Up @@ -38043,17 +38043,17 @@ endif]]></segment>
<param name="cond" value="true" />
</paramlist>
</Gfx>
<Gfx classid="Graphics.Text" id="378627266" x="-24" y="-7">
<Gfx classid="Graphics.Text" id="378627266" x="-15" y="-7">
<paramlist>
<param name="text" value="PP-MTB" />
<param name="text" value="MTB" />
<param name="anchor" value="0" />
<param name="full_font" value="Tahoma, 13world" />
<param name="angle" value="0" />
<param name="color" value="Black" />
<param name="cond" value="true" />
</paramlist>
</Gfx>
<Gfx classid="Graphics.Text" id="741102889" x="-15" y="15">
<Gfx classid="Graphics.Text" id="741102889" x="-16" y="12">
<paramlist>
<param name="text" value="Fault" />
<param name="anchor" value="0" />
Expand Down Expand Up @@ -39256,7 +39256,7 @@ It is often necessary to scale or adjust the reference signals and mode selectio
</User>
</schematic>
</Definition>
<Definition classid="UserCmpDefn" name="ThreePhaseCtrl" build="" crc="30817612" view="false" instances="0" date="1725879195" id="1238595495" w="320" h="400">
<Definition classid="UserCmpDefn" name="ThreePhaseCtrl" build="" crc="30817612" view="false" instances="0" date="1726239157" id="1238595495" w="320" h="400">
<paramlist>
<param name="Description" value="" />
</paramlist>
Expand Down Expand Up @@ -40352,7 +40352,7 @@ $out = mtb_return_value
#ENDIF]]></segment>
</script>
</Definition>
<Definition classid="UserCmpDefn" name="MTB" build="" crc="4940412" view="false" instances="0" date="1725879194" id="274789173" w="320" h="400" url="" group="">
<Definition classid="UserCmpDefn" name="MTB" build="" crc="84448470" view="false" instances="0" date="1726239157" id="274789173" w="320" h="400" url="" group="">
<paramlist>
<param name="Description" value="" />
</paramlist>
Expand Down Expand Up @@ -40859,7 +40859,7 @@ $out = mtb_return_value
<vertex x="108" y="0" />
<vertex x="108" y="36" />
</Wire>
<User classid="UserCmp" id="906711646" name="master:source_1" x="738" y="234" w="55" h="80" z="2390" orient="1" defn="master:source_1" link="-1" q="4" disable="false">
<User classid="UserCmp" id="906711646" name="master:source_1" x="738" y="234" w="55" h="80" z="2380" orient="1" defn="master:source_1" link="-1" q="4" disable="false">
<paramlist name="" link="-1" crc="49505675">
<param name="Name" value="Source_1" />
<param name="Type" value="6" />
Expand Down Expand Up @@ -42799,7 +42799,7 @@ $out = mtb_return_value
<param name="yinter" value="true" />
<param name="xinter" value="true" />
<param name="marker" value="false" />
<param name="trigger" value="true" />
<param name="trigger" value="false" />
<param name="invertcolor" value="false" />
<param name="crosshair" value="false" />
<param name="manualscale" value="false" />
Expand Down Expand Up @@ -44240,7 +44240,7 @@ $out = mtb_return_value
<param name="InitStatus" value="0" />
</paramlist>
</User>
<User classid="UserCmp" defn="master:source_3" id="370538517" x="378" y="270" w="54" h="80" z="2380" orient="3" link="-1" layer="" q="4" disable="false">
<User classid="UserCmp" defn="master:source_3" id="370538517" x="378" y="270" w="54" h="80" z="2390" orient="3" link="-1" layer="" q="4" disable="false">
<paramlist link="-1" name="" crc="111699524">
<param name="Name" value="Source 1" />
<param name="Type" value="6" />
Expand Down Expand Up @@ -44718,7 +44718,7 @@ $out = mtb_return_value
<param name="Name" value="mtb_t_vmode" />
</paramlist>
</User>
<User classid="UserCmp" defn="master:unity" id="134538277" x="270" y="2034" w="21" h="44" z="1540" orient="3" link="-1" layer="" q="4" disable="false">
<User classid="UserCmp" defn="master:unity" id="134538277" x="270" y="2034" w="21" h="44" z="1530" orient="3" link="-1" layer="" q="4" disable="false">
<paramlist link="-1" name="" crc="65785874">
<param name="IType" value="2" />
<param name="OType" value="3" />
Expand Down Expand Up @@ -46259,7 +46259,7 @@ $out = mtb_return_value
<vertex x="0" y="0" />
<vertex x="0" y="-18" />
</Wire>
<User classid="UserCmp" id="1628505981" name="MTB:grid_z" x="990" y="1962" w="153" h="158" z="1530" orient="0" defn="MTB:grid_z" link="-1" q="4" disable="false">
<User classid="UserCmp" id="1628505981" name="MTB:grid_z" x="990" y="1962" w="153" h="158" z="1540" orient="0" defn="MTB:grid_z" link="-1" q="4" disable="false">
<paramlist name="" link="-1" crc="49745624">
<param name="Name" value="" />
</paramlist>
Expand Down Expand Up @@ -49583,7 +49583,7 @@ $iqneg = $ineg * Sin(v_neg_p-i_neg_p)]]></segment>
</Gfx>
</graphics>
</Definition>
<Definition classid="UserCmpDefn" name="PLL_seq_src" build="" crc="91398720" view="false" instances="0" date="1725879195" id="146087733" w="320" h="400" url="" group="">
<Definition classid="UserCmpDefn" name="PLL_seq_src" build="" crc="91398720" view="false" instances="0" date="1726239157" id="146087733" w="320" h="400" url="" group="">
<paramlist>
<param name="Description" value="" />
</paramlist>
Expand Down Expand Up @@ -50491,7 +50491,7 @@ $iqneg = $ineg * Sin(v_neg_p-i_neg_p)]]></segment>
</User>
</schematic>
</Definition>
<Definition classid="UserCmpDefn" name="PLL_ADAPTIVE_src" build="" crc="71566166" view="false" instances="0" date="1725879195" id="1299688213" w="320" h="400" url="" group="">
<Definition classid="UserCmpDefn" name="PLL_ADAPTIVE_src" build="" crc="71566166" view="false" instances="0" date="1726239157" id="1299688213" w="320" h="400" url="" group="">
<paramlist>
<param name="Description" value="" />
</paramlist>
Expand Down Expand Up @@ -59795,15 +59795,15 @@ $iqneg = $ineg * Sin(v_neg_p-i_neg_p)]]></segment>
</Resource>
</List>
<hierarchy>
<call link="1619643197" name="MTB:DS" z="-1" view="false" instance="0">
<call link="855062775" name="MTB:Main" z="-1" view="true" instance="0">
<call link="581244505" name="MTB:DS" z="-1" view="false" instance="0">
<call link="855062775" name="MTB:Main" z="-1" view="false" instance="0">
<call link="1029603519" name="MTB:unit_meas" z="-1" view="false" instance="0">
<call link="1517696666" name="MTB:PLL_seq" z="470" view="false" instance="0">
<call link="1742400640" name="MTB:PLL_ADAPTIVE" z="60" view="false" instance="0" />
<call link="1637378826" name="MTB:PLL_ADAPTIVE" z="70" view="false" instance="1" />
</call>
</call>
<call link="2118952145" name="MTB:MTB" z="-1" view="false" instance="0">
<call link="2118952145" name="MTB:MTB" z="-1" view="true" instance="0">
<call link="168397858" name="MTB:ThreePhaseCtrl" z="1820" view="false" instance="0" />
<call link="1075289416" name="MTB:PLL_seq_src" z="1920" view="false" instance="0">
<call link="212921357" name="MTB:PLL_ADAPTIVE_src" z="60" view="false" instance="0" />
Expand Down
126 changes: 42 additions & 84 deletions execute_pf.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def script_GetInt(script : pf.ComPython, name : str) -> Optional[int]:
else:
return None

def connectPF() -> Tuple[pf.Application, pf.IntPrj, pf.ComPython]:
def connectPF() -> Tuple[pf.Application, pf.IntPrj, pf.ComPython, int]:
'''
Connects to the powerfactory application and returns the application, project and this script object.
'''
Expand All @@ -91,6 +91,10 @@ def connectPF() -> Tuple[pf.Application, pf.IntPrj, pf.ComPython]:
app.PrintInfo(f'Powerfactory application connected externally. Executable: {sys.executable}')
app.PrintInfo(f'Imported powerfactory module from {pf.__file__}')

version : str = pf.__version__
pfVersion = 2000 + int(version.split('.')[0])
app.PrintInfo(f'Powerfactory version registred: {pfVersion}')

project : Optional[pf.IntPrj] = app.GetActiveProject() #type: ignore

if DEBUG:
Expand All @@ -106,7 +110,7 @@ def connectPF() -> Tuple[pf.Application, pf.IntPrj, pf.ComPython]:
thisScript : pf.ComPython = networkData.SearchObject('MTB\\MTB\\execute.ComPython') #type: ignore
assert thisScript is not None

return app, project, thisScript
return app, project, thisScript, pfVersion

def resetProjectUnits(project : pf.IntPrj) -> None:
'''
Expand Down Expand Up @@ -150,81 +154,32 @@ def setupResFiles(app : pf.Application, script : pf.ComPython, root : pf.DataObj
elmRes.AddVariable(measurementBlock, 's:ppoc_pu')
elmRes.AddVariable(measurementBlock, 's:qpoc_pu')

mtb_s_pref_pu = root.SearchObject('mtb_s_pref_pu.ElmDsl')
assert mtb_s_pref_pu is not None
elmRes.AddVariable(mtb_s_pref_pu, 's:yo')

mtb_s_qref = root.SearchObject('mtb_s_qref.ElmDsl')
assert mtb_s_qref is not None
elmRes.AddVariable(mtb_s_qref, 's:yo')

mtb_s_qref_q_pu = root.SearchObject('mtb_s_qref_q_pu.ElmDsl')
assert mtb_s_qref_q_pu is not None
elmRes.AddVariable(mtb_s_qref_q_pu, 's:yo')

mtb_s_qref_qu_pu = root.SearchObject('mtb_s_qref_qu_pu.ElmDsl')
assert mtb_s_qref_qu_pu is not None
elmRes.AddVariable(mtb_s_qref_qu_pu, 's:yo')

mtb_s_qref_pf = root.SearchObject('mtb_s_qref_pf.ElmDsl')
assert mtb_s_qref_pf is not None
elmRes.AddVariable(mtb_s_qref_pf, 's:yo')

mtb_s_qref_3 = root.SearchObject('mtb_s_qref_3.ElmDsl')
assert mtb_s_qref_3 is not None
elmRes.AddVariable(mtb_s_qref_3, 's:yo')

mtb_s_qref_4 = root.SearchObject('mtb_s_qref_4.ElmDsl')
assert mtb_s_qref_4 is not None
elmRes.AddVariable(mtb_s_qref_4, 's:yo')

mtb_s_qref_5 = root.SearchObject('mtb_s_qref_5.ElmDsl')
assert mtb_s_qref_5 is not None
elmRes.AddVariable(mtb_s_qref_5, 's:yo')

mtb_s_qref_6 = root.SearchObject('mtb_s_qref_6.ElmDsl')
assert mtb_s_qref_6 is not None
elmRes.AddVariable(mtb_s_qref_6, 's:yo')

mtb_s_1 = root.SearchObject('mtb_s_1.ElmDsl')
assert mtb_s_1 is not None
elmRes.AddVariable(mtb_s_1, 's:yo')

mtb_s_2 = root.SearchObject('mtb_s_2.ElmDsl')
assert mtb_s_2 is not None
elmRes.AddVariable(mtb_s_2, 's:yo')

mtb_s_3 = root.SearchObject('mtb_s_3.ElmDsl')
assert mtb_s_3 is not None
elmRes.AddVariable(mtb_s_3, 's:yo')

mtb_s_4 = root.SearchObject('mtb_s_4.ElmDsl')
assert mtb_s_4 is not None
elmRes.AddVariable(mtb_s_4, 's:yo')

mtb_s_5 = root.SearchObject('mtb_s_5.ElmDsl')
assert mtb_s_5 is not None
elmRes.AddVariable(mtb_s_5, 's:yo')

mtb_s_6 = root.SearchObject('mtb_s_6.ElmDsl')
assert mtb_s_6 is not None
elmRes.AddVariable(mtb_s_6, 's:yo')

mtb_s_7 = root.SearchObject('mtb_s_7.ElmDsl')
assert mtb_s_7 is not None
elmRes.AddVariable(mtb_s_7, 's:yo')

mtb_s_8 = root.SearchObject('mtb_s_8.ElmDsl')
assert mtb_s_8 is not None
elmRes.AddVariable(mtb_s_8, 's:yo')

mtb_s_9 = root.SearchObject('mtb_s_9.ElmDsl')
assert mtb_s_9 is not None
elmRes.AddVariable(mtb_s_9, 's:yo')

mtb_s_10 = root.SearchObject('mtb_s_10.ElmDsl')
assert mtb_s_10 is not None
elmRes.AddVariable(mtb_s_10, 's:yo')
signals = [
'mtb_s_pref_pu.ElmDsl',
'mtb_s_qref.ElmDsl',
'mtb_s_qref_q_pu.ElmDsl',
'mtb_s_qref_qu_pu.ElmDsl',
'mtb_s_qref_pf.ElmDsl',
'mtb_s_qref_3.ElmDsl',
'mtb_s_qref_4.ElmDsl',
'mtb_s_qref_5.ElmDsl',
'mtb_s_qref_6.ElmDsl',
'mtb_s_1.ElmDsl',
'mtb_s_2.ElmDsl',
'mtb_s_3.ElmDsl',
'mtb_s_4.ElmDsl',
'mtb_s_5.ElmDsl',
'mtb_s_6.ElmDsl',
'mtb_s_7.ElmDsl',
'mtb_s_8.ElmDsl',
'mtb_s_9.ElmDsl',
'mtb_s_10.ElmDsl'
]

for signal in signals:
signalObj = root.SearchObject(signal)
assert signalObj is not None
elmRes.AddVariable(signalObj, 's:yo')

# Include measurement objects and set alias
for i in range(1, 100):
Expand Down Expand Up @@ -381,7 +336,7 @@ def convertToConfStr(param : str, signal : str) -> str:

def main():
# Connect to Powerfactory
app, project, thisScript = connectPF()
app, project, thisScript, pfVersion = connectPF()

# Check if any studycase is active
currentStudyCase : Optional[pf.IntCase] = app.GetActiveStudyCase() #type: ignore
Expand Down Expand Up @@ -524,12 +479,15 @@ def main():
if onlySetup == 0:
taskAuto.Execute()

for studycase in studycases:
studycase.Activate()
setupPlots(app, root)
app.WriteChangesToDb()
studycase.Deactivate()
app.WriteChangesToDb()
if pfVersion >= 2024:
for studycase in studycases:
studycase.Activate()
setupPlots(app, root)
app.WriteChangesToDb()
studycase.Deactivate()
app.WriteChangesToDb()
else:
app.PrintWarn('Plot setup not supported for PowerFactory versions older than 2024.')

# Create post run backup
postBackup = script_GetInt(thisScript, 'Post_run_backup')
Expand Down
27 changes: 15 additions & 12 deletions execute_pscad.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def outToCsv(srcPath : str, dstPath : str):
open(dstPath, 'w') as csv:
csv.writelines(','.join(line.split()) +'\n' for line in out)

def moveFiles(srcPath : str, dstPath : str, types : List[str]) -> None:
def moveFiles(srcPath : str, dstPath : str, types : List[str], suffix : str = '') -> None:
'''
Moves files of the specified types from srcPath to dstPath.
'''
for file in os.listdir(srcPath):
_, typ = os.path.splitext(file)
if typ in types:
shutil.move(os.path.join(srcPath, file), os.path.join(dstPath, file))
shutil.move(os.path.join(srcPath, file), os.path.join(dstPath, file + suffix))

def taskIdToRank(csvPath : str, projectName : str, emtCases : List[cs.Case]):
'''
Expand All @@ -94,17 +94,20 @@ def taskIdToRank(csvPath : str, projectName : str, emtCases : List[cs.Case]):
for file in os.listdir(csvPath):
_, fileName = os.path.split(file)
root, typ = os.path.splitext(fileName)
if typ == '.csv' or typ == '.inf':
parts = root.split('_')
if len(parts) > 1 and parts[0] == projectName and parts[1].isnumeric():
taskId = int(parts[1])
if typ == '.csv_taskid' or typ == '.inf_taskid' and root.startswith(projectName + '_'):
suffix = root[len(projectName) + 1:]
parts = suffix.split('_')
if len(parts) > 0 and parts[0].isnumeric():
taskId = int(parts[0])
if taskId - 1 < len(emtCases):
parts[1] = str(emtCases[int(parts[1]) - 1].rank)
newName = '_'.join(parts)
print(f'Renaming {fileName} to {newName + typ}')
os.rename(os.path.join(csvPath, fileName), os.path.join(csvPath, newName + typ))
parts[0] = str(emtCases[taskId - 1].rank)
newName = projectName + '_' + '_'.join(parts) + typ.replace('_taskid', '')
print(f'Renaming {fileName} to {newName}')
os.rename(os.path.join(csvPath, fileName), os.path.join(csvPath, newName))
else:
print(f'WARNING: {fileName} has a task ID that is out of bounds. Ignoring file.')
else:
print(f'WARNING: {fileName} has an invalid task ID. Ignoring file.')

def cleanUpOutFiles(buildPath : str, projectName : str) -> str:
'''
Expand Down Expand Up @@ -136,7 +139,7 @@ def cleanUpOutFiles(buildPath : str, projectName : str) -> str:
#Move .csv and .inf files away from build folder into output folder
csvFolder = os.path.join(outputFolder, resultsFolder)
os.mkdir(csvFolder)
moveFiles(buildPath, csvFolder, ['.csv', '.inf'])
moveFiles(buildPath, csvFolder, ['.csv', '.inf'], '_taskid')

#Move .out file away from build folder
outFolder = os.path.join(buildPath, resultsFolder)
Expand Down Expand Up @@ -245,7 +248,7 @@ def main():
print()
taskIdToRank(csvFolder, plantSettings.Projectname, emtCases)

print('execute.py finished at:', datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
print('execute.py finished at: ', datetime.now().strftime('%m-%d %H:%M:%S'))

if __name__ == '__main__':
main()
Expand Down
11 changes: 6 additions & 5 deletions plotter/config.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[config]
resultsDir = results
columns = 3
genHTML = True
genJPEG = True
genImage = True
imageFormat = png
htmlColumns = 1
imageColumns = 3
threads = 10
pfFlatTime = 0.1
pscadInitTime = 3.5
optionalCasesheet = ../testcases.xlsx

[Simulation data paths]
EMT = C:\EMT
RMS = C:\RMS

EMT = C:\Users\MKT.ENERGINET\Desktop\MTB\MTB_04092024154118
RMS = C:\Users\MKT.ENERGINET\Desktop\MTB\export
Loading

0 comments on commit 222c4ef

Please sign in to comment.