Skip to content

Commit

Permalink
Bug Fix: Restore time-based-availability (#137)
Browse files Browse the repository at this point in the history
* reinstate the old time-based availability method

* update changelog
  • Loading branch information
RHammond2 authored Feb 15, 2024
1 parent 540d3bb commit 17714af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
## Unreleased (TBD)

- Reinstate the original time-based availability methodology, which is based on all
turbines, not the wind farm total.
- Replace the `black` formatter with `ruff`.
- Adopt `pyupgrade` to ensure modern Python language usage.
- Add the NumPy 2.0 integration tool to Ruf.
- Add the NumPy 2.0 integration tool to Ruff.

## v0.9.2 (13 November 2023)

Expand Down
19 changes: 5 additions & 14 deletions wombat/core/post_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,17 @@ def _check_frequency(frequency: str, which: str = "all") -> str:
def _calculate_time_availability(
availability: pd.DataFrame,
by_turbine: bool = False,
turbine_id: list[str] | None = None,
) -> float | np.ndarray:
"""Calculates the availability ratio of the whole timeseries or the whole
timeseries, by turbine.
Parameters
----------
availability : pd.DataFrame
Timeseries array of operating ratios.
Timeseries array of operating ratios for all turbines.
by_turbine : bool, optional
If True, calculates the availability rate of each column, otherwise across the
whole array, by default False.
turbine_id : list[str], optional
A list of turbine IDs that is required if :py:attr:`by_turbine` is ``True``, by
default None.
Returns
-------
Expand All @@ -77,8 +73,8 @@ def _calculate_time_availability(
"""
availability = availability > 0
if by_turbine:
return availability[turbine_id].values.sum(axis=0) / availability.shape[0]
return availability.windfarm.values.sum() / availability.windfarm.size
return availability.values.sum(axis=0) / availability.shape[0]
return availability.values.sum() / availability.size

Check warning on line 77 in wombat/core/post_processor.py

View check run for this annotation

Codecov / codecov/patch

wombat/core/post_processor.py#L76-L77

Added lines #L76 - L77 were not covered by tests


class Metrics:
Expand Down Expand Up @@ -375,15 +371,13 @@ def time_based_availability(self, frequency: str, by: str) -> pd.DataFrame:
for sub, val in self.substation_turbine_map.items():
turbine_operations[val["turbines"]] *= self.operations[[sub]].values

hourly = turbine_operations.loc[:, ["windfarm"] + self.turbine_id]
hourly = turbine_operations.loc[:, self.turbine_id]

Check warning on line 374 in wombat/core/post_processor.py

View check run for this annotation

Codecov / codecov/patch

wombat/core/post_processor.py#L374

Added line #L374 was not covered by tests

# TODO: The below should be better summarized as:
# (availability > 0).groupby().sum() / groupby().count()

if frequency == "project":
availability = _calculate_time_availability(
hourly, by_turbine=by_turbine, turbine_id=self.turbine_id
)
availability = _calculate_time_availability(hourly, by_turbine=by_turbine)

Check warning on line 380 in wombat/core/post_processor.py

View check run for this annotation

Codecov / codecov/patch

wombat/core/post_processor.py#L380

Added line #L380 was not covered by tests
if not by_turbine:
return pd.DataFrame([availability], columns=["windfarm"])

Expand All @@ -401,7 +395,6 @@ def time_based_availability(self, frequency: str, by: str) -> pd.DataFrame:
_calculate_time_availability(
hourly[date_time.year == year],
by_turbine=by_turbine,
turbine_id=self.turbine_id,
)
for year in counts.index
]
Expand All @@ -414,7 +407,6 @@ def time_based_availability(self, frequency: str, by: str) -> pd.DataFrame:
_calculate_time_availability(
hourly[date_time.month == month],
by_turbine=by_turbine,
turbine_id=self.turbine_id,
)
for month in counts.index
]
Expand All @@ -427,7 +419,6 @@ def time_based_availability(self, frequency: str, by: str) -> pd.DataFrame:
_calculate_time_availability(
hourly[(date_time.year == year) & (date_time.month == month)],
by_turbine=by_turbine,
turbine_id=self.turbine_id,
)
for year, month in counts.index
]
Expand Down

0 comments on commit 17714af

Please sign in to comment.