Skip to content

Commit

Permalink
pd deprecation fixes in availability.py
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-springer committed Sep 11, 2024
1 parent 7d3929d commit 8eb38c8
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions rdtools/availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,13 @@ def _calc_loss_subsystem(self, low_threshold, relative_sizes,
system_delta = 1 - power_system / virtual_full_power

subsystem_fraction = relative_sizes / relative_sizes.sum()
smallest_delta = power_subsystem.le(low_threshold) \
.replace(False, np.nan) \
.multiply(subsystem_fraction) \
.min(axis=1) \
.fillna(1) # use safe value of 100%
smallest_delta = (
power_subsystem.le(low_threshold)
.replace(False, np.nan)
.multiply(subsystem_fraction)
.min(axis=1)
) # use safe value of 100%
smallest_delta.loc[smallest_delta.isnull] = 1
is_downtime = system_delta > (0.75 * smallest_delta)
is_downtime[looks_online.all(axis=1)] = False

Expand Down Expand Up @@ -415,20 +417,17 @@ def _calc_loss_system(self):
all_times = self.power_system.index
masked = looks_offline[self.power_expected > 0].reindex(all_times)
# Note: in Series, (nan | True) is False, but (True | nan) is True
full_outage = (
masked.ffill().fillna(False) | masked.bfill().fillna(False)
)

full_outage = masked.ffill() | masked.bfill()
# Find expected production and associated uncertainty for each outage
diff = full_outage.astype(int).diff()
starts = all_times[diff == 1].tolist()
ends = all_times[diff.shift(-1) == -1].tolist()
steps = diff[~diff.isnull() & (diff != 0)]
if not steps.empty:
if steps[0] == -1:
if steps.iloc[0] == -1:
# data starts in an outage
starts.insert(0, all_times[0])
if steps[-1] == 1:
if steps.iloc[-1] == 1:
# data ends in an outage
ends.append(all_times[-1])

Expand Down Expand Up @@ -497,7 +496,7 @@ def _calc_loss_system(self):

# generate a best-guess timeseries loss for the full outages by
# scaling the expected power signal to match the actual
lost_power_full = pd.Series(0, index=self.loss_subsystem.index)
lost_power_full = pd.Series(0, index=self.loss_subsystem.index, dtype=float)
expected_power = self.power_expected
corrected_cumulative_energy = self.energy_cumulative.copy()
for i, row in self.outage_info.iterrows():
Expand Down

0 comments on commit 8eb38c8

Please sign in to comment.