Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
faoh committed Sep 11, 2022
1 parent 4ba5a2c commit 8b31cc9
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions esa/saw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ def run_ecological_analysis(self, target: str = 'MW', split_generator: bool = Tr
:results: it is a list of ecological metrics, including the Ecological Robustness (Reco),
the Ascendancy (ASC), the Development Capacity (DC), the Cycled Throughflow (tstc), the Finn Cycling Index (CI)
and the Total System Overhead (TSO) and the energy flow matrix EFM
and the Total System Overhead (TSO)
"""
warnings.warn("Please make sure the current system state is valid")

Expand All @@ -1335,7 +1335,7 @@ def run_ecological_analysis(self, target: str = 'MW', split_generator: bool = Tr
branch_df = self.GetParametersMultipleElement('branch', kf)
# add a function to get LinelossMVA
LinelossMVA = np.zeros(len(branch_df))
for i in range(branch_df.shape(0)):
for i in range(len(branch_df)):
realloss = branch_df["LineLossMW"][i]
reactiveloss = branch_df["LineLossMVR"][i]
LinelossMVA[i] = np.sqrt(pow(realloss, 2) + pow(reactiveloss, 2))
Expand Down Expand Up @@ -1365,8 +1365,8 @@ def run_ecological_analysis(self, target: str = 'MW', split_generator: bool = Tr
# It should be better since it captures the generators' robustness
### not aggregate gen #################################################################################################
# gen_unique=list(set(gen.BusNum))
num_gen = gen.shape(0)
num_bus = bus.shape(0)
num_gen = len(gen)
num_bus = len(bus)
num_actor = num_gen+num_bus+3
s = (num_actor, num_actor)
EFM = np.zeros(s)
Expand All @@ -1385,15 +1385,15 @@ def run_ecological_analysis(self, target: str = 'MW', split_generator: bool = Tr
EFM[j+1][1+num_gen+i] = EFM[0][j+1]

# feed load to last second
for i in range(load.shape(0)):
for i in range(len(load)):
for j in range(num_bus):
if load.loadindex[i] == j:
flow = load.loc[i, f"Load{target}"]
#flow = load.LoadMW[i]
EFM[1+num_gen+i][1+num_gen+num_bus] += flow

# feed line flow to EFM
for i in range(branch_df.shape(0)):
for i in range(len(branch_df)):
frombus = branch_df['findex'][i]
tobus = branch_df['tindex'][i]
flow = branch_df.loc[i, f"Line{target}"]
Expand All @@ -1406,7 +1406,7 @@ def run_ecological_analysis(self, target: str = 'MW', split_generator: bool = Tr
# this loss aggregates the line loss to from bus
# can be further updated based on your consideration.
# however, the loss is/should be very small, thus it may not induce any change
for i in range(branch_df.shape(0)):
for i in range(len(branch_df)):
frombus = branch_df['findex'][i]
tobus = branch_df['tindex'][i]
flow = branch_df.loc[i, f"LineLoss{target}"]
Expand All @@ -1417,15 +1417,15 @@ def run_ecological_analysis(self, target: str = 'MW', split_generator: bool = Tr
# Option 2 #### Not considering generators' robustness
###aggregate gen#####################################################################################################
gen_unique = list(set(gen.BusNum))
num_gen = gen_unique.shape(0)
num_gen = len(gen_unique)
num_bus = bus.shape[0]
num_actor = num_gen+num_bus+3
s = (num_actor, num_actor)
EFM = np.zeros(s)

# feed generator to first row
for i in range(num_gen):
for j in range(gen.shape(0)):
for j in range(len(gen)):
if gen_unique[i] == gen.gindex[j]:
#if target == 'MW':
flow = gen.loc[i, f"Gen{target}"]
Expand All @@ -1437,14 +1437,14 @@ def run_ecological_analysis(self, target: str = 'MW', split_generator: bool = Tr
EFM[j+1][1+num_gen+i] = EFM[0][j+1]

# feed load to last second
for i in range(load.shape(0)):
for i in range(len(load)):
for j in range(num_bus):
if load.BusNum[i] == j:
flow = load.loc[i, f"Load{target}"]
EFM[1+num_gen+i][1+num_gen+num_bus] += flow

# feed line flow to EFM
for i in range(branch_df.shape(0)):
for i in range(len(branch_df)):
frombus = branch_df['findex'][i]
tobus = branch_df['tindex'][i]
flow = branch_df.loc[i, f"Line{target}"]
Expand All @@ -1457,7 +1457,7 @@ def run_ecological_analysis(self, target: str = 'MW', split_generator: bool = Tr
# this loss aggregates the line loss to from bus
# can be further updated based on your consideration.
# however, the loss is/should be very small, thus it may not induce any change
for i in range(branch_df.shape(0)):
for i in range(len(branch_df)):
frombus = branch_df['findex'][i]
tobus = branch_df['tindex'][i]
flow = branch_df.loc[i, f"LineLoss{target}"]
Expand All @@ -1477,12 +1477,12 @@ def run_ecological_analysis(self, target: str = 'MW', split_generator: bool = Tr
P_rsum = P.sum(axis=1) # sum over rows

k = 1
s = T.shape(0)
s = len(T)
Q = np.zeros((s, s))

tstp = T.sum()

for i in range(s):
for i in range(len(T)):
if P_rsum[i] > 0:
Q[i] = P[i]/P_rsum[1]
else:
Expand Down

1 comment on commit 8b31cc9

@mzy2240
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to #86

Please sign in to comment.