Skip to content

Commit d1bbde2

Browse files
clean up lint issues
1 parent fc5d926 commit d1bbde2

1 file changed

Lines changed: 36 additions & 32 deletions

File tree

electricpy/sim.py

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,18 @@ def step_response(system, npts=1000, dt=0.01, combine=True, xlim=False,
212212
_plt.grid()
213213
_plt.legend()
214214
_plt.xlabel("Time (seconds)")
215-
if xlim != False:
215+
if not xlim:
216216
_plt.xlim(xlim)
217217
_plt.subplot(122)
218218
_plt.title(errtitle)
219219
_plt.plot(TT, errS, 'k', label=errlabel)
220220
_plt.grid()
221221
_plt.legend()
222222
_plt.xlabel("Time (seconds)")
223-
if xlim != False:
223+
if not xlim:
224224
_plt.xlim(xlim)
225225
_plt.subplots_adjust(wspace=0.3)
226-
if filename != None:
226+
if filename is not None:
227227
_plt.savefig(filename)
228228
return _plt
229229

@@ -297,18 +297,18 @@ def ramp_response(system, npts=1000, dt=0.01, combine=True, xlim=False,
297297
_plt.grid()
298298
_plt.legend()
299299
_plt.xlabel("Time (seconds)")
300-
if xlim != False:
300+
if not xlim:
301301
_plt.xlim(xlim)
302302
_plt.subplot(122)
303303
_plt.title(errtitle)
304304
_plt.plot(TT, errR, 'k', label=errlabel)
305305
_plt.grid()
306306
_plt.legend()
307307
_plt.xlabel("Time (seconds)")
308-
if xlim != False:
308+
if not xlim:
309309
_plt.xlim(xlim)
310310
_plt.subplots_adjust(wspace=0.3)
311-
if filename != None:
311+
if filename is not None:
312312
_plt.savefig(filename)
313313
return _plt
314314

@@ -381,18 +381,18 @@ def parabolic_response(system, npts=1000, dt=0.01, combine=True, xlim=False,
381381
_plt.grid()
382382
_plt.legend()
383383
_plt.xlabel("Time (seconds)")
384-
if xlim != False:
384+
if not xlim:
385385
_plt.xlim(xlim)
386386
_plt.subplot(122)
387387
_plt.title(errtitle)
388388
_plt.plot(TT, errP, 'k', label=errlabel)
389389
_plt.grid()
390390
_plt.legend()
391391
_plt.xlabel("Time (seconds)")
392-
if xlim != False:
392+
if not xlim:
393393
_plt.xlim(xlim)
394394
_plt.subplots_adjust(wspace=0.3)
395-
if filename != None:
395+
if filename is not None:
396396
_plt.savefig(filename)
397397
return _plt
398398

@@ -652,58 +652,58 @@ def func_c(self, x): # Concatenated Function
652652

653653
# Plot Forcing Functions
654654
if (plotforcing):
655-
fffig = _plt.figure("Forcing Functions")
655+
_ = _plt.figure("Forcing Functions")
656656
if fnc > 1:
657657
for x in range(fnc):
658658
_plt.plot(TT, fn_arr[x], label="f" + str(x + 1))
659659
else:
660660
_plt.plot(TT, fn_arr, label="f1")
661-
if xlim != False:
661+
if not xlim:
662662
_plt.xlim(xlim)
663-
if ylim != False:
663+
if not ylim:
664664
_plt.ylim(ylim)
665665
_plt.title("Forcing Functions " + title)
666666
_plt.xlabel("Time (seconds)")
667667
_plt.legend(title="Forcing Functions")
668668
_plt.grid()
669-
if filename != None:
669+
if filename is not None:
670670
_plt.savefig('Simulation Forcing Functions.png')
671671
if plotstate:
672672
_plt.show()
673673

674674
# Plot each state-variable over time
675-
stvfig = _plt.figure("State Variables")
675+
_ = _plt.figure("State Variables")
676676
for x in range(xtim_len):
677677
_plt.plot(TT, xtim[x], label="x" + str(x + 1))
678-
if xlim != False:
678+
if not xlim:
679679
_plt.xlim(xlim)
680-
if ylim != False:
680+
if not ylim:
681681
_plt.ylim(ylim)
682682
_plt.title("Simulated Output Terms " + soltype[solution] + title)
683683
_plt.xlabel("Time (seconds)")
684684
_plt.legend(title="State Variable")
685685
_plt.grid()
686-
if filename != None:
686+
if filename is not None:
687687
_plt.savefig('Simulation Terms.png')
688688
if plotstate:
689689
_plt.show()
690690

691691
# Plot combined output
692692
if (plotresult and solution == 3):
693-
cofig = _plt.figure("Combined Output")
693+
_ = _plt.figure("Combined Output")
694694
C = _np.asarray(C) # convert back to array for operation
695695
for i in range(cC):
696696
yout = yout + xtim[i] * C[0][i] # Sum all st-space var mult. by their coeff
697697
yout = _np.asarray(yout) # convert output to array for plotting purposes
698698
_plt.plot(TT, yout[0])
699-
if xlim != False:
699+
if not xlim:
700700
_plt.xlim(xlim)
701-
if ylim != False:
701+
if not ylim:
702702
_plt.ylim(ylim)
703703
_plt.title("Combined Output " + title)
704704
_plt.xlabel("Time (seconds)")
705705
_plt.grid()
706-
if filename != None:
706+
if filename is not None:
707707
_plt.savefig('Simulation Combined Output.png')
708708
if plotresult:
709709
_plt.show()
@@ -958,7 +958,6 @@ def func_c(self, x): # Concatenated Function
958958
Q_funcs = []
959959
P_strgs = []
960960
Q_strgs = []
961-
Vi_list = []
962961
lists = [P_strgs, Q_strgs]
963962
i = 0 # Index
964963
ii = 0 # String Index
@@ -986,12 +985,12 @@ def func_c(self, x): # Concatenated Function
986985
Padd = False
987986
Qadd = False
988987
for _j in range(N):
989-
if P_list[_k] == None:
988+
if P_list[_k] is None:
990989
continue # Don't Generate Requirements for Slack Bus
991990
if (_k != _j) and not Padd: # Skip i,i Terms
992991
ang_len += 1
993992
Padd = True
994-
if (_k != _j) and (Q_list[_k] != None) and not Qadd:
993+
if (_k != _j) and (Q_list[_k] is not None) and not Qadd:
995994
mag_len += 1
996995
Qadd = True
997996
Vxdim = ang_len + mag_len
@@ -1006,20 +1005,21 @@ def func_c(self, x): # Concatenated Function
10061005
# Add New Entry To Lists
10071006
for LST in lists:
10081007
LST.append(None)
1009-
if P_list[_k] == None:
1008+
if P_list[_k] is None:
10101009
continue # Don't Generate Requirements for Slack Bus
10111010
# Collect Other Terms
10121011
Yind = "[{}][{}]".format(_k, _j)
1013-
if verbose: print("K:", _k, "\tJ:", _j)
1012+
if verbose:
1013+
print("K:", _k, "\tJ:", _j)
10141014
# Generate Voltage-Related Strings
10151015
if _k != _j: # Skip i,i Terms
10161016
# Generate K-Related Strings
1017-
if V_list[_k][0] == None: # The Vk magnitude is unknown
1017+
if V_list[_k][0] is None: # The Vk magnitude is unknown
10181018
Vkm = "Vx[{}]".format(_k + ang_len - magoff * _k) # Use Variable Magnitude
10191019
Vka = "Vx[{}]".format(_k - angoff) # Use Variable Angle
10201020
else: # The Vk magnitude is known
10211021
Vkm = "V_list[{}][0]".format(_k) # Load Magnitude
1022-
if V_list[_k][1] == None: # The Vj angle is unknown
1022+
if V_list[_k][1] is None: # The Vj angle is unknown
10231023
Vka = "Vx[{}]".format(_k - angoff) # Use Variable Angle
10241024
else:
10251025
Vka = "V_list[{}][1]".format(_k) # Load Angle
@@ -1035,7 +1035,8 @@ def func_c(self, x): # Concatenated Function
10351035
Vja = "V_list[{}][1]".format(_j) # Load Angle
10361036
# Generate String and Append to List of Functions
10371037
P_strgs[i] = (Pstr.format(Vkm, Vka, Vjm, Vja, Yind))
1038-
if verbose: print("New P-String:", P_strgs[i])
1038+
if verbose:
1039+
print("New P-String:", P_strgs[i])
10391040
# Generate Q Requirement
10401041
if Q_list[_k] is not None:
10411042
# Generate String and Append to List of Functions
@@ -1045,7 +1046,8 @@ def func_c(self, x): # Concatenated Function
10451046
else:
10461047
Qgen = ""
10471048
Q_strgs[i] = (Qstr.format(Vkm, Vka, Vjm, Vja, Yind, Qgen))
1048-
if verbose: print("New Q-String:", Q_strgs[i])
1049+
if verbose:
1050+
print("New Q-String:", Q_strgs[i])
10491051
# Increment Index at Each Interior Level
10501052
i += 1
10511053
tempPstr = "P_funcs.append(lambda Vx: -P_list[{0}]".format(_k)
@@ -1060,10 +1062,12 @@ def func_c(self, x): # Concatenated Function
10601062
tempPstr += ")"
10611063
tempQstr += ")"
10621064
if any(P_strgs[ii:i]):
1063-
if verbose: print("Full P-Func Str:", tempPstr)
1065+
if verbose:
1066+
print("Full P-Func Str:", tempPstr)
10641067
exec(tempPstr)
10651068
if any(Q_strgs[ii:i]):
1066-
if verbose: print("Full Q-Func Str:", tempQstr)
1069+
if verbose:
1070+
print("Full Q-Func Str:", tempQstr)
10671071
exec(tempQstr)
10681072
ii = i # Increase Lower Index
10691073
retset = (P_funcs, Q_funcs)

0 commit comments

Comments
 (0)