Salome HOME
sauve du 10/06
[tools/eficas.git] / PSEN_Eficas / PSEN / PSEN_GUI.py
1 # -*- coding: cp1252 -*-\r
2 # ======================== PSEN graphic interface ========================\r
3 # This Python script creates a graphical interface to parameter and launch PSEN\r
4 \r
5 # ============== Import useful modules =================\r
6 from Tkinter import *\r
7 from ttk import Combobox\r
8 import tkFileDialog, os\r
9 import subprocess\r
10 from time import sleep\r
11 import numpy as np\r
12 \r
13 # ============== Initialize some variables  =================\r
14 config=[]\r
15 for i in range (60) : # config[] will be used as a list of preferences for PSEN study\r
16     config.append('')\r
17 \r
18 root = Tk() # Creates the main window\r
19 root.wm_withdraw() # The main window is withdrawn/hidden\r
20 \r
21 CIST=PhotoImage(file="lib\CISTlogo.gif") # Load images\r
22 header=PhotoImage(file="lib\header.gif")\r
23 WTcurve=PhotoImage(file="lib\WTcurve.gif")\r
24 \r
25 # ============== Define functions  =================\r
26 \r
27 # browse_PSSe function is used to get the .SAV file path from the user.\r
28 # tkFileDialog.askopenfilename offers a browsing interface to the user\r
29 def browse_PSSe() :\r
30     global savAdress\r
31     savAdress = tkFileDialog.askopenfilename(parent=fenPref,title='Open PSSe SAV file',filetypes=[('SAV files', '.sav')])\r
32     savAdressD.set(savAdress)\r
33     fenPref.update_idletasks() # this updates the values in the fenPref window (defined in preferences())\r
34     print 'Added: '+str(savAdress)\r
35     return savAdress\r
36 \r
37 # browse_ENR function is used to get a .CSV file path from the user\r
38 # The CSV file contains a list of machines and their type (PV, Wind, Interconnexion)\r
39 # tkFileDialog.askopenfilename offers a browsing interface to the user\r
40 def browse_ENR() :\r
41     global ENRpath\r
42     ENRpath = tkFileDialog.askopenfilename(parent=fenPref,title='Open ENR configuration',filetypes=[('CSV files', '.csv'),('All files', '.*')])\r
43     ENRpathD.set(ENRpath)\r
44     fenPref.update_idletasks() # this updates the values in the fenPref window (defined in preferences())\r
45     print 'Added: '+str(ENRpath)\r
46     return ENRpath    \r
47 \r
48 # browse_folder function is used to get a folder path from the user\r
49 # This folder is used to save all study files (.sav, .csv, ...)\r
50 # tkFileDialog.askdirectory offers a browsing interface to the user    \r
51 def browse_folder() :\r
52     global folderPATH\r
53     folderPATH = tkFileDialog.askdirectory(parent=fenPref,title='Choose working folder')\r
54     folderPATHD.set(folderPATH)\r
55     fenPref.update_idletasks()  # this updates the values in the fenPref window (defined in preferences())\r
56     print 'Added: '+str(folderPATH)\r
57     return folderPATH\r
58 \r
59 # savePref function is used to save preferences input in fenPref window (defined in preferences())\r
60 def savePref() :\r
61     global Vcin, Vrate, Vcout, Rho, lossrate # These variables are global because they are used in savePSEN()\r
62     try : # Test if the user has defined all the requested variables\r
63         savAdress\r
64         folderPATH\r
65         ENRpath\r
66         VcinD\r
67         VrateD\r
68         VcoutD\r
69         RhoD\r
70         lossrateD\r
71     except NameError : # If not a new window pops up and explains the data is missing\r
72         fenetre2 = Tk()\r
73         champ_label = Label(fenetre2, text="ERROR\nNo file and/or folder selected", fg="red", font=("Century Gothic",16))\r
74         champ_label.pack(side=TOP, fill=BOTH, expand=YES)\r
75     else : # If it's OK it gets the data from the fields and save it into config[]\r
76         config[9]=VcinD.get(); config[10]=VrateD.get(); config[11]=VcoutD.get(); config[12]=RhoD.get(); config[13]=lossrateD.get(); config[2]=ENRpathD.get(); config[1]=folderPATHD.get(); config[0]=savAdressD.get()\r
77         Vcin=VcinD.get()\r
78         Vrate=VrateD.get()\r
79         Vcout=VcoutD.get()\r
80         Rho=RhoD.get()\r
81         lossrate=lossrateD.get()\r
82         f=open("lib\pref.psen", "w") # Creates a config file with values to give to PSSEWrapper.py\r
83         f.write(str(savAdress)+";"+str(folderPATH)+";"+str(ENRpath)+";"+str(Vcin)+";"+str(Vrate)+";"+str(Vcout)+";"+str(Rho)+";"+str(lossrate)+";0\n")\r
84         f.close()\r
85     try : \r
86         fenPref\r
87     except NameError :\r
88         pass\r
89     else :\r
90         fenPref.destroy()\r
91         print 'Preferences saved'\r
92    \r
93 # refresh_pref function is used to refresh fields value in fenPref window (defined in preferences())\r
94 def refresh_pref () :\r
95         try :\r
96             saved\r
97         except NameError : # if saved hasn't been created yet there is no data to update\r
98             pass\r
99             print 'No configuration yet'\r
100         else : # if it has been created we set fields variables and update the window with update_idletasks()\r
101             print 'Update values'\r
102             global continpath\r
103             global model_Path\r
104             global PSSEfolder\r
105             VcinD.set(config[9])\r
106             VrateD.set(config[10])\r
107             VcoutD.set(config[11])\r
108             RhoD.set(config[12])\r
109             lossrateD.set(config[13])\r
110             ENRpathD.set(ENRpath)\r
111             folderPATHD.set(folderPATH)\r
112             savAdressD.set(savAdress)\r
113             fenPref.update_idletasks() \r
114 \r
115 # savePSEN function is used to create a .PSEN file containing all users parameters and preferences        \r
116 def savePSEN() :\r
117     global savePATH\r
118     global saved\r
119     saved=1\r
120 \r
121     # === We get all the fields data ===    \r
122     \r
123     MCS_num=var_MCS.get()\r
124     N_1_opt=N_1.get()\r
125     PV_opt=PV.get()\r
126     Wind1_opt=Wind1.get()\r
127     Wind2_opt=Wind1.get()\r
128     Load_opt=Load.get()\r
129 \r
130     load_type=choix_load.get()\r
131     load1=var_loadn1.get()\r
132     load2=var_loadn2.get()\r
133     load3=var_loadn3.get()\r
134     load4=var_loadn4.get()\r
135     loadPath=loadPathD.get()\r
136 \r
137     wind11_type=choix_wind11.get()\r
138     wind11=var_windn11.get()\r
139     wind12=var_windn12.get()\r
140     wind13=var_windn13.get()\r
141     wind14=var_windn14.get()\r
142     wind1Path=wind1PathD.get()\r
143     \r
144     wind21_type=choix_wind21.get()\r
145     wind21=var_windn21.get()\r
146     wind22=var_windn22.get()\r
147     wind23=var_windn23.get()\r
148     wind24=var_windn24.get()\r
149     wind2Path=wind2PathD.get()\r
150     \r
151     pv_type=choix_pv.get()\r
152     pv1=var_pvn1.get()\r
153     pv2=var_pvn2.get()\r
154     pv3=var_pvn3.get()\r
155     pv4=var_pvn4.get()\r
156     pvPath=pvPathD.get()\r
157     \r
158     C01=C01D.get()\r
159     C02=C02D.get()\r
160     C03=C03D.get()\r
161     C04=C04D.get()\r
162     C12=C12D.get()\r
163     C14=C14D.get()\r
164     C13=C13D.get()\r
165     C23=C23D.get()\r
166     C24=C24D.get()\r
167     C34=C34D.get()\r
168     \r
169     fuel_cost_opt = fuel_cost.get()\r
170     bus_shunt_opt = bus_shunt.get()\r
171     bus_loads_opt = bus_loads.get()\r
172     \r
173     rate_choice = rate_choiceD.get()\r
174     \r
175     try :\r
176         contin_lines_Path\r
177         contin_groups_Path\r
178     except NameError : # If the user hasn't choose a path for the contingency CSV file, we create it as blank to save the data\r
179         contin_lines_Path=''\r
180         contin_groups_Path=''\r
181     \r
182     # We ask the user the name and path of the file\r
183     savePATH = tkFileDialog.asksaveasfilename(parent=fenetre,title='Save the file as ...',defaultextension='.psen',filetypes=[('PSEN file', '.psen')])\r
184     try :\r
185         len(savePATH)>0\r
186     except NameError :\r
187         pass\r
188     else : # Writing all the variables in a specific order (could be improved with XML file for instance)\r
189         f=open(savePATH,'w')\r
190         f.write(str(savAdress)+";"+str(folderPATH)+";"+str(ENRpath)+";"\r
191             +str(contin_lines_Path)+";"+str(contin_groups_Path)+";"+str(model_Path)+";"+str(PSSEfolder)+";"+str(orange_Path)+";"+str(python_Path)+";"\r
192             +str(Vcin)+";"+str(Vrate)+";"+str(Vcout)+";"+str(Rho)+";"+str(lossrate)+";"\r
193             +str(MCS_num)+";"+str(N_1_opt)+";"+str(PV_opt)+";"+str(Wind1_opt)+";"+str(Wind2_opt)+";"+str(Load_opt)+";"\r
194             +str(load_type)+";"+str(load1)+";"+str(load2)+";"+str(load3)+";"+str(load4)+";"+str(loadPath)+";"\r
195             +str(wind11_type)+";"+str(wind11)+";"+str(wind12)+";"+str(wind13)+";"+str(wind14)+";"+str(wind1Path)+";"\r
196             +str(wind21_type)+";"+str(wind21)+";"+str(wind22)+";"+str(wind23)+";"+str(wind24)+";"+str(wind2Path)+";"\r
197             +str(pv_type)+";"+str(pv1)+";"+str(pv2)+";"+str(pv3)+";"+str(pv4)+";"+str(pvPath)+";"\r
198             +str(C01)+";"+str(C02)+";"+str(C03)+";"+str(C04)+";"+str(C12)+";"+str(C13)+";"+str(C14)+";"+str(C23)+";"+str(C24)+";"+str(C34)+";"\r
199             +str(fuel_cost_opt)+";"+str(bus_shunt_opt)+";"+str(bus_loads_opt)+";"\r
200             +str(rate_choice)+";0\n")\r
201         f.close()\r
202         print 'Successfuly saved case study'\r
203 \r
204 # preferences function is a new window to update some PSEN parameters\r
205 def preferences () :   \r
206     global fenPref\r
207     global savAdressD\r
208     global folderPATHD\r
209     global ENRpathD\r
210     global VcinD\r
211     global VrateD\r
212     global VcoutD\r
213     global RhoD\r
214     global lossrateD\r
215     global config        \r
216         \r
217     fenPref = Toplevel(root) # Creating a new window\r
218     fenPref.wm_iconbitmap('lib\PSEN.ico') # Window icon\r
219     fenPref.wm_title('PSEN - Probabilistic Studies of Electrical Networks') # Window title\r
220     \r
221     f0p=Frame(fenPref, height=70, width=500, bd=2, relief=RIDGE)\r
222     f0p.pack_propagate(0) # don't shrink\r
223     f0p.pack()\r
224     \r
225     Label(f0p, text="PSSe .SAV file", fg="black", justify=LEFT, font=("Century Gothic",12)).pack(anchor=NW, padx=10, expand=YES)\r
226     savAdressD=StringVar()\r
227     Entry(f0p, textvariable=savAdressD, width=50).pack(side=LEFT, padx=15, expand=YES)\r
228     Button(f0p, text="Load SAV file", command=browse_PSSe, height=15, width=30).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
229     \r
230     fline=Frame(fenPref, height=2, width=500, bg="grey")\r
231     fline.pack_propagate(0) # don't shrink\r
232     fline.pack(expand=1)\r
233     \r
234     f1p=Frame(fenPref, height=70, width=500, bd=2, relief=RIDGE)\r
235     f1p.pack_propagate(0) # don't shrink\r
236     f1p.pack()    \r
237     \r
238     Label(f1p, text="Working folder adress :", fg="black", justify=LEFT, font=("Century Gothic",12)).pack(anchor=NW, padx=10, expand=YES)\r
239     folderPATHD=StringVar()\r
240     Entry(f1p, textvariable=folderPATHD, width=50).pack(side=LEFT, padx=15, expand=YES)\r
241     Button(f1p, text="Browse to working folder", command=browse_folder, height=15, width=30).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
242     \r
243     fline=Frame(fenPref, height=5, width=500, bg="grey")\r
244     fline.pack_propagate(0) # don't shrink\r
245     fline.pack(expand=1)\r
246     \r
247     f3p=Frame(fenPref, height=100, width=500, bd=2, relief=RIDGE)\r
248     f3p.pack_propagate(0) # don't shrink\r
249     f3p.pack()    \r
250     \r
251     Label(f3p, text="Machines configuration :", fg="black", justify=LEFT, font=("Century Gothic",12)).pack(anchor=NW, padx=10, expand=YES)\r
252     Label(f3p, text="N.B. Use the PSSe machine tab, insert a new column in first and write PV for PV, W1 for wind 1, W2 for wind 2 or do nothing for non-ENR. Save as CSV", fg="black", justify=LEFT, wraplength=450).pack(anchor=NW, padx=10, expand=YES)\r
253     ENRpathD=StringVar()\r
254     Entry(f3p, textvariable=ENRpathD, width=50).pack(side=LEFT, padx=15, expand=YES)\r
255     Button(f3p, text="Browse to ENR CSV file", command=browse_ENR, height=15, width=30).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
256     \r
257     fline=Frame(fenPref, height=5, width=500, bg="grey")\r
258     fline.pack_propagate(0) # don't shrink\r
259     fline.pack(expand=1)\r
260     \r
261     f4p=Frame(fenPref, height=120, width=500, bd=2, relief=RIDGE)\r
262     f4p.pack_propagate(0) # don't shrink\r
263     f4p.pack()    \r
264     \r
265     # Creates 5 entry for wind turbines characteristics    \r
266     Label(f4p, text="Wind 1 & 2 characteristics :", fg="black", justify=LEFT, font=("Century Gothic",12)).pack(anchor=NW, padx=10, expand=YES)\r
267     Label(f4p, text="If wind law, enter the following parameters : \nVcin, Vrate, Vcout, rho (air density kg.m-3, base is 1.225), lossrate (base is 0.05)\nIf power law: Vcin=0, Vrate=1, Vcout>=1. Law must take values between 0 and 1.", fg="black", justify=LEFT, wraplength=450).pack(anchor=NW, padx=10, expand=YES)\r
268     VcinD = StringVar()\r
269     Entry(f4p, textvariable=VcinD, width=13).pack(side=LEFT, padx=5, pady=5) \r
270     VrateD = StringVar()\r
271     Entry(f4p, textvariable=VrateD, width=13).pack(side=LEFT, padx=5, pady=5)\r
272     VcoutD = StringVar()\r
273     Entry(f4p, textvariable=VcoutD, width=13).pack(side=LEFT, padx=5, pady=5)\r
274     RhoD = StringVar()\r
275     Entry(f4p, textvariable=RhoD, width=13).pack(side=LEFT, padx=5, pady=5)\r
276     lossrateD = StringVar()\r
277     Entry(f4p, textvariable=lossrateD, width=13).pack(side=LEFT, padx=5, pady=5)\r
278     \r
279     fline=Frame(fenPref, height=2, width=500, bg="grey")\r
280     fline.pack_propagate(0) # don't shrink\r
281     fline.pack(expand=1)\r
282     \r
283     f2p=Frame(fenPref, height=40, width=500, bd=2, relief=RIDGE)\r
284     f2p.pack_propagate(0) # don't shrink\r
285     f2p.pack()    \r
286     \r
287     Button(f2p, text="Save and quit", command=savePref, height=1, width=30).pack(anchor=N, fill=BOTH, expand=1, padx=5, pady=3)\r
288     \r
289     # Refresh the window data\r
290     refresh_pref ()\r
291     \r
292 # openPSEN function opens a .PSEN file with all PSEN parameters, read them and updates their value in the GUI\r
293 def openPSEN () :\r
294     global openPATH\r
295     global folderPATH\r
296     global savAdress\r
297     global ENRpath\r
298     global contin_lines_Path\r
299     global contin_groups_Path\r
300     global model_Path\r
301     global loadPath, wind1Path, wind2Path, pvPath\r
302     global PSSEfolder\r
303     global orange_Path\r
304     global python_Path\r
305     global config\r
306     global Vcin; global Vrate; global Vcout; global Rho; global lossrate\r
307     global PVpath\r
308     \r
309     openPATH = tkFileDialog.askopenfilename(parent=fenetre,title='Open PSEN file',filetypes=[('PSEN files', '.psen'),('All files', '.*'),])\r
310     try :\r
311         os.lstat(openPATH)\r
312     except WindowsError : # If the user doesn't choose any file we don't open it\r
313         pass \r
314     except NameError : # If the user doesn't choose any file we don't open it\r
315         pass\r
316     else :\r
317         global saved # Create a saved variable : config list will be created\r
318         saved=1\r
319         f=open(openPATH,'r')\r
320         lines=f.readlines()\r
321         config=lines[0].split(";")\r
322         savAdress=config[0]; folderPATH=config[1]; ENRpath=config[2];\r
323         contin_lines_Path=config[3]; contin_groups_Path=config[4]; model_Path=config[5]; PSSEfolder=config[6]; orange_Path=config[7]; python_Path=config[8]; \r
324         Vcin=config[9]; Vrate=config[10]; Vcout=config[11]; Rho=config[12]; lossrate=config[13];\r
325         loadPath=config[25]; wind1Path=config[31]; wind2Path=config[37]; pvPath=config[43]; \r
326         refresh(config)\r
327         f=open("lib\pref.psen", "w")\r
328         f.write(str(savAdress)+";"+str(folderPATH)+";"+str(ENRpath)+";"+str(Vcin)+";"+str(Vrate)+";"+str(Vcout)+";"+str(Rho)+";"+str(lossrate)+";0\n")\r
329         f.close()\r
330         print 'Successfuly opened '+str(openPATH)\r
331 \r
332 # This function is not used yet\r
333 def numToName (num) :\r
334     num=int(num)\r
335     if num == 1 :\r
336         name = "Normal(mean, stdev)"\r
337     elif num == 2 :\r
338         name = "Uniform(min, max)"\r
339     elif num == 3 :\r
340         name = "Exponential(lambda, gamma)"\r
341     elif num == 4 :\r
342         name = "Weibull(alpha, beta, gamma)"\r
343     elif num == 5 :\r
344         name = "TruncatedNormal(mean, stdev, min, max)"\r
345     elif num == 6 :\r
346         name = "Value list ([[v1,p1],[v2,p2],...])"\r
347     elif num == 7 :\r
348         name = "Histogram (steps, probabilities)"\r
349     elif num == 10 :\r
350         name = "PDF from file ()"\r
351     elif num == 20 :\r
352         name = "Time Serie from file (stepsize, number of points)"\r
353     return name\r
354         \r
355 # refresh function updates fields values in fenetre window\r
356 def refresh (config) :\r
357     var_MCS.set(config[14])\r
358     N_1.set(config[15])\r
359     PV.set(config[16])\r
360     Wind1.set(config[17])\r
361     Wind2.set(config[18])\r
362     Load.set(config[19])\r
363     \r
364     choix_load.set(config[20])\r
365     var_loadn1.set(config[21])\r
366     var_loadn2.set(config[22])\r
367     var_loadn3.set(config[23])\r
368     var_loadn4.set(config[24])\r
369     loadPathD.set(config[25])\r
370     \r
371     choix_wind11.set(config[26])\r
372     var_windn11.set(config[27])\r
373     var_windn12.set(config[28])\r
374     var_windn13.set(config[39])\r
375     var_windn14.set(config[30])\r
376     wind1PathD.set(config[31])\r
377     \r
378     choix_wind21.set(config[32])\r
379     var_windn21.set(config[33])\r
380     var_windn22.set(config[34])\r
381     var_windn23.set(config[35])\r
382     var_windn24.set(config[36])\r
383     wind2PathD.set(config[37])\r
384     \r
385     choix_pv.set(config[38])\r
386     var_pvn1.set(config[39])\r
387     var_pvn2.set(config[40])\r
388     var_pvn3.set(config[41])\r
389     var_pvn4.set(config[42])\r
390     pvPathD.set(config[43])\r
391 \r
392     C01D.set(config[44])\r
393     C02D.set(config[45])\r
394     C03D.set(config[46])\r
395     C04D.set(config[47])\r
396     C12D.set(config[48])\r
397     C13D.set(config[49])\r
398     C14D.set(config[50])\r
399     C23D.set(config[51])\r
400     C24D.set(config[52])\r
401     C34D.set(config[53])\r
402     \r
403     fuel_cost.set(config[54])\r
404     bus_shunt.set(config[55])\r
405     bus_loads.set(config[56])\r
406 \r
407     rate_choiceD.set(config[57])\r
408 \r
409     fenetre.update_idletasks()\r
410 \r
411 # PCpreferences function creates a window in which the user can choose some requested paths         \r
412 def PCpreferences ():\r
413     global fenPrefPC\r
414     global python_Path\r
415     global orange_Path\r
416     global PSSEfolder\r
417     \r
418     fenPrefPC = Tk()\r
419     fenPrefPC.wm_iconbitmap('lib\PSEN.ico')\r
420     fenPrefPC.wm_title('PSEN - Probabilistic Studies of Electrical Networks')\r
421     \r
422     Label(fenPrefPC, text="Configure PSEN for your computer : ", fg="black", justify=LEFT, font=("Century Gothic",12)).pack(anchor=NW, padx=10, expand=YES)\r
423     Button(fenPrefPC, text="Path to Python 2.7.exe...", command=browse_Python, height=3, width=30).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
424     Button(fenPrefPC, text="Path to orngCanvas.pyw...", command=browse_Orange, height=3, width=30).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
425     Button(fenPrefPC, text="Path to PSSE33\PSSBIN...", command=browse_PSSEfolder, height=3, width=30).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
426     Button(fenPrefPC, text="Save and close", command=closePCpref, height=3, width=15).pack(anchor=S, fill=BOTH, expand=1, padx=5, pady=10)\r
427     \r
428 def closePCpref () :\r
429     try : # Test if the user has defined all the requested variables\r
430         python_Path\r
431         orange_Path\r
432         PSSEfolder\r
433     except NameError : # If not a new window pops up and explains the data is missing\r
434         fenetre2 = Tk()\r
435         champ_label = Label(fenetre2, text="ERROR\nNo file and/or folder selected", fg="red", font=("Century Gothic",16))\r
436         champ_label.pack(side=TOP, fill=BOTH, expand=YES)\r
437     else : # If it's OK it gets the data from the fields and save it into config[]\r
438         config[6]=PSSEfolder; config[7]=orange_Path; config[8]=python_Path \r
439     try : \r
440         fenPrefPC\r
441     except NameError :\r
442         pass\r
443     else :\r
444         fenPrefPC.destroy()\r
445         print 'Data saved'\r
446 \r
447 # PCpreferences function creates a window in which the user can choose some requested paths         \r
448 def ContinPreferences ():\r
449     global fenPrefC\r
450     global contin_lines_Path\r
451     global contin_groups_Path\r
452     \r
453     fenPrefC = Tk()\r
454     fenPrefC.wm_iconbitmap('lib\PSEN.ico')\r
455     fenPrefC.wm_title('PSEN - Probabilistic Studies of Electrical Networks')\r
456     \r
457     Label(fenPrefC, text="Choose contingency files with probabilities : ", fg="black", justify=LEFT, font=("Century Gothic",12)).pack(anchor=NW, padx=10, expand=YES)\r
458     Button(fenPrefC, text="Path to branches file", command=contin_lines, height=3, width=30).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
459     Button(fenPrefC, text="Path to groups file", command=contin_groups, height=3, width=30).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
460     Button(fenPrefC, text="Save and close", command=closeCpref, height=3, width=15).pack(anchor=S, fill=BOTH, expand=1, padx=5, pady=10)\r
461     \r
462 def closeCpref () :\r
463     try : # Test if the user has defined all the requested variables\r
464         contin_lines_Path\r
465         contin_groups_Path\r
466     except NameError : # If not a new window pops up and explains the data is missing\r
467         fenetre2 = Tk()\r
468         champ_label = Label(fenetre2, text="ERROR\nNo file and/or folder selected", fg="red", font=("Century Gothic",16))\r
469         champ_label.pack(side=TOP, fill=BOTH, expand=YES)\r
470     else : # If it's OK it gets the data from the fields and save it into config[]\r
471         config[3]=contin_lines_Path; config[4]=contin_lines_Path\r
472         f=open("lib\contin.psen", "w")\r
473         f.write(str(contin_lines_Path)+";"+str(contin_groups_Path)+";0\n")\r
474         f.close()\r
475     try : \r
476         fenPrefC\r
477     except NameError :\r
478         pass\r
479     else :\r
480         print 'Added :\n'+str(contin_lines_Path)+'\n'+str(contin_groups_Path)\r
481         fenPrefC.destroy()    \r
482         print 'Saved contingency data'\r
483         \r
484 def contin_lines () :\r
485     global contin_lines_Path\r
486     contin_lines_Path =  tkFileDialog.askopenfilename(parent=fenetre,title='Choose contingency lines file',filetypes=[('CSV file', '.csv'),('All files', '.*')])\r
487     return contin_lines_Path\r
488     \r
489 def contin_groups () :\r
490     global contin_groups_Path\r
491     contin_groups_Path =  tkFileDialog.askopenfilename(parent=fenetre,title='Choose contingency groups file',filetypes=[('CSV file', '.csv'),('All files', '.*')])\r
492     return contin_groups_Path\r
493         \r
494 # Hide command window\r
495 if os.name == 'nt': # The functions only work with Windows OS\r
496     try:\r
497         import win32gui, win32console, win32con\r
498         win32console.GetConsoleWindow() # do nothing, this is just a test\r
499         def set_attached_console_visible():\r
500             state=is_attached_console_visible()\r
501             win32gui.ShowWindow(win32console.GetConsoleWindow(), win32con.SW_HIDE if state else win32con.SW_SHOW)\r
502         def is_attached_console_visible():\r
503             return win32gui.IsWindowVisible(win32console.GetConsoleWindow())\r
504     except (ImportError, NotImplementedError):\r
505         pass\r
506 \r
507 \r
508 # config_save function is used to save configuration for PSSEWrapper\r
509 def config_save():\r
510     MCS_num=var_MCS.get()\r
511     N_1_opt=N_1.get()\r
512     PV_opt=PV.get()\r
513     Wind1_opt=Wind1.get()\r
514     Wind2_opt=Wind2.get()\r
515     Load_opt=Load.get()\r
516 \r
517     load_type=choix_load.get()\r
518     load1=var_loadn1.get()\r
519     load2=var_loadn2.get()\r
520     load3=var_loadn3.get()\r
521     load4=var_loadn4.get()\r
522     loadPath=loadPathD.get()\r
523     \r
524     wind11_type=choix_wind11.get()\r
525     wind11=var_windn11.get()\r
526     wind12=var_windn12.get()\r
527     wind13=var_windn13.get()\r
528     wind14=var_windn14.get()\r
529     wind1Path=wind1PathD.get()\r
530     \r
531     wind21_type=choix_wind21.get()\r
532     wind21=var_windn21.get()\r
533     wind22=var_windn22.get()\r
534     wind23=var_windn23.get()\r
535     wind24=var_windn24.get()\r
536     wind2Path=wind2PathD.get()\r
537     \r
538     pv_type=choix_pv.get()\r
539     pv1=var_pvn1.get()\r
540     pv2=var_pvn2.get()\r
541     pv3=var_pvn3.get()\r
542     pv4=var_pvn4.get()\r
543     pvPath=pvPathD.get()\r
544     \r
545     C01=C01D.get()\r
546     C02=C02D.get()\r
547     C03=C03D.get()\r
548     C04=C04D.get()\r
549     C12=C12D.get()\r
550     C13=C13D.get()\r
551     C14=C14D.get()\r
552     C23=C23D.get()\r
553     C24=C24D.get()\r
554     C34=C34D.get()\r
555     \r
556     fuel_cost_opt = fuel_cost.get()\r
557     bus_shunt_opt = bus_shunt.get()\r
558     bus_loads_opt = bus_loads.get()\r
559     \r
560     rate_choice=rate_choiceD.get()\r
561 \r
562     f=open("lib\config.psen", "w")\r
563 # Write probabilistic model data \r
564     f.write(str(MCS_num)+";"+str(N_1_opt)+";"+str(PV_opt)+";"+str(Wind1_opt)+";"+str(Wind2_opt)+";"+str(Load_opt)+";"+str(fuel_cost_opt)+";"+str(bus_shunt_opt)+";"+str(bus_loads_opt)+"\n")\r
565     \r
566 # Write load probabilistic model data \r
567     if load_type == "Normal(mean, stdev)" :\r
568         f.write('1;'+str(load1)+";"+str(load2)+';0')\r
569     elif load_type == "Uniform(min, max)" :\r
570         f.write('2;'+str(load1)+";"+str(load2)+';0')\r
571     elif load_type == "Exponential(lambda, gamma)" :\r
572         f.write('3;'+str(load1)+";"+str(load2)+';0')\r
573     elif load_type == "Weibull(alpha, beta, gamma)" :\r
574         f.write('4;'+str(load1)+";"+str(load2)+";"+str(load3)+';0')\r
575     elif load_type == "TruncatedNormal(mean, stdev, min, max)" :\r
576         f.write('5;'+str(load1)+";"+str(load2)+";"+str(load3)+";"+str(load4)+';0')\r
577     elif load_type == "Value list (values, probabilities)" :\r
578         f.write('6;'+str(load1)+";"+str(load2)+';0')\r
579     elif load_type == 'Histogram (steps, probabilities)' :\r
580         f.write('7;'+str(load1)+";"+str(load2)+';0')\r
581     elif load_type== "PDF from file ()" :\r
582         try :\r
583             loadPath\r
584         except NameError :\r
585             fenetre2 = Tk()\r
586             Label(fenetre2, text="ERROR\nNo file selected", fg="red", font=("Century Gothic",16)).pack(side=TOP, fill=BOTH, expand=YES)\r
587         else :\r
588             f.write('10;'+loadPath+';0')   \r
589     elif load_type== "Time Serie from file (stepsize, number of points)" :\r
590         try :\r
591             loadPath\r
592         except NameError :\r
593             fenetre2 = Tk()\r
594             Label(fenetre2, text="ERROR\nNo file selected", fg="red", font=("Century Gothic",16)).pack(side=TOP, fill=BOTH, expand=YES)\r
595         else :\r
596             f.write('20;'+loadPath+";"+str(load1)+";"+str(load2)+';0') \r
597     else :\r
598         fenetre2 = Tk()\r
599         Label(fenetre2, text="ERROR\nNo load model selected", fg="red", font=("Century Gothic",16)).pack(side=TOP, fill=BOTH, expand=YES)\r
600     f.write("\n")\r
601     \r
602 # Write wind 1 probabilistic model data \r
603     if wind11_type == "Normal(mean, stdev)" :\r
604         f.write('1;'+str(wind11)+";"+str(wind12)+';0')\r
605     elif wind11_type == "Uniform(min, max)" :\r
606         f.write('2;'+str(wind11)+";"+str(wind12)+';0')\r
607     elif wind11_type == "Exponential(lambda, gamma)" :\r
608         f.write('3;'+str(wind11)+";"+str(wind12)+';0')\r
609     elif wind11_type == "Weibull(alpha, beta, gamma)" :\r
610         f.write('4;'+str(wind11)+";"+str(wind12)+";"+str(wind13)+';0')\r
611     elif wind11_type == "TruncatedNormal(mean, stdev, min, max)" :\r
612         f.write('5;'+str(wind11)+";"+str(wind12)+";"+str(wind13)+";"+str(wind14)+';0')\r
613     elif wind11_type == "Value list (values, probabilities)" :\r
614         f.write('6;'+str(wind11)+";"+str(wind12)+';0')\r
615     elif wind11_type == 'Histogram (steps, probabilities)' :\r
616         f.write('7;'+str(wind11)+";"+str(wind12)+';0')\r
617     elif wind11_type== "PDF from file ()" :\r
618         try :\r
619             wind1Path\r
620         except NameError :\r
621             fenetre2 = Tk()\r
622             Label(fenetre2, text="ERROR\nNo file selected", fg="red", font=("Century Gothic",16)).pack(side=TOP, fill=BOTH, expand=YES)\r
623         else :\r
624             f.write('10;'+wind1Path+';0')   \r
625     elif wind11_type== "Time Serie from file (stepsize, number of points)" :\r
626         try :\r
627             wind1Path\r
628         except NameError :\r
629             fenetre2 = Tk()\r
630             Label(fenetre2, text="ERROR\nNo file selected", fg="red", font=("Century Gothic",16)).pack(side=TOP, fill=BOTH, expand=YES)\r
631         else :\r
632             f.write('20;'+wind1Path+";"+str(wind11)+";"+str(wind12)+';0') \r
633     else :\r
634         fenetre2 = Tk()\r
635         Label(fenetre2, text="ERROR\nNo wind model selected", fg="red", font=("Century Gothic",16)).pack(side=TOP, fill=BOTH, expand=YES)\r
636     f.write("\n")\r
637     \r
638 # Write wind 2 probabilistic model data    \r
639     if wind21_type == "Normal(mean, stdev)" :\r
640         f.write('1;'+str(wind21)+";"+str(wind22)+';0')\r
641     elif wind21_type == "Uniform(min, max)" :\r
642         f.write('2;'+str(wind21)+";"+str(wind22)+';0')\r
643     elif wind21_type == "Exponential(lambda, gamma)" :\r
644         f.write('3;'+str(wind21)+";"+str(wind22)+';0')\r
645     elif wind21_type == "Weibull(alpha, beta, gamma)" :\r
646         f.write('4;'+str(wind21)+";"+str(wind22)+";"+str(wind23)+';0')\r
647     elif wind21_type == "TruncatedNormal(mean, stdev, min, max)" :\r
648         f.write('5;'+str(wind21)+";"+str(wind22)+";"+str(wind23)+";"+str(wind24)+';0')\r
649     elif wind21_type == "Value list (values, probabilities)" :\r
650         f.write('6;'+str(wind21)+";"+str(wind22)+';0')\r
651     elif wind21_type == 'Histogram (steps, probabilities)' :\r
652         f.write('7;'+str(wind21)+";"+str(wind22)+';0')\r
653     elif wind21_type== "PDF from file ()" :\r
654         try :\r
655             wind2Path\r
656         except NameError :\r
657             fenetre2 = Tk()\r
658             Label(fenetre2, text="ERROR\nNo file selected", fg="red", font=("Century Gothic",16)).pack(side=TOP, fill=BOTH, expand=YES)\r
659         else :\r
660             f.write('10;'+wind2Path+';0')   \r
661     elif wind21_type== "Time Serie from file (stepsize, number of points)" :\r
662         try :\r
663             wind2Path\r
664         except NameError :\r
665             fenetre2 = Tk()\r
666             Label(fenetre2, text="ERROR\nNo file selected", fg="red", font=("Century Gothic",16)).pack(side=TOP, fill=BOTH, expand=YES)\r
667         else :\r
668             f.write('20;'+wind2Path+";"+str(wind21)+";"+str(wind22)+';0') \r
669     else :\r
670         fenetre2 = Tk()\r
671         Label(fenetre2, text="ERROR\nNo wind 2 model selected", fg="red", font=("Century Gothic",16)).pack(side=TOP, fill=BOTH, expand=YES)\r
672     f.write("\n")\r
673 \r
674 # Write correlation probabilistic model data     \r
675     f.write(str(C01)+";"+str(C02)+";"+str(C03)+";"+str(C04)+";"+str(C12)+";"+str(C13)+";"+str(C14)+";"+str(C23)+";"+str(C24)+";"+str(C34)+";0")\r
676     f.write("\n") \r
677 \r
678 # Write pv probabilistic model data     \r
679     if pv_type == "Normal(mean, stdev)" :\r
680         f.write('1;'+str(pv1)+";"+str(pv2)+';0')\r
681     elif pv_type == "Uniform(min, max)" :\r
682         f.write('2;'+str(pv1)+";"+str(pv2)+';0')\r
683     elif pv_type == "Exponential(lambda, gamma)" :\r
684         f.write('3;'+str(pv1)+";"+str(pv2)+';0')\r
685     elif pv_type == "Weibull(alpha, beta, gamma)" :\r
686         f.write('4;'+str(pv1)+";"+str(pv2)+";"+str(pv3)+';0')\r
687     elif pv_type == "TruncatedNormal(mean, stdev, min, max)" :\r
688         f.write('5;'+str(pv1)+";"+str(pv2)+";"+str(pv3)+";"+str(pv4)+';0')\r
689     elif pv_type == "Value list (values, probabilities)" :\r
690         f.write('6;'+str(pv1)+";"+str(pv2)+';0')\r
691     elif pv_type == 'Histogram (steps, probabilities)' :\r
692         f.write('7;'+str(pv1)+";"+str(pv2)+';0')\r
693     elif pv_type== "PDF from file ()" :\r
694         try :\r
695             pvPath\r
696         except NameError :\r
697             fenetre2 = Tk()\r
698             champ_label = Label(fenetre2, text="ERROR\nNo file selected", fg="red", font=("Century Gothic",16))\r
699             champ_label.pack(side=TOP, fill=BOTH, expand=YES)\r
700         else :\r
701             f.write('10;'+pvPath+';0')   \r
702     elif pv_type== "Time Serie from file (stepsize, number of points)" :\r
703         try :\r
704             pvPath\r
705         except NameError :\r
706             fenetre2 = Tk()\r
707             champ_label = Label(fenetre2, text="ERROR\nNo file selected", fg="red", font=("Century Gothic",16))\r
708             champ_label.pack(side=TOP, fill=BOTH, expand=YES)\r
709         else :\r
710             f.write('20;'+pvPath+";"+str(pv1)+";"+str(pv2)+';0') \r
711     else :\r
712         fenetre2 = Tk()\r
713         champ_label = Label(fenetre2, text="ERROR\nNo wind model selected", fg="red", font=("Century Gothic",16))\r
714         champ_label.pack(side=TOP, fill=BOTH, expand=YES)\r
715     f.write("\n")\r
716 \r
717 # Write OPF data model     \r
718     f.write(str(fuel_cost_opt) +";"+ str(bus_shunt_opt) +";"+ str(bus_loads_opt)+";0\n")\r
719 \r
720 # Write Imap rate choice     \r
721     f.write(str(rate_choice)+";0\n")\r
722 \r
723     f.close()\r
724     \r
725     print 'Successfuly saved case data'\r
726 \r
727 # launch_PSEN function is used to run PSSEWrapper code with the configuration in the GUI\r
728 def launch_PSEN():\r
729     config_save() # Current configuration is fist saved\r
730     PSEN_Path='PSEN/PSSEWrapper.py'\r
731     subprocess.Popen([python_Path,PSEN_Path])\r
732 \r
733 # launch_orange function is used to launch Orange with the model file\r
734 def launch_Orange():\r
735     subprocess.Popen([python_Path,orange_Path,model_Path])\r
736 \r
737 # browse_load is used to select a .CSV file with a 1D array of load measures\r
738 def browse_load() :\r
739     global loadPath\r
740     loadPath = tkFileDialog.askopenfilename(parent=fenetre,title='Open file for load data estimation',filetypes=[('CSV files', '.csv'),('All files', '.*')])\r
741     loadPathD.set(loadPath)\r
742     fenetre.update_idletasks() # updates the fields paths\r
743     return loadPath\r
744 \r
745 # browse_wind is used to select a .CSV file with a 1D array of wind measures    \r
746 def browse_wind1() :\r
747     global wind1Path\r
748     wind1Path = tkFileDialog.askopenfilename(parent=fenetre,title='Open file for wind 1 data estimation',filetypes=[('CSV files', '.csv'),('All files', '.*')])\r
749     wind1PathD.set(wind1Path)\r
750     fenetre.update_idletasks() # updates the fields paths\r
751     return wind1Path\r
752     \r
753 # browse_wind is used to select a .CSV file with a 1D array of wind measures    \r
754 def browse_wind2() :\r
755     global wind2Path\r
756     wind2Path = tkFileDialog.askopenfilename(parent=fenetre,title='Open file for wind 2 data estimation',filetypes=[('CSV files', '.csv'),('All files', '.*')])\r
757     wind2PathD.set(wind2Path)\r
758     fenetre.update_idletasks() # updates the fields paths\r
759     return wind2Path\r
760 \r
761 # browse_pv is used to select a .CSV file with a 1D array of PV measures    \r
762 def browse_pv() :\r
763     global pvPath\r
764     pvPath = tkFileDialog.askopenfilename(parent=fenetre,title='Open file for PV data estimation',filetypes=[('CSV files', '.csv'),('All files', '.*')])\r
765     pvPathD.set(pvPath)\r
766     fenetre.update_idletasks() # updates the fields paths\r
767     return pvPath    \r
768 \r
769 # continload function is a browsing window returning the path to the contingency CSV file\r
770 def continload () :\r
771     global continpath\r
772     continpath = tkFileDialog.askopenfilename(parent=fenetre,title='Open contingency file',filetypes=[('CSV files', '.csv'),('All files', '.*')])\r
773     try :\r
774         continpath\r
775     except NameError :\r
776         pass\r
777     else : # Saves the path into a file for PSSEWrapper.py\r
778         f=open("lib\contin.psen", "w")\r
779         f.write(str(continpath)+";0\n")\r
780         f.close()\r
781     return continpath\r
782 \r
783 # orangeload function is a browsing window returning the path to the orange model file OWS\r
784 def orangeload () :\r
785     global model_Path\r
786     model_Path = tkFileDialog.askopenfilename(parent=fenetre,title='Open orange file...',filetypes=[('Orange Widget Scripts', '.ows')])\r
787     \r
788 def browse_PSSEfolder () :\r
789     global PSSEfolder\r
790     if os.path.exists("C:\Program Files\PTI\PSSE33\PSSBIN") == True : \r
791         path="C:\Program Files\PTI\PSSE33\PSSBIN"\r
792     else : \r
793         path="C:"\r
794     PSSEfolder = tkFileDialog.askdirectory(parent=fenPrefPC,title='Choose PSSE/PSSBIN folder', initialdir=path)\r
795     return PSSEfolder\r
796     \r
797 def browse_Python () :\r
798     global python_Path\r
799     if os.path.exists("C:\Python27") == True : \r
800         path="C:\Python27"\r
801     else : \r
802         path="C:"\r
803     python_Path =  tkFileDialog.askopenfilename(parent=fenetre,title='Choose python.exe',filetypes=[('Executables', '.exe'),('All files', '.*')], initialdir=path)\r
804     return python_Path\r
805     \r
806 def browse_Orange () :\r
807     global orange_Path\r
808     if os.path.exists("C:\Python27\Lib\site-packages\Orange\OrangeCanvas") == True : \r
809         path="C:\Python27\Lib\site-packages\Orange\OrangeCanvas"\r
810     else : \r
811         path="C:"\r
812     orange_Path = tkFileDialog.askopenfilename(parent=fenetre,title='Choose orngCanvas.pyw',filetypes=[('Python file', '.pyw'),('All files', '.*')], initialdir=path)\r
813     return orange_Path\r
814 # On crĂ©e une fenĂȘtre, racine de notre interface\r
815 def fenetre() :\r
816     global fenetre,var_MCS,N_1,PV,Wind1,Wind2,Load,choix_load,var_loadn1,var_loadn2,var_loadn3,var_loadn4,loadPathD,choix_wind11,var_windn11,var_windn12,var_windn13,var_windn14,wind1PathD,choix_wind21,var_windn21,var_windn22,var_windn23,var_windn24,wind2PathD,choix_pv,var_pvn1,var_pvn2,var_pvn3,var_pvn4,pvPathD,C01D,C02D,C03D,C04D,C12D,C13D,C14D,C23D,C24D,C34D,fuel_cost,bus_shunt,bus_loads,rate_choiceD\r
817     fenetre = Toplevel(root)\r
818     fenetre.wm_iconbitmap('lib\PSEN.ico')\r
819     fenetre.wm_title('PSEN - Probabilistic Studies of Electrical Networks')\r
820     \r
821     def openshort (event):\r
822         openPSEN()\r
823     def saveshort (event) : \r
824         savePSEN()\r
825     def quitshort (event) : \r
826         fenetre.destroy()\r
827     def orangeshort (event):\r
828         launch_Orange()\r
829     def runshort (event) : \r
830         launch_PSEN()\r
831     def prefshort (event) : \r
832         preferences()    \r
833     \r
834     fenetre.bind_all("<Control-q>", quitshort)\r
835     fenetre.bind_all("<Control-o>", openshort)\r
836     fenetre.bind_all("<Control-s>", saveshort)\r
837     fenetre.bind_all("<Control-a>", orangeshort)\r
838     fenetre.bind_all("<Control-r>", runshort)\r
839     fenetre.bind_all("<Control-p>", prefshort)    \r
840     \r
841     wd=500\r
842     \r
843     # Create a toplevel menu\r
844     menubar=Menu(fenetre)\r
845     \r
846     filemenu = Menu(menubar, tearoff=0)\r
847     filemenu.add_command(label="Open PSEN", command=openPSEN, accelerator="Ctrl+O")\r
848     filemenu.add_command(label="Save PSEN", command=savePSEN, accelerator="Ctrl+S")\r
849     filemenu.add_separator() \r
850     filemenu.add_command(label="Exit", command=fenetre.quit, accelerator="Ctrl+Q")\r
851     menubar.add_cascade(label="File", menu=filemenu)\r
852     \r
853     editmenu = Menu(menubar, tearoff=0)\r
854     editmenu.add_command(label="Computer preferences", command=PCpreferences)\r
855     editmenu.add_separator() \r
856     editmenu.add_command(label="Study preferences", command=preferences, accelerator="Ctrl+P")\r
857     menubar.add_cascade(label="Edit", menu=editmenu)\r
858     \r
859     exemenu = Menu(menubar, tearoff=0)\r
860     exemenu.add_command(label="Run PSEN", command=preferences, accelerator="Ctrl+R")\r
861     menubar.add_cascade(label="Execution", menu=exemenu)\r
862     \r
863     contmenu = Menu(menubar, tearoff=0)\r
864     contmenu.add_command(label="Load contingency file", command=ContinPreferences)\r
865     menubar.add_cascade(label="Contingency analysis", menu=contmenu)\r
866     \r
867     orangemenu = Menu(menubar, tearoff=0)\r
868     orangemenu.add_command(label="Choose Orange model", command=orangeload)\r
869     orangemenu.add_command(label="Open Orange", command=launch_Orange, accelerator="Ctrl+A")\r
870     menubar.add_cascade(label="Orange analysis", menu=orangemenu)\r
871     \r
872     viewmenu = Menu(menubar, tearoff=0)\r
873     viewmenu.add_command(label="Show/Hide cmd window", command=set_attached_console_visible)\r
874     menubar.add_cascade(label="View", menu=viewmenu)\r
875     \r
876     # Display the menu\r
877     fenetre.config(menu=menubar)\r
878     \r
879     ftop=Frame(fenetre, height=140, width=2*wd, bd=2, relief=RIDGE)\r
880     ftop.pack_propagate(0) # don't shrink\r
881     ftop.pack()\r
882     \r
883     fmid=Frame(fenetre, height=500, width=2*wd)\r
884     fmid.pack_propagate(0) # don't shrink\r
885     fmid.pack()\r
886     \r
887     fleft=Frame(fmid, height=500, width=wd, bd=2, relief=RIDGE)\r
888     fleft.pack_propagate(0) # don't shrink\r
889     fleft.pack(side=LEFT)\r
890     \r
891     fright=Frame(fmid, height=500, width=wd, bd=2, relief=RIDGE)\r
892     fright.pack_propagate(0) # don't shrink\r
893     fright.pack(side=RIGHT)\r
894     \r
895     #canvas=Canvas(fenetre, width=600, height=100, bg='ivory')\r
896     Label(ftop, image=header).pack(side=TOP, fill=BOTH, expand=YES)\r
897     #canvas.pack(side=TOP,padx=5,pady=5)\r
898 \r
899     fline=Frame(ftop, height=2, width=2*wd, bg="grey")\r
900     fline.pack_propagate(0) # don't shrink\r
901     fline.pack(expand=1)\r
902     \r
903     fl0=Frame(fleft, height=55, width=wd)\r
904     fl0.pack_propagate(0) # don't shrink\r
905     fl0.pack()\r
906     \r
907     Label(fl0, text="Simulation parameters", fg="black", justify=LEFT, font=("Century Gothic",14)).pack(anchor=NW, padx=10, expand=NO)\r
908     \r
909     # Change Monte Carlo samplings\r
910     Label(fl0, text="Choose the number of samples:", fg="black").pack(side=LEFT, padx=10, expand=NO)\r
911     \r
912     var_MCS = StringVar()\r
913     Entry(fl0, textvariable=var_MCS, width=15).pack(side=LEFT, padx=15, expand=NO)\r
914     \r
915     fl01=Frame(fleft, height=30, width=wd)\r
916     fl01.pack_propagate(0) # don't shrink\r
917     fl01.pack()\r
918     \r
919     # Change N-1 study or not\r
920     N_1 = IntVar()\r
921     Checkbutton(fl01, text="N-1 study ?", variable=N_1).pack(side=LEFT, padx=2)\r
922     \r
923     # Include Load ?\r
924     Load = IntVar()\r
925     Checkbutton(fl01, text="Load study ?", variable=Load).pack(side=LEFT, padx=2)\r
926     \r
927     # Include Wind 1 ?\r
928     Wind1 = IntVar()\r
929     Checkbutton(fl01, text="Wind 1 study ?", variable=Wind1).pack(side=LEFT, padx=2)\r
930     \r
931     # Include Wind 2 ?\r
932     Wind2 = IntVar()\r
933     Checkbutton(fl01, text="Wind 2 study ?", variable=Wind2).pack(side=LEFT, padx=2)\r
934     \r
935     # Include PV\r
936     PV = IntVar()\r
937     Checkbutton(fl01, text="PV study ?", variable=PV).pack(side=LEFT, padx=2)\r
938     \r
939     Frame(fleft, height=2, width=wd, bg="grey").pack(pady=10, expand=NO)\r
940     \r
941     fl1=Frame(fleft, height=152, width=wd)\r
942     fl1.pack_propagate(0) # don't shrink\r
943     fl1.pack(pady=0, expand=NO)\r
944     \r
945     champ_label = Label(fl1, text="Correlation upper matrix :", fg="black", justify=LEFT, font=("Century Gothic",14))\r
946     champ_label.pack(anchor=NW, padx=10, expand=NO)\r
947     \r
948     champ_label = Label(fl1, text="Load                         N-1                    Wind1               Wind2                 Solar           ", fg="black")\r
949     champ_label.pack(anchor=NE, padx=10)\r
950     \r
951     fl11=Frame(fl1, height=25, width=wd)\r
952     fl11.pack_propagate(0) # don't shrink\r
953     fl11.pack(padx=10, expand=NO)\r
954     C04D = StringVar()\r
955     Entry(fl11, textvariable=C04D, width=10).pack(side=RIGHT, padx=10, pady=5)\r
956     C04D.set(0)\r
957     C03D = StringVar()\r
958     Entry(fl11, textvariable=C03D, width=10).pack(side=RIGHT, padx=10, pady=5)\r
959     C03D.set(0)\r
960     C02D = StringVar()\r
961     Entry(fl11, textvariable=C02D, width=10).pack(side=RIGHT, padx=10, pady=5)\r
962     C02D.set(0)\r
963     C01D = StringVar()\r
964     Entry(fl11, textvariable=C01D, width=10).pack(side=RIGHT, padx=10, pady=5)\r
965     C01D.set(0)\r
966     \r
967     champ_label = Label(fl11, text="Load     ", fg="black")\r
968     champ_label.pack(side=RIGHT, padx=10)\r
969     \r
970     fl12=Frame(fl1, height=25, width=wd)\r
971     fl12.pack_propagate(0) # don't shrink\r
972     fl12.pack(padx=10, expand=NO)\r
973     C14D = StringVar()\r
974     Entry(fl12, textvariable=C14D, width=10).pack(side=RIGHT, padx=10, pady=5)\r
975     C14D.set(0)\r
976     C13D = StringVar()\r
977     Entry(fl12, textvariable=C13D, width=10).pack(side=RIGHT, padx=10, pady=5)\r
978     C13D.set(0)\r
979     C12D = StringVar()\r
980     Entry(fl12, textvariable=C12D, width=10).pack(side=RIGHT, padx=10, pady=5)\r
981     C12D.set(0)\r
982     \r
983     champ_label = Label(fl12, text="N-1    ", fg="black")\r
984     champ_label.pack(side=RIGHT, padx=10)\r
985     \r
986     fl13=Frame(fl1, height=25, width=wd)\r
987     fl13.pack_propagate(0) # don't shrink\r
988     fl13.pack(padx=10, expand=NO)\r
989     C24D = StringVar()\r
990     Entry(fl13, textvariable=C24D, width=10).pack(side=RIGHT, padx=10, pady=5)\r
991     C24D.set(0)\r
992     C23D = StringVar()\r
993     Entry(fl13, textvariable=C23D, width=10).pack(side=RIGHT, padx=10, pady=5)\r
994     C23D.set(0)\r
995     \r
996     champ_label = Label(fl13, text="Wind1    ", fg="black")\r
997     champ_label.pack(side=RIGHT, padx=10)\r
998     \r
999     fl14=Frame(fl1, height=25, width=wd)\r
1000     fl14.pack_propagate(0) # don't shrink\r
1001     fl14.pack(padx=10, expand=NO)\r
1002     C34D = StringVar()\r
1003     Entry(fl14, textvariable=C34D, width=10).pack(side=RIGHT, padx=10, pady=5)\r
1004     C34D.set(0)\r
1005     \r
1006     champ_label = Label(fl14, text="Wind2      ", fg="black")\r
1007     champ_label.pack(side=RIGHT, padx=10)\r
1008     \r
1009     fline=Frame(fleft, height=2, width=wd, bg="grey")\r
1010     fline.pack(pady=10, expand=NO)\r
1011     \r
1012     fl2=Frame(fleft, height=20, width=wd)\r
1013     fl2.pack_propagate(0) # don't shrink\r
1014     fl2.pack()\r
1015     \r
1016     champ_label = Label(fl2, text="PSSe OPF parameters", fg="black", justify=LEFT, font=("Century Gothic",14))\r
1017     champ_label.pack(anchor=NW, padx=10, expand=NO)\r
1018     \r
1019     fl21=Frame(fleft, height=30, width=wd)\r
1020     fl21.pack_propagate(0) # don't shrink\r
1021     fl21.pack()\r
1022     \r
1023     # "Minimize fuel cost"\r
1024     fuel_cost = IntVar()\r
1025     Checkbutton(fl21, text="Minimize fuel cost", variable=fuel_cost).pack(side=LEFT, padx=10)\r
1026     \r
1027     # "Minimize adj. bus shunts"\r
1028     bus_shunt = IntVar()\r
1029     Checkbutton(fl21, text="Minimize adj. bus shunts", variable=bus_shunt).pack(side=LEFT, padx=10)\r
1030     \r
1031     # "Minimize adj. bus loads"\r
1032     bus_loads = IntVar()\r
1033     Checkbutton(fl21, text="Minimize adj. bus loads", variable=bus_loads).pack(side=LEFT, padx=10)\r
1034     \r
1035     fline=Frame(fleft, height=2, width=wd, bg="grey")\r
1036     fline.pack(pady=10, expand=NO)\r
1037     \r
1038     fl3=Frame(fleft, height=20, width=wd)\r
1039     fl3.pack_propagate(0) # don't shrink\r
1040     fl3.pack()\r
1041     \r
1042     champ_label = Label(fl3, text="PSSe Irate choice :", fg="black", justify=LEFT, font=("Century Gothic",14))\r
1043     champ_label.pack(side=LEFT, padx=10, expand=NO)\r
1044 \r
1045     # "Minimize fuel cost"\r
1046     rate_choiceD = IntVar()\r
1047     Radiobutton(fl3, text="Rate A", variable=rate_choiceD, value=1).pack(side=LEFT, padx=20)\r
1048     Radiobutton(fl3, text="Rate B", variable=rate_choiceD, value=2).pack(side=LEFT, padx=10)\r
1049     Radiobutton(fl3, text="Rate C", variable=rate_choiceD, value=3).pack(side=LEFT, padx=10)\r
1050     \r
1051 #---- Choose the probability laws ---\r
1052     #---- Load model ----\r
1053     fr0=Frame(fright, height=55, width=wd)\r
1054     fr0.pack_propagate(0) # don't shrink\r
1055     fr0.pack(expand=NO, anchor=NW)\r
1056     \r
1057     champ_label = Label(fr0, text="Load model :", fg="black", justify=LEFT, font=("Century Gothic",14))\r
1058     champ_label.pack(anchor=NW, padx=10, expand=NO)\r
1059     \r
1060     choix_load=StringVar()\r
1061     laws_choice = ('Normal(mean, stdev)','Uniform(min, max)','Exponential(lambda, gamma)','Weibull(alpha, beta, gamma)', 'TruncatedNormal(mean, stdev, min, max)', 'Value list (values, probabilities)', 'Histogram (steps, probabilities)', 'PDF from file ()', 'Time Serie from file (stepsize, number of points)' )\r
1062     Combobox(fr0, textvariable = choix_load, values = laws_choice, state = 'readonly', width=50).pack(side=LEFT, padx=10, expand=NO)\r
1063     choix_load.set('Choose your load model')\r
1064     \r
1065     fr01=Frame(fright, height=30, width=wd)\r
1066     fr01.pack_propagate(0) # don't shrink\r
1067     fr01.pack(expand=NO)\r
1068     champ_label = Label(fr01, text="Parameters :", fg="black").pack(side=LEFT, padx=10, pady=0)\r
1069     \r
1070     var_loadn1 = StringVar()\r
1071     Entry(fr01, textvariable=var_loadn1, width=12).pack(side=LEFT, padx=10, pady=5)\r
1072     var_loadn2 = StringVar()\r
1073     Entry(fr01, textvariable=var_loadn2, width=12).pack(side=LEFT, padx=10, pady=5)\r
1074     var_loadn3 = StringVar()\r
1075     Entry(fr01, textvariable=var_loadn3, width=12).pack(side=LEFT, padx=10, pady=5)\r
1076     var_loadn4 = StringVar()\r
1077     Entry(fr01, textvariable=var_loadn4, width=12).pack(side=LEFT, padx=10, pady=5)\r
1078     \r
1079     fr011=Frame(fright, height=35, width=wd)\r
1080     fr011.pack_propagate(0) # don't shrink\r
1081     fr011.pack(expand=NO)\r
1082     \r
1083     # We create the browse button\r
1084     loadPathD=StringVar()\r
1085     Entry(fr011, textvariable=loadPathD, width=50).pack(side=LEFT, padx=15, expand=YES)\r
1086     \r
1087     Button(fr011, text="Load data", command=browse_load).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
1088     \r
1089     fline=Frame(fright, height=2, width=wd, bg="grey")\r
1090     fline.pack(pady=2, expand=NO)\r
1091     \r
1092     #---- Wind 1 model ----\r
1093     fr1=Frame(fright, height=55, width=wd)\r
1094     fr1.pack_propagate(0) # don't shrink\r
1095     fr1.pack(expand=NO, pady=0)\r
1096     \r
1097     champ_label = Label(fr1, text="Wind 1 distribution model :", fg="black", justify=LEFT, font=("Century Gothic",14))\r
1098     champ_label.pack(anchor=NW, padx=10, expand=NO)\r
1099     \r
1100     choix_wind11=StringVar()\r
1101     laws_choice = ('Normal(mean, stdev)','Uniform(min, max)','Exponential(lambda, gamma)','Weibull(alpha, beta, gamma)', 'TruncatedNormal(mean, stdev, min, max)', 'Value list (values, probabilities)', 'Histogram (steps, probabilities)', 'PDF from file ()', 'Time Serie from file (stepsize, number of points)' )\r
1102     Combobox(fr1, textvariable = choix_wind11, values = laws_choice, state = 'readonly', width=50).pack(side=LEFT, padx=10, expand=NO)\r
1103     choix_wind11.set('Choose your wind model')\r
1104     \r
1105     fr11=Frame(fright, height=30, width=wd)\r
1106     fr11.pack_propagate(0) # don't shrink\r
1107     fr11.pack(expand=NO)\r
1108     Label(fr11, text="Parameters :", fg="black").pack(side=LEFT, padx=10, pady=0)\r
1109     \r
1110     var_windn11 = StringVar()\r
1111     Entry(fr11, textvariable=var_windn11, width=12).pack(side=LEFT, padx=10, pady=5)\r
1112     var_windn12 = StringVar()\r
1113     Entry(fr11, textvariable=var_windn12, width=12).pack(side=LEFT, padx=10, pady=5)\r
1114     var_windn13 = StringVar()\r
1115     Entry(fr11, textvariable=var_windn13, width=12).pack(side=LEFT, padx=10, pady=5)\r
1116     var_windn14 = StringVar()\r
1117     Entry(fr11, textvariable=var_windn14, width=12).pack(side=LEFT, padx=10, pady=5)\r
1118     \r
1119     fr111=Frame(fright, height=35, width=wd)\r
1120     fr111.pack_propagate(0) # don't shrink\r
1121     fr111.pack(expand=NO)\r
1122     \r
1123     # We create the browse button\r
1124     wind1PathD=StringVar()\r
1125     Entry(fr111, textvariable=wind1PathD, width=50).pack(side=LEFT, padx=15, expand=YES)\r
1126     \r
1127     Button(fr111, text="Wind 1 data", command=browse_wind1).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
1128     \r
1129     fline=Frame(fright, height=2, width=wd, bg="grey")\r
1130     fline.pack(pady=2, expand=NO)\r
1131     \r
1132     #---- Wind 2 model ----\r
1133     fr2=Frame(fright, height=55, width=wd)\r
1134     fr2.pack_propagate(0) # don't shrink\r
1135     fr2.pack(expand=NO, pady=0)\r
1136     \r
1137     champ_label = Label(fr2, text="Wind 2 distribution model :", fg="black", justify=LEFT, font=("Century Gothic",14))\r
1138     champ_label.pack(anchor=NW, padx=10, expand=NO)\r
1139     \r
1140     choix_wind21=StringVar()\r
1141     laws_choice = ('Normal(mean, stdev)','Uniform(min, max)','Exponential(lambda, gamma)','Weibull(alpha, beta, gamma)', 'TruncatedNormal(mean, stdev, min, max)', 'Value list (values, probabilities)', 'Histogram (steps, probabilities)', 'PDF from file ()', 'Time Serie from file (stepsize, number of points)' )\r
1142     Combobox(fr2, textvariable = choix_wind21, values = laws_choice, state = 'readonly', width=50).pack(side=LEFT, padx=10, expand=NO)\r
1143     choix_wind21.set('Choose your wind model')\r
1144     \r
1145     fr21=Frame(fright, height=30, width=wd)\r
1146     fr21.pack_propagate(0) # don't shrink\r
1147     fr21.pack(expand=NO)\r
1148     Label(fr21, text="Parameters :", fg="black").pack(side=LEFT, padx=10, pady=0)\r
1149     \r
1150     var_windn21 = StringVar()\r
1151     Entry(fr21, textvariable=var_windn21, width=12).pack(side=LEFT, padx=10, pady=5)\r
1152     var_windn22 = StringVar()\r
1153     Entry(fr21, textvariable=var_windn22, width=12).pack(side=LEFT, padx=10, pady=5)\r
1154     var_windn23 = StringVar()\r
1155     Entry(fr21, textvariable=var_windn23, width=12).pack(side=LEFT, padx=10, pady=5)\r
1156     var_windn24 = StringVar()\r
1157     Entry(fr21, textvariable=var_windn24, width=12).pack(side=LEFT, padx=10, pady=5)\r
1158     \r
1159     fr211=Frame(fright, height=35, width=wd)\r
1160     fr211.pack_propagate(0) # don't shrink\r
1161     fr211.pack(expand=NO)\r
1162     \r
1163     # We create the browse button\r
1164     wind2PathD=StringVar()\r
1165     Entry(fr211, textvariable=wind2PathD, width=50).pack(side=LEFT, padx=15, expand=YES)\r
1166     \r
1167     Button(fr211, text="Wind 2 data", command=browse_wind2).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
1168     \r
1169     fline=Frame(fright, height=2, width=wd, bg="grey")\r
1170     fline.pack(pady=2, expand=NO)\r
1171     \r
1172     #---- PV model ----    \r
1173     fr3=Frame(fright, height=55, width=wd)\r
1174     fr3.pack_propagate(0) # don't shrink\r
1175     fr3.pack(expand=NO, pady=0)\r
1176     \r
1177     champ_label = Label(fr3, text="Photovoltaic distribution model :", fg="black", justify=LEFT, font=("Century Gothic",14))\r
1178     champ_label.pack(anchor=NW, padx=10, expand=NO)\r
1179     \r
1180     choix_pv=StringVar()\r
1181     laws_choice = ('Normal(mean, stdev)','Uniform(min, max)','Exponential(lambda, gamma)','Weibull(alpha, beta, gamma)', 'TruncatedNormal(mean, stdev, min, max)', 'Value list (values, probabilities)', 'Histogram (steps, probabilities)', 'PDF from file ()', 'Time Serie from file (stepsize, number of points)' )\r
1182     Combobox(fr3, textvariable = choix_pv, values = laws_choice, state = 'readonly', width=50).pack(side=LEFT, padx=10, expand=NO)\r
1183     choix_pv.set('Choose your PV model')\r
1184     \r
1185     fr31=Frame(fright, height=30, width=wd)\r
1186     fr31.pack_propagate(0) # don't shrink\r
1187     fr31.pack(expand=NO)\r
1188     Label(fr31, text="Parameters :", fg="black").pack(side=LEFT, padx=10, pady=0)\r
1189     \r
1190     var_pvn1 = StringVar()\r
1191     Entry(fr31, textvariable=var_pvn1, width=12).pack(side=LEFT, padx=10, pady=5)\r
1192     var_pvn2 = StringVar()\r
1193     Entry(fr31, textvariable=var_pvn2, width=12).pack(side=LEFT, padx=10, pady=5)\r
1194     var_pvn3 = StringVar()\r
1195     Entry(fr31, textvariable=var_pvn3, width=12).pack(side=LEFT, padx=10, pady=5)\r
1196     var_pvn4 = StringVar()\r
1197     Entry(fr31, textvariable=var_pvn4, width=12).pack(side=LEFT, padx=10, pady=5)\r
1198     \r
1199     fr311=Frame(fright, height=35, width=wd)\r
1200     fr311.pack_propagate(0) # don't shrink\r
1201     fr311.pack(expand=NO)\r
1202     \r
1203     # We create the browse button\r
1204     pvPathD=StringVar()\r
1205     Entry(fr311, textvariable=pvPathD, width=50).pack(side=LEFT, padx=15, expand=YES)\r
1206     \r
1207     Button(fr311, text="PV data", command=browse_pv).pack(side=LEFT, fill=BOTH, expand=1, padx=5, pady=3)\r
1208     \r
1209     fb=Frame(fenetre, height=50, width=2*wd, bd=2, relief=RIDGE)\r
1210     fb.pack_propagate(0) # don't shrink\r
1211     fb.pack()\r
1212     \r
1213     Frame(fb, height=2, width=2*wd, bg="grey").pack(expand=1)\r
1214     \r
1215     # We create the launch button\r
1216     Button(fb, text="Run PSEN", command=launch_PSEN, height=1, width=20, underline=YES).pack(expand=NO, padx=5, pady=3)\r
1217     \r
1218 # On dĂ©marre la boucle Tkinter qui s'interompt quand on ferme la fenĂȘtre\r
1219 fenetre()\r
1220 root.mainloop()