Skip to content

Commit

Permalink
Merge pull request #138 from WISDEM/develop
Browse files Browse the repository at this point in the history
v0.9.3: Minor Bug Fix and Formatting Updates
  • Loading branch information
RHammond2 authored Feb 15, 2024
2 parents b4eecd8 + 22cd06d commit 0bba8c6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 54 deletions.
23 changes: 12 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ repos:
name: isort
stages: [commit]

- repo: https://github.com/psf/black
rev: 23.12.0
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: black
name: black
- id: pyupgrade
args: [--py39-plus]
stages: [commit]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.8
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
types_or: [python, pyi, jupyter]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.7.1' # Use the sha / tag you want to point at
hooks:
Expand All @@ -38,13 +46,6 @@ repos:
- id: pretty-format-json
args: [--autofix]


- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.8
hooks:
- id: ruff
args: [--fix]

# - repo: local
# hooks:
# - id: pytest
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## v0.9.3 (15 February 2024)

- 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 Ruff.

## v0.9.2 (13 November 2023)

### General
Expand Down
44 changes: 19 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[metadata]
version = "attr: wombat.__version__"

[project]
name = "wombat"
dynamic = ["version"]
Expand Down Expand Up @@ -62,12 +65,12 @@ changelog = "https://github.com/WISDEM/WOMBAT/blob/main/CHANGELOG.md"
[project.optional-dependencies]
dev = [
"pre-commit>=2.20",
"black>=22.1",
"isort>=5.10",
"pytest>=7",
"pytest-cov>=4",
"mypy==0.991",
"ruff==0.0.246",
"ruff>=0.2",
"pyupgrade",
]
docs = [
"jupyter-book>=0.15",
Expand Down Expand Up @@ -161,36 +164,27 @@ length_sort = true
lines_after_imports = 2
line_length = 88


[tool.black]
target-version=["py39", "py310"]
line-length=88

include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''
[tool.numpydoc_validation]
checks = [
"all",
"ES01",
"SA01",
"EX01",
]
exclude = ["*__pycache__"]

[tool.ruff]
src = ["wombat", "tests"]
line-length = 88
target-version = "py39"
ignore-init-module-imports = true
fix = true

[tool.ruff.lint]
# See https://github.com/charliermarsh/ruff#supported-rules
# for rules included and matching to prefix.
# TODO: "FBT", "B", "PIE, "T20", "SIM", "PTH", "PD", "I", "PL"
select = ["F", "E", "W", "C4", "D", "UP"]
ignore-init-module-imports = true
select = ["F", "E", "W", "C4", "D", "UP", "NPY201"]

# D205: not using summary lines and descriptions, just descriptions
# D401: don't believe enough in imperative mode to make all the changes currently
Expand Down Expand Up @@ -226,7 +220,7 @@ exclude = [
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"setup.py" = ["D104"]
"library/__init__.py" = ["D104"]
"library/code_comparison/__init__.py" = ["D104"]
Expand Down Expand Up @@ -278,5 +272,5 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
"wombat/windfarm/__init__.py" = ["F401"]
"wombat/windfarm/system/__init__.py" = ["F401"]

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "numpy"
2 changes: 1 addition & 1 deletion wombat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from wombat.core.library import create_library_structure


__version__ = "0.9.2"
__version__ = "0.9.3"
8 changes: 6 additions & 2 deletions wombat/core/data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ def check_start_stop_dates(


def valid_hour(
instance: Any, attribute: Attribute, value: int # pylint: disable=W0613
instance: Any,
attribute: Attribute,
value: int, # pylint: disable=W0613
) -> None:
"""Validate that the input is a valid time or null value (-1).
Expand All @@ -275,7 +277,9 @@ def valid_hour(


def valid_reduction(
instance, attribute: Attribute, value: int | float # pylint: disable=W0613
instance,
attribute: Attribute,
value: int | float, # pylint: disable=W0613
) -> None:
"""Check to see if the reduction factor is between 0 and 1, inclusive.
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


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]

# 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)
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
3 changes: 2 additions & 1 deletion wombat/windfarm/windfarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ def _create_wind_farm_map(self) -> None:
downstream=graph.nodes[s_id]["connection"],
)
self.wind_farm_map = WindFarmMap(
substation_map=wind_map, export_cables=export # type: ignore
substation_map=wind_map,
export_cables=export, # type: ignore
)

def finish_setup(self) -> None:
Expand Down

0 comments on commit 0bba8c6

Please sign in to comment.