From: pascale.noyret Date: Wed, 20 Feb 2019 12:50:09 +0000 (+0100) Subject: 1eres modifs X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e8668c7e266ba803fc01a3fc432791b1c69bee4d;p=tools%2Feficas.git 1eres modifs --- diff --git a/PSSE_PF_Eficas/ExtractGeneratorLoadLineandTransfoDico.py b/PSSE_PF_Eficas/ExtractGeneratorLoadLineandTransfoDico.py index 438b08fd..fd406be2 100644 --- a/PSSE_PF_Eficas/ExtractGeneratorLoadLineandTransfoDico.py +++ b/PSSE_PF_Eficas/ExtractGeneratorLoadLineandTransfoDico.py @@ -4,6 +4,7 @@ ############################################################ NoBreakersandSwitches = True +from utils import nettoyeName def ExtractGeneratorLoadLineandTransfoDico(NetworkFile,PSSE_PATH, PSSPY_PATH): @@ -56,21 +57,22 @@ def ExtractGeneratorLoadLineandTransfoDico(NetworkFile,PSSE_PATH, PSSPY_PATH): # except: #id is not an integer # idname = "Lo" + carray[1][i] loadname = carray[0][i].strip()+ "__" + idname - loadname = loadname.replace(" ","_") - loadname = loadname.replace("-","_") - loadname = loadname.replace(".","_") - loadname = loadname.replace("&","and") - loadname = loadname.replace("%","pct") - loadname = loadname.replace("=","eq") - loadname = loadname.replace("#","_") - loadname = loadname.replace("$","_") - loadname = loadname.replace("/","_") - loadname = loadname.replace("\\","_") - try: - int(loadname[0]) - loadname="_" + loadname - except: - pass + loadname=nettoyeName(loadname) + #loadname = loadname.replace(" ","_") + #loadname = loadname.replace("-","_") + #loadname = loadname.replace(".","_") + #loadname = loadname.replace("&","and") + #loadname = loadname.replace("%","pct") + #loadname = loadname.replace("=","eq") + #loadname = loadname.replace("#","_") + #loadname = loadname.replace("$","_") + #loadname = loadname.replace("/","_") + #loadname = loadname.replace("\\","_") + #try: + # int(loadname[0]) + # loadname="_" + loadname + #except: + # pass LoadDico[loadname]= {} LoadDico[loadname]['NAME'] = carray[0][i].strip() LoadDico[loadname]['ID'] = carray[1][i] @@ -100,21 +102,22 @@ def ExtractGeneratorLoadLineandTransfoDico(NetworkFile,PSSE_PATH, PSSPY_PATH): ## except: ## idname = "Gr" + carray[1][i] machinename = carray[0][i].strip()+ "__" + idname - machinename = machinename.replace(" ","_") - machinename = machinename.replace("-","_") - machinename = machinename.replace(".","_") - machinename = machinename.replace("&","and") - machinename = machinename.replace("%","pct") - machinename = machinename.replace("=","eq") - machinename = machinename.replace("#","_") - machinename = machinename.replace("$","_") - machinename = machinename.replace("/","_") - machinename = machinename.replace("\\","_") - try: - int(machinename[0]) - machinename="_" + machinename - except: - pass + machinename=nettoyeName(machinename) + #machinename = machinename.replace(" ","_") + #machinename = machinename.replace("-","_") + #machinename = machinename.replace(".","_") + #machinename = machinename.replace("&","and") + #machinename = machinename.replace("%","pct") + #machinename = machinename.replace("=","eq") + #machinename = machinename.replace("#","_") + #machinename = machinename.replace("$","_") + #machinename = machinename.replace("/","_") + #machinename = machinename.replace("\\","_") + #try: + # int(machinename[0]) + # machinename="_" + machinename + #except: + # pass MachineDico[machinename]={} MachineDico[machinename]['NAME'] = carray[0][i].strip() MachineDico[machinename]['ID'] = carray[1][i] diff --git a/PSSE_PF_Eficas/utils.py b/PSSE_PF_Eficas/utils.py new file mode 100644 index 00000000..ff8b31a8 --- /dev/null +++ b/PSSE_PF_Eficas/utils.py @@ -0,0 +1,369 @@ + +############################################################ +# objectif de ce module: fonctions utilisees pour les chaines +############################################################ +debug = True + +dicoCaracteresSpeciaux = { + " ":"_", + "-" : "_" , + "." : "_" , + "&" : "and" , + "%" : "pct" , + "=" : "eq" , + "#" : "_" , + "$" : "_" , + "/" : "_" , + "\\" : "_" , + } +def nettoyeName (name) : +# --------------------- +# remplace les caracteres speciaux definis dans dicoCaracteresSpeciaux +# de la chaine name passe en argument et retourne une chaine nettoyee +# prefixe la chaine d un _ si la chaine commence par un chiffre + + nouveauNom = name + for c in dicoCaracteresSpeciaux.keys(): + nouveauNom = nouveauNom.replace(c,dicoCaracteresSpeciaux[c]) + if nouveauNom[0] in ( '0','1','2','3','4','5','6','7','8','9') : nouveauNom = '_'+nouveauNom + return nouveauNom + + +def testNettoyeName(): + nom1 = 'a b-c' + if nettoyeName(nom1) != 'a_b_c': + print ('Echec de testNettoyeName sur remplacement du blanc') + exit() + nom2 = '2a' + if nettoyeName(nom2) != '_2a': + print ('Echec de testNettoyeName sur prefixe par _ ') + exit() + print ('succes testNettoyeName') + +if __name__ == "__main__": + testNettoyeName() + + +# try: +# int(loadname[0]) +# loadname="_" + loadname +# except: +# pass +# LoadDico[loadname]= {} +# LoadDico[loadname]['NAME'] = carray[0][i].strip() +# LoadDico[loadname]['ID'] = carray[1][i] +# LoadDico[loadname]['EXNAME'] =carray[2][i] +# LoadDico[loadname]['NUMBER']=iarray[0][i] +# LoadDico[loadname]['P']=np.real(xdata)[0][i] +# LoadDico[loadname]['Q']=np.imag(xdata)[0][i] +# +# #Extract Generators +# sid = -1 #all buses +# flag = 1 #all in service loads/generators (4 all loads/generators) +# +# string = ['NUMBER'] +# ierr,iarray = psspy.amachint(sid,flag,string) +# +# string = ['NAME','ID','EXNAME'] +# ierr,carray = psspy.amachchar(sid,flag,string) +# +# rstrings = ['pgen','qgen','mbase','pmax','qmax','pmin','qmin'] +# ierr, rarray = psspy.amachreal(sid, flag, rstrings) +# +# MachineDico = {} # [Bus name, machine ID, extended bus name, bus number] +# for i in range(len(iarray[0])): +# idname = "Gr" + carray[1][i].strip() +### try: +### idname = "Gr" + str(int(carray[1][i])) +### except: +### idname = "Gr" + carray[1][i] +# machinename = carray[0][i].strip()+ "__" + idname +# machinename = machinename.replace(" ","_") +# machinename = machinename.replace("-","_") +# machinename = machinename.replace(".","_") +# machinename = machinename.replace("&","and") +# machinename = machinename.replace("%","pct") +# machinename = machinename.replace("=","eq") +# machinename = machinename.replace("#","_") +# machinename = machinename.replace("$","_") +# machinename = machinename.replace("/","_") +# machinename = machinename.replace("\\","_") +# try: +# int(machinename[0]) +# machinename="_" + machinename +# except: +# pass +# MachineDico[machinename]={} +# MachineDico[machinename]['NAME'] = carray[0][i].strip() +# MachineDico[machinename]['ID'] = carray[1][i] +# MachineDico[machinename]['EXNAME'] =carray[2][i] +# MachineDico[machinename]['NUMBER']=iarray[0][i] +# MachineDico[machinename]['P']=rarray[0][i] +# MachineDico[machinename]['Q']=rarray[1][i] +# MachineDico[machinename]['PMAX']=rarray[3][i] +# MachineDico[machinename]['QMAX']=rarray[4][i] +# MachineDico[machinename]['PMIN']=rarray[5][i] +# MachineDico[machinename]['QMIN']=rarray[6][i] +# +# #Extract Motors +# sid = -1 #all buses +# flag = 1 #all in service loads/generators (4 all loads/generators) +# +# string = ['NUMBER','PSETCODE','BASECODE'] +# ierr,iarray = psspy.aindmacint(sid,flag,string) +# +# string = ['NAME','ID','EXNAME'] +# ierr,carray = psspy.aindmacchar(sid,flag,string) +# +# rstrings = ['psetpoint','mbase','p','q'] +# ierr, rarray = psspy.aindmacreal(sid, flag, rstrings) +# +# +# MotorDico = {} # [Bus name, machine ID, extended bus name, bus number] +# for i in range(len(iarray[0])): +# idname = "Mo" + carray[1][i].strip() +### try: +### idname = "Gr" + str(int(carray[1][i])) +### except: +### idname = "Gr" + carray[1][i] +# motorname = carray[0][i].strip()+ "__" + idname +# motorname = motorname.replace(" ","_") +# motorname = motorname.replace("-","_") +# motorname = motorname.replace(".","_") +# motorname = motorname.replace("&","and") +# motorname = motorname.replace("%","pct") +# motorname = motorname.replace("=","eq") +# motorname = motorname.replace("#","_") +# motorname = motorname.replace("$","_") +# motorname = motorname.replace("/","_") +# motorname = motorname.replace("\\","_") +# +# try: +# int(motorname[0]) +# motorname="_" + motorname +# except: +# pass +# MotorDico[motorname]={} +# MotorDico[motorname]['NAME'] = carray[0][i].strip() +# MotorDico[motorname]['ID'] = carray[1][i] +# MotorDico[motorname]['EXNAME'] =carray[2][i] +# MotorDico[motorname]['NUMBER']=iarray[0][i] +# MotorDico[motorname]['PSETCODE']=iarray[1][i] +# MotorDico[motorname]['BASECODE']=iarray[2][i] +# MotorDico[motorname]['PSETPOINT']=rarray[0][i] +# MotorDico[motorname]['MBASE']=rarray[1][i] +# MotorDico[motorname]['P']=rarray[2][i] +# MotorDico[motorname]['Q']=rarray[3][i] +# +# +# #Extract Lignes +# sid = -1 +# owner = 1 +# ties = 1 +# flag = 2 #6 for two-winding transfos +# entry = 1 #each branch once, not both directions +# string = ['FROMNUMBER','TONUMBER'] +# ierr,iarray = psspy.abrnint(sid,owner,ties,flag,entry,string) +# string = ['FROMNAME','TONAME','FROMEXNAME','TOEXNAME','ID'] +# ierr,carray = psspy.abrnchar(sid,owner,ties,flag,entry,string) +# +# LineDico = {} #[linename, Bus name 1, Bus name 2, ID, extended bus name 1, extended bus name 2, bus number 1, bus number 2] +# for i in range(len(iarray[0])): +# idname = carray[4][i].strip() +# #idname = carray[4][i] +# if '@' in idname: +# idname = idname.replace('@','Br') +# elif '*' in idname: +# idname = idname.replace('*','Sw') +# else: +# try: +# idname = 'Li' + str(int(idname)) +# except: +# idname = 'Li' + idname +# linename =carray[0][i].strip() + "__" + carray[1][i].strip() + "__" + idname +# linename = linename.replace(" ","_") +# linename = linename.replace("-","_") +# linename = linename.replace(".","_") +# linename = linename.replace("&","and") +# linename = linename.replace("%","pct") +# linename = linename.replace("=","eq") +# linename = linename.replace("#","_") +# linename = linename.replace("$","_") +# linename = linename.replace("/","_") +# linename = linename.replace("\\","_") +# try: +# int(linename[0]) +# linename="_" + linename +# except: +# pass +# if NoBreakersandSwitches: +# if 'Br' not in idname and 'Sw' not in idname: +# LineDico[linename]={} +# LineDico[linename]['FROMNAME']=carray[0][i].strip() +# LineDico[linename]['TONAME']=carray[1][i].strip() +# LineDico[linename]['ID']=carray[4][i] +# LineDico[linename]['FROMEXNAME']=carray[2][i] +# LineDico[linename]['TOEXNAME']=carray[3][i] +# LineDico[linename]['FROMNUMBER']=iarray[0][i] +# LineDico[linename]['TONUMBER']=iarray[1][i] +# +# +# print "Read lines" +# +# #Extract Transfos +# sid = -1 +# owner = 1 +# ties = 1 +# flag = 6 #two-winding transfos +# entry = 1 #each branch once, not both directions +# string = ['FROMNUMBER','TONUMBER'] +# ierr,iarray = psspy.abrnint(sid,owner,ties,flag,entry,string) +# string = ['FROMNAME','TONAME','FROMEXNAME','TOEXNAME','ID'] +# ierr,carray = psspy.abrnchar(sid,owner,ties,flag,entry,string) +# +# TfoDico = {} #[linename, Bus name 1, Bus name 2, machine ID, extended bus name 1, extended bus name 2, bus number 1, bus number 2] +# for i in range(len(iarray[0])): +# idname = 'Tr' + carray[4][i].strip() +### try: +### idname = 'Tr' + str(int(carray[4][i])) +### except: +### idname = 'Tr' + carray[4][i] +# tfoname = carray[0][i].strip() + "__" + carray[1][i].strip() + "__" + idname +# tfoname = tfoname.replace(" ","_") +# tfoname = tfoname.replace("-","_") +# tfoname = tfoname.replace(".","_") +# tfoname = tfoname.replace("&","and") +# tfoname = tfoname.replace("%","pct") +# tfoname = tfoname.replace("=","eq") +# tfoname = tfoname.replace("#","_") +# tfoname = tfoname.replace("$","_") +# tfoname = tfoname.replace("/","_") +# tfoname = tfoname.replace("\\","_") +# try: +# int(tfoname[0]) +# tfoname="_" + tfoname +# except: +# pass +# TfoDico[tfoname]={} +# TfoDico[tfoname]['FROMNAME']=carray[0][i].strip() +# TfoDico[tfoname]['TONAME']=carray[1][i].strip() +# TfoDico[tfoname]['ID']=carray[4][i] +# TfoDico[tfoname]['FROMEXNAME']=carray[2][i] +# TfoDico[tfoname]['TOEXNAME']=carray[3][i] +# TfoDico[tfoname]['FROMNUMBER']=iarray[0][i] +# TfoDico[tfoname]['TONUMBER']=iarray[1][i] +# TfoDico[tfoname]['#WIND']=2 +# print "Read Transfos" +# +# #Extract 3 winding Transfos +# sid = -1 #assume a subsystem containing all buses in working case +# owner_3flow = 1 #1 = use bus ownership 2 = use tfo ownership +# ties_3flow = 3 #ignored bc sid is negative. 3 = interior subsystem and subsystem tie 3 winding transformers +# flag=3 #all 3 winding transfo windings +# string = ['wind1number','wind2number','wind3number'] +# ierr,iarray = psspy.awndint(sid,owner,ties,flag,entry,string) +# string = ['wind1name','wind2name','wind3name','wind1exname','wind2exname','wind3exname','id'] +# ierr,carray = psspy.awndchar(sid,owner,ties,flag,entry,string) +# +# #[Bus name 1, Bus name 2, Bus name 3, machine ID, extended bus name 1, extended bus name 2, extended bus name 3, bus number 1, bus number 2, bus number 3] +# for i in range(len(iarray[0])): +# idname = 'Tr' + carray[6][i].strip() +### try: +### idname = 'Tr' + str(int(carray[4][i])) +### except: +### idname = 'Tr' + carray[4][i] +# tfoname = carray[0][i].strip() + "__" + carray[1][i].strip() + "__" + carray[2][i].strip() + "__" + idname +# tfoname = tfoname.replace(" ","_") +# tfoname = tfoname.replace("-","_") +# tfoname = tfoname.replace(".","_") +# tfoname = tfoname.replace("&","and") +# tfoname = tfoname.replace("%","pct") +# tfoname = tfoname.replace("=","eq") +# tfoname = tfoname.replace("#","_") +# tfoname = tfoname.replace("$","_") +# tfoname = tfoname.replace("/","_") +# tfoname = tfoname.replace("\\","_") +# try: +# int(tfoname[0]) +# tfoname="_" + tfoname +# except: +# pass +# TfoDico[tfoname]={} +# TfoDico[tfoname]['FROMNAME']=carray[0][i].strip() +# TfoDico[tfoname]['TONAME']=carray[1][i].strip() +# TfoDico[tfoname]['3NAME']=carray[2][i].strip() +# TfoDico[tfoname]['ID']=carray[6][i] +# TfoDico[tfoname]['FROMEXNAME']=carray[3][i] +# TfoDico[tfoname]['TOEXNAME']=carray[4][i] +# TfoDico[tfoname]['3EXNAME']=carray[5][i] +# TfoDico[tfoname]['FROMNUMBER']=iarray[0][i] +# TfoDico[tfoname]['TONUMBER']=iarray[1][i] +# TfoDico[tfoname]['3NUMBER']=iarray[2][i] +# TfoDico[tfoname]['#WIND']=3 +# print "Read 3-Winding Transfos" +# # path1 = os.getcwd() +# # import json +# # path_temp=os.path.dirname(NetworkFile) +# # # filew = open(path_temp+'/temp.txt', 'w') +# # json.dump(MachineDico, open("toto.txt", 'w')) +# # # filew.write(MachineDico) +# # # filew.close() +# filew = open('temp.txt', 'w') +# filew.write(NetworkFile + '\n') +# filew.write(PSSE_PATH + '\n') +# filew.close() +# +# return MachineDico, LoadDico, LineDico, TfoDico, MotorDico +# +# +#def PFExtractGeneratorLoadLineandTransfoDico(NetworkFile, PF_PATH,Python3_path): +# # PSEN sous PowerFactory Lecture les donnees de Generateur,Load,Line,Transfo +# import os,pickle +# import sys, subprocess +# import numpy as np +# path1=os.getcwd() +# # path_temp=os.path.dirname(NetworkFile) +# filew=open('temp.txt','w') +# filew.write(NetworkFile+'\n') +# filew.write(PF_PATH + '\n') +# filew.write(Python3_path + '\n') +# filew.close() +# print('changer le chemin de Python3 executable') +# lancer = [Python3_path+'/python.exe', path1+'/com.py']# changer le chemin de Python3 executable +# proc = subprocess.Popen(lancer) +# proc.wait() +# with open('Data_for_interface', 'rb') as fichier: +# mon_depickler = pickle.Unpickler(fichier) +# data_file = mon_depickler.load() +# +# import collections +# def convert(data): +# if isinstance(data, basestring): +# return str(data) +# elif isinstance(data, collections.Mapping): +# return dict(map(convert, data.iteritems())) +# elif isinstance(data, collections.Iterable): +# return type(data)(map(convert, data)) +# else: +# return data +# data=convert(data_file) +# MachineDico=data['MachineDico'] +# LoadDico = data['LoadDico'] +# LineDico = data['LineDico'] +# TfoDico = data['TransfoDico'] +# MotorDico = data['MotorDico'] +# os.remove('Data_for_interface') +# +# +# return MachineDico, LoadDico, LineDico, TfoDico, MotorDico +# +# +##NetworkFile=r"C:\Users\j15773\Documents\Projects\DEWA\Task 4\FEWA_GCCIA_SUMMAX2018_OPF_EQ2.sav" +# +##PSSE_PATH=r"C:\Program Files (x86)\PTI\PSSE34\PSSBIN" +##PSSPY_PATH=r"C:\Program Files (x86)\PTI\PSSE34\PSSPY27" +# +##PSSE_PATH=r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN" +##PSSPY_PATH=r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN" +# +##MachineDico, LoadDico, LineDico, TfoDico, MotorDico = ExtractGeneratorLoadLineandTransfoDico(NetworkFile,PSSE_PATH,PSSPY_PATH)