patternpythonMinor
Processing simulation data from power flow analysis
Viewed 0 times
processingflowsimulationanalysispowerfromdata
Problem
The intro is a bit long. If you're not interested, then please read the update, and have a look at the specific parts I'm highlighting.
I'm very interested in any improvements, but you can assume that all calls starting with
The code is written in Python 2.7. This is because the simulation tool doesn't work with newer versions.
Update:
In case the code is too long for anyone to bother reviewing it, I'll write up some specific lines that probably could need some reviewing:
Explanation:
The code below calls a simulation software (called Power System Simulator for Engineering), and runs power flow analysis using the module
The code works fine, but unfortunately you can't run it as it stands now, since the software is not a free program, and you don't have the power system model. I've provided sample input variables that can be used instead of the function calls (there are only a few lines that must be changed). This way, the bottom half of the code can be tested properly. I'll also provide an overview of the different outputs the simulation tool gives, and
I'm very interested in any improvements, but you can assume that all calls starting with
psspy. are correct and can't be changed. Also, the calls to psspy that are inside a loop have to be inside a loop, I can't call the functions with several input values. The code is written in Python 2.7. This is because the simulation tool doesn't work with newer versions.
Update:
In case the code is too long for anyone to bother reviewing it, I'll write up some specific lines that probably could need some reviewing:
- The way I create
branch_string. First:nodes_from_string = [str(x) for x in nodes_from], followed bybranch_string = [nodes_from_string[x] +'-' +nodes_to_string[x] for x in range(0, len(nodes_from))].
- Is this a good way of doing this. I'm not using
nodes_from_stringlater in the code, but I donf = nodes_from[branch]andnf_str = str(nf)inside the loop.
- What about the part where the plots are created? Starting with
fig = plt.figure().
- Should I do this outside the loop instead? If so, how could this be done in a simple manner?
- Can I simplify the way I'm creating datasheets and writing to Excel?
- Do I use
enumerateas it should be used in the last 3 rows?Izero_3is a np.array.
Explanation:
The code below calls a simulation software (called Power System Simulator for Engineering), and runs power flow analysis using the module
psspy (PSS/E to Python).The code works fine, but unfortunately you can't run it as it stands now, since the software is not a free program, and you don't have the power system model. I've provided sample input variables that can be used instead of the function calls (there are only a few lines that must be changed). This way, the bottom half of the code can be tested properly. I'll also provide an overview of the different outputs the simulation tool gives, and
Solution
There's only a single thing I can spot as a non-python programmer:
You can use
if ierr == 0:
print "Case loaded: " + CASE
if ierr != 0:
sys.exit("Case could not load. Check name and folder!")You can use
else here.if ierr == 0:
print "Case loaded: " + CASE
else:
sys.exit("Case could not load. Check name and folder!")Code Snippets
if ierr == 0:
print "Case loaded: " + CASE
if ierr != 0:
sys.exit("Case could not load. Check name and folder!")if ierr == 0:
print "Case loaded: " + CASE
else:
sys.exit("Case could not load. Check name and folder!")Context
StackExchange Code Review Q#136618, answer score: 3
Revisions (0)
No revisions yet.