Skip to content

Commit

Permalink
trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
lthurner committed Apr 3, 2017
1 parent 0a60ee4 commit 375fe92
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 140 deletions.
18 changes: 9 additions & 9 deletions pandapower/build_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ def _build_bus_ppc(net, ppc):
# init results (= voltages) from previous power flow
ppc["bus"][:n_bus, VM] = net["res_bus"]["vm_pu"].values
ppc["bus"][:n_bus, VA] = net["res_bus"].va_degree.values

if mode == "sc":
ppc["bus_sc"] = np.empty(shape=(n_bus, 10), dtype=float)
ppc["bus_sc"].fill(np.nan)
_add_c_to_ppc(net, ppc)


if copy_constraints_to_ppc:
if "max_vm_pu" in net.bus:
Expand Down Expand Up @@ -233,7 +233,7 @@ def _calc_loads_and_add_on_ppc_opf(net, ppc):
vl = (_is_elements["load"] & ~l["controllable"]) * l["scaling"].values.T / np.float64(1000.)
lp = l["p_kw"].values * vl
lq = l["q_kvar"].values * vl
else:
else:
lp = []
lq = []

Expand Down Expand Up @@ -290,13 +290,13 @@ def _calc_shunts_and_add_on_ppc(net, ppc):

ppc["bus"][b, GS] = vp
ppc["bus"][b, BS] = -vq

def _controllable_to_bool(ctrl):
ctrl_bool = []
for val in ctrl:
ctrl_bool.append(val if not np.isnan(val) else False)
return np.array(ctrl_bool, dtype=bool)

def _add_gen_impedances_ppc(net, ppc):
_add_ext_grid_sc_impedance(net, ppc)
_add_gen_sc_impedance(net, ppc)
Expand Down Expand Up @@ -340,7 +340,7 @@ def _add_gen_sc_impedance(net, ppc):
gen_buses = gen.bus.values
bus_lookup = net["_pd2ppc_lookups"]["bus"]
gen_buses_ppc = bus_lookup[gen_buses]

vn_net = ppc["bus"][gen_buses_ppc, BASE_KV]
cmax = ppc["bus_sc"][gen_buses_ppc, C_MAX]
phi_gen = np.arccos(gen.cos_phi)
Expand Down Expand Up @@ -373,15 +373,15 @@ def _add_sgen_sc_impedance(net, ppc):
x_sgen = np.sqrt(z_sgen**2 / (0.1**2 + 1))
r_sgen = np.sqrt(z_sgen**2 - x_sgen**2)
y_sgen = 1 / (r_sgen + x_sgen*1j)

buses, gs, bs = _sum_by_group(sgen_buses_ppc, y_sgen.real, y_sgen.imag)
ppc["bus"][buses, GS] = gs
ppc["bus"][buses, BS] = bs
ppc["bus"][buses, BS] = bs

def _generator_correction_factor(vn_net, vn_gen, cmax, phi_gen, xdss):
kg = vn_gen / vn_net * cmax / (1 + xdss * np.sin(phi_gen))
return kg

def _add_c_to_ppc(net, ppc):
from pandapower.shortcircuit.idx_bus import C_MAX, C_MIN
ppc["bus_sc"][:, C_MAX] = 1.1
Expand Down
4 changes: 2 additions & 2 deletions pandapower/build_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _build_pp_xward(net, ppc, gen_end, xw_end, q_lim_default, update_lookup=True




def _update_gen_ppc(net, ppc):
'''
Takes the ppc network and updates the gen values from the values in net.
Expand Down Expand Up @@ -257,7 +257,7 @@ def _build_gen_opf(net, ppc, delta=1e-10):
min_p_kw = ppc["gen"][gen_end:sg_end, [PMAX]]
ncn.copyto(min_p_kw, p_lim_default, where=isnan(min_p_kw))
ppc["gen"][gen_end:sg_end, [PMAX]] = min_p_kw

# add controllable loads
if l_end > sg_end:
load_buses = bus_lookup[l_is["bus"].values]
Expand Down
62 changes: 31 additions & 31 deletions pandapower/estimation/state_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def estimate(net, init='flat', tolerance=1e-6, maximum_iterations=10,
**init** - (string) Initial voltage for the estimation. 'flat' sets 1.0 p.u. / 0° for all
buses, 'results' uses the values from *res_bus_est* if available and 'slack' considers the
slack bus voltage (and optionally, angle) as the initial values. Default is 'flat'.
OPTIONAL:
**tolerance** - (float) - When the maximum state change between iterations is less than
tolerance, the process stops. Default is 1e-6.
Expand All @@ -66,36 +66,36 @@ def estimate(net, init='flat', tolerance=1e-6, maximum_iterations=10,
elif init != 'flat':
raise UserWarning("Unsupported init value. Using flat initialization.")
return wls.estimate(v_start, delta_start, calculate_voltage_angles)


def remove_bad_data(net, init='flat', tolerance=1e-6, maximum_iterations=10,
calculate_voltage_angles=True, rn_max_threshold=3.0, chi2_prob_false=0.05):
"""
Wrapper function for bad data removal.
INPUT:
**net** - The net within this line should be created.
**init** - (string) Initial voltage for the estimation. 'flat' sets 1.0 p.u. / 0° for all
buses, 'results' uses the values from *res_bus_est* if available and 'slack' considers the
slack bus voltage (and optionally, angle) as the initial values. Default is 'flat'.
OPTIONAL:
**tolerance** - (float) - When the maximum state change between iterations is less than
tolerance, the process stops. Default is 1e-6.
**maximum_iterations** - (integer) - Maximum number of iterations. Default is 10.
**calculate_voltage_angles** - (boolean) - Take into account absolute voltage angles and phase
shifts in transformers, if init is 'slack'. Default is True.
shifts in transformers, if init is 'slack'. Default is True.
**rn_max_threshold** (float) - Identification threshold to determine
if the largest normalized residual reflects a bad measurement
(default value of 3.0)
**chi2_prob_false** (float) - probability of error / false alarms
(default value: 0.05)
OUTPUT:
**successful** (boolean) - Was the state estimation successful?
"""
Expand All @@ -120,26 +120,26 @@ def chi2_analysis(net, init='flat', tolerance=1e-6, maximum_iterations=10,
calculate_voltage_angles=True, chi2_prob_false=0.05):
"""
Wrapper function for the chi-squared test.
INPUT:
**net** - The net within this line should be created.
**init** - (string) Initial voltage for the estimation. 'flat' sets 1.0 p.u. / 0° for all
buses, 'results' uses the values from *res_bus_est* if available and 'slack' considers the
slack bus voltage (and optionally, angle) as the initial values. Default is 'flat'.
OPTIONAL:
**tolerance** - (float) - When the maximum state change between iterations is less than
tolerance, the process stops. Default is 1e-6.
**maximum_iterations** - (integer) - Maximum number of iterations. Default is 10.
**calculate_voltage_angles** - (boolean) - Take into account absolute voltage angles and phase
shifts in transformers, if init is 'slack'. Default is True.
shifts in transformers, if init is 'slack'. Default is True.
**chi2_prob_false** (float) - probability of error / false alarms
(default value: 0.05)
OUTPUT:
**successful** (boolean) - Was the state estimation successful?
"""
Expand All @@ -158,7 +158,7 @@ def chi2_analysis(net, init='flat', tolerance=1e-6, maximum_iterations=10,
raise UserWarning("Unsupported init value. Using flat initialization.")
return wls.perform_chi2_test(v_start, delta_start, calculate_voltage_angles,
chi2_prob_false)


class state_estimation(object):
"""
Expand Down Expand Up @@ -213,7 +213,7 @@ def estimate(self, v_start=None, delta_start=None, calculate_voltage_angles=True
**delta_start** (np.array, shape=(1,), optional) - Vector with initial values for all
voltage angles in degrees (sorted by bus index)
OPTIONAL:
**calculate_voltage_angles** - (bool) - Take into account absolute voltage angles and
phase shifts in transformers Default is True.
Expand Down Expand Up @@ -573,11 +573,11 @@ def perform_chi2_test(self, v_in_out=None, delta_in_out=None,
**delta_in_out** (np.array, shape=(1,), optional) - Vector with initial values for all
voltage angles in degrees (sorted by bus index)
OPTIONAL:
**calculate_voltage_angles** - (boolean) - Take into account absolute voltage angles and phase
shifts in transformers, if init is 'slack'. Default is True.
**chi2_prob_false** (float) - probability of error / false alarms (standard value: 0.05)
OUTPUT:
Expand All @@ -586,13 +586,13 @@ def perform_chi2_test(self, v_in_out=None, delta_in_out=None,
EXAMPLE:
perform_chi2_test(np.array([1.0, 1.0, 1.0]), np.array([0.0, 0.0, 0.0]), 0.97)
"""
"""
# 'flat'-start conditions
if v_in_out is None:
v_in_out = np.ones(self.net.bus.shape[0])
if delta_in_out is None:
delta_in_out = np.zeros(self.net.bus.shape[0])
delta_in_out = np.zeros(self.net.bus.shape[0])

# perform SE
successful = self.estimate(v_in_out, delta_in_out, calculate_voltage_angles)

Expand Down Expand Up @@ -644,15 +644,15 @@ def perform_rn_max_test(self, v_in_out=None, delta_in_out=None,
**delta_in_out** (np.array, shape=(1,), optional) - Vector with initial values for all
voltage angles in degrees (sorted by bus index)
OPTIONAL:
OPTIONAL:
**calculate_voltage_angles** - (boolean) - Take into account absolute voltage angles and phase
shifts in transformers, if init is 'slack'. Default is True.
**rn_max_threshold** (float) - Identification threshold to determine
if the largest normalized residual reflects a bad measurement
(standard value of 3.0)
**chi2_prob_false** (float) - probability of error / false alarms
(standard value: 0.05)
Expand All @@ -667,8 +667,8 @@ def perform_rn_max_test(self, v_in_out=None, delta_in_out=None,
if v_in_out is None:
v_in_out = np.ones(self.net.bus.shape[0])
if delta_in_out is None:
delta_in_out = np.zeros(self.net.bus.shape[0])
delta_in_out = np.zeros(self.net.bus.shape[0])

num_iterations = 0

v_in = v_in_out
Expand Down Expand Up @@ -744,9 +744,9 @@ def perform_rn_max_test(self, v_in_out=None, delta_in_out=None,
self.logger.error("A problem appeared while using the linear algebra methods."
"Check and change the measurement set.")
return False

self.logger.debug("rn_max identification threshold: %.2f" % rn_max_threshold)

num_iterations += 1

return successful
Expand Down
16 changes: 8 additions & 8 deletions pandapower/estimation/wls_matrix_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, ppc, slack_buses, non_slack_buses, s_ref, bs_cols, br_cols):
self.create_y()

# Function which builds a node admittance matrix out of the topology data
# In addition, it provides the series admittances of lines as G_series and B_series
# In addition, it provides the series admittances of lines as G_series and B_series
def create_y(self):
from_to = np.concatenate((self.ppc["branch"][:, 0].real, self.ppc["branch"][:, 1].real))\
.astype(int)
Expand All @@ -54,11 +54,11 @@ def create_y(self):
self.G_shunt = np.zeros_like(self.G)
self.B_shunt = np.zeros((n, n))
self.B_shunt[from_to, to_from] = np.tile(0.5 * self.ppc["branch"][:, 4].real, 2)

# Get Y as tuple (real, imaginary)
def get_y(self):
return self.G, self.B

# Creates h(x), depending on the current U and delta and the static topology data
def create_hx(self, v, delta):
deltas = delta[:, np.newaxis] - delta
Expand Down Expand Up @@ -117,7 +117,7 @@ def create_hx(self, v, delta):

return hx

# Create Jacobian matrix
# Create Jacobian matrix
def create_jacobian(self, v, delta):
n = len(self.ppc["bus"])
G = self.G
Expand All @@ -126,10 +126,10 @@ def create_jacobian(self, v, delta):
B_series = self.B_series
G_shunt = self.G_shunt
B_shunt = self.B_shunt

# Create Jacobi Matrix
# Source: p.23; Power System State Estimation by Ali Abur

deltas = delta[:, np.newaxis] - delta # delta_i - delta_j
cos_delta = np.cos(deltas) # cos(delta_i - delta_j)
sin_delta = np.sin(deltas) # sin(delta_i - delta_j)
Expand All @@ -154,7 +154,7 @@ def create_jacobian(self, v, delta):
H_dQinj_dU[diag_n, diag_n] = np.sum(v * (G * sin_delta - B * cos_delta), axis=1) \
- (v * B.diagonal())

# Submatrices d(Pij)/d(theta) and d(Pij)/d(V)
# Submatrices d(Pij)/d(theta) and d(Pij)/d(V)
# d(P01)/d(theta0) is at position H_dPij_dth_i[0,1]
# d(P23)/d(theta3) is at position H_dPij_dth_j[2,3]
# d(P23)/d(theta1) is 0 and not stored in the matrix
Expand Down Expand Up @@ -194,7 +194,7 @@ def create_jacobian(self, v, delta):
columns = 2 * n - len(self.slack_buses)
range_theta = self.non_slack_buses
range_v = list(range(n))

h_mat = np.zeros((1, columns)) # create matrix with dummy line so that we can append to it

# if P bus measurements exist
Expand Down
Loading

0 comments on commit 375fe92

Please sign in to comment.