Data Transfer Between Python and DigSilent
Data Transfer Between Python and DigSilent
1.Description: This procedure of data exchange between Python and DIgSILENT was created in
order to benefit of both software advantages, thus you can use them at the same time in power
system analysis. In this way a loop was created between Python and DIgSILENT. The procedure
comes with a .py file and a script from a .pfd file (DIgSILENT 15.1.7 x86), so the data transfer is
made between these 2 files using as a link layer 2 csv files.
The data transfer between Python and DIgSILENT is made using two .csv files (Flag.csv and
Data.csv):
- Flag.csv - can take only one value (1 or 0): 1 - means that Python works and DIgSILENT waits.
0 - means that DIgSILENT works and Python waits.
- Data.csv - contains a vector of data and is divided in 2 (Fig. 3). First part can be filled with
variables that are necessary in the data exchange procedure (we use only 7 variables in this
example:- SizeOfDataVectPy, SizeOfDataVectDIg, NrOfIterations, CurrentIt, NrComVar,
NrOfDataTransFromPy, NrOfDataTransFromDIg), and the second part are the variables
of interest that you want to transfer from Python to DIgSILENT and from DIgSILENT to
Python.
Fig. 1. Flowchart
DIgSILENT Python
Data variables; Data variables;
Read Flag.csv; Read Flag.csv;
While Flag.csv = 1 { !wait for Python to work While Flag.csv = 0 { !wait for DIgSILENT to work
Scan Flag.csv; Scan Flag.csv;
If Flag.csv = 0{ If Flag.csv = 1{
break; break;
} }
} }
Read Data.csv; Read Data.csv;
Write Input Data; Write Input Data;
!-------------------------------------------------------- !--------------------------------------------------------
1.use values from vector InputData in your analysis 1.use values from vector InputData in your analysis
2.write variables resulted in your analysis in 2.write variables resulted in your analysis in
OutputData OutputData
!-------------------------------------------------------- !--------------------------------------------------------
Write Flag.csv = 1; Write Flag.csv = 0;
From Fig.1, is depicted the flowchart of the .py file and the script from DIgSILENT. It can be
seen that for a software to wait for the other to work, it is used a simple while loop which is
continuously scanning the Flag.csv. The while loop is broken only when the software that works
finishes its computation and modifies the value of Flag.csv.
2. Run files in your computer: In order the software to communicate between them you must
introduce in DigSilent script, the path where the .py and the DigSilent script are stored in your
computer (see video). The .py file doesn’t need to introduce this path, because it creates
automatic the Data.csv and Flag.csv in the folder where .py and DigSilent script are stored. After
this is done, you first must run the .py file and after that you must execute the script in DigSilent
(see the video). The data that is transferred between software (as an example) are:
- From Python to DigSilent: a random number between 100 and 1000 transferred in a vector of
dimension 7 (for example: 121 121 121 121 121 121 121).
- From DigSilent to Python: a random number between 1 and 99 transferred in a vector of
dimension 13 (for example: 41 41 41 41 41 41 41 41 41 41 41 41 41)
To adapt the procedure to your problem, you must write code in both .py and DigSilent script in
the space clearly delimited in the files.
SizeOfDataVectPy
SizeOfDataVectDIg
NrOfIterations
CurrentIt
NrComVar Data useful in communication
NrOfDataTransFromPy between Python and DIgSILENT
NrOfDataTransFromDIg
0
0
0
var1
. Variables of interest transferred
. between Python and DIgSILENT
.
varn