diff --git a/.github/workflows/tests-coverage.yml b/.github/workflows/tests-coverage.yml index c6efca1..0c758c7 100644 --- a/.github/workflows/tests-coverage.yml +++ b/.github/workflows/tests-coverage.yml @@ -33,16 +33,16 @@ jobs: steps: - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v7 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} - name: Set up Conda if: runner.os == 'Windows' - uses: conda-incubator/setup-miniconda@v2 + uses: conda-incubator/setup-miniconda@v4 with: miniconda-version: "latest" python-version: ${{ matrix.python-version }} diff --git a/pytest.ini b/pytest.ini index 2bed0f3..70be5e2 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,3 @@ [pytest] -addopts = --doctest-modules \ No newline at end of file +addopts = --doctest-modules +testpaths = tests windpowerlib diff --git a/setup.py b/setup.py index 8672c49..61e2ef2 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,6 @@ def read(fname): "nbsphinx", "numpy", "pytest", - "pytest-notebook", "sphinx >= 1.4", "sphinx_rtd_theme", ] diff --git a/tests/test_data_handling.py b/tests/test_data_handling.py index b53d2bc..e1ee387 100644 --- a/tests/test_data_handling.py +++ b/tests/test_data_handling.py @@ -93,7 +93,7 @@ def test_store_turbine_data_from_oedb(self, caplog): for fn in os.listdir(self.orig_path): t[fn] = os.path.getmtime(os.path.join(self.orig_path, fn)) with caplog.at_level(logging.WARNING): - store_turbine_data_from_oedb() + store_turbine_data_from_oedb(threshold=1.0) for fn in os.listdir(self.orig_path): assert t[fn] < os.path.getmtime(os.path.join(self.orig_path, fn)) assert "The turbine library data contains too many faulty" not in caplog.text @@ -151,7 +151,7 @@ def test_wrong_url_load_turbine_data(self): ConnectionError, match=r"Database \(oep\) connection not successful*", ): - store_turbine_data_from_oedb("wrong_schema") + store_turbine_data_from_oedb(table="wrong_table") @pytest.mark.skip(reason="Use it to check a persistent ssl error") def test_wrong_ssl_connection(self): diff --git a/tests/test_modelchain.py b/tests/test_modelchain.py index 483f0b4..33be315 100644 --- a/tests/test_modelchain.py +++ b/tests/test_modelchain.py @@ -59,6 +59,17 @@ def setup_class(cls): ], ) + def test_get_closest_height(self): + """Test the _get_closest_height helper method.""" + test_mc = mc.ModelChain(wt.WindTurbine(**self.test_turbine)) + # Hub height is 100, so 110 is the closest height + heights = np.array([10, 80, 110, 150]) + assert test_mc._get_closest_height(heights) == 110 + + # Test when there is an exact match + heights = np.array([10, 100, 150]) + assert test_mc._get_closest_height(heights) == 100 + def test_temperature_hub(self): # Test modelchain with temperature_model='linear_gradient' test_mc = mc.ModelChain(wt.WindTurbine(**self.test_turbine)) diff --git a/windpowerlib/data.py b/windpowerlib/data.py index 3562817..d95cee6 100644 --- a/windpowerlib/data.py +++ b/windpowerlib/data.py @@ -133,7 +133,7 @@ def fetch_turbine_data_from_oedb( """ # url of OpenEnergy Platform that contains the oedb - oep_url = "https://oep.iks.cs.ovgu.de/" + oep_url = "https://openenergyplatform.org/" url = oep_url + "/api/v0/schema/{}/tables/{}/rows/?".format(schema, table) # load data diff --git a/windpowerlib/modelchain.py b/windpowerlib/modelchain.py index d9def99..2a9fc89 100644 --- a/windpowerlib/modelchain.py +++ b/windpowerlib/modelchain.py @@ -17,7 +17,7 @@ ) -class ModelChain(object): +class ModelChain: r"""Model to determine the output of a wind turbine The ModelChain class provides a standardized, high-level @@ -163,6 +163,14 @@ def __init__( self.hellman_exp = hellman_exp self.power_output = None + def _get_closest_height(self, heights): + return heights[ + min( + range(len(heights)), + key=lambda i: abs(heights[i] - self.power_plant.hub_height), + ) + ] + def temperature_hub(self, weather_df): r""" Calculates the temperature of air at hub height. @@ -200,15 +208,9 @@ def temperature_hub(self, weather_df): logging.debug( "Calculating temperature using temperature " "gradient." ) - closest_height = weather_df["temperature"].columns[ - min( - range(len(weather_df["temperature"].columns)), - key=lambda i: abs( - weather_df["temperature"].columns[i] - - self.power_plant.hub_height - ), - ) - ] + closest_height = self._get_closest_height( + weather_df["temperature"].columns + ) temperature_hub = temperature.linear_gradient( weather_df["temperature"][closest_height], closest_height, @@ -273,15 +275,9 @@ def density_hub(self, weather_df): logging.debug( "Calculating density using barometric height " "equation." ) - closest_height = weather_df["pressure"].columns[ - min( - range(len(weather_df["pressure"].columns)), - key=lambda i: abs( - weather_df["pressure"].columns[i] - - self.power_plant.hub_height - ), - ) - ] + closest_height = self._get_closest_height( + weather_df["pressure"].columns + ) density_hub = density.barometric( weather_df["pressure"][closest_height], closest_height, @@ -290,15 +286,9 @@ def density_hub(self, weather_df): ) elif self.density_model == "ideal_gas": logging.debug("Calculating density using ideal gas equation.") - closest_height = weather_df["pressure"].columns[ - min( - range(len(weather_df["pressure"].columns)), - key=lambda i: abs( - weather_df["pressure"].columns[i] - - self.power_plant.hub_height - ), - ) - ] + closest_height = self._get_closest_height( + weather_df["pressure"].columns + ) density_hub = density.ideal_gas( weather_df["pressure"][closest_height], closest_height, @@ -358,15 +348,9 @@ def wind_speed_hub(self, weather_df): logging.debug( "Calculating wind speed using logarithmic wind " "profile." ) - closest_height = weather_df["wind_speed"].columns[ - min( - range(len(weather_df["wind_speed"].columns)), - key=lambda i: abs( - weather_df["wind_speed"].columns[i] - - self.power_plant.hub_height - ), - ) - ] + closest_height = self._get_closest_height( + weather_df["wind_speed"].columns + ) wind_speed_hub = wind_speed.logarithmic_profile( weather_df["wind_speed"][closest_height], closest_height, @@ -376,15 +360,9 @@ def wind_speed_hub(self, weather_df): ) elif self.wind_speed_model == "hellman": logging.debug("Calculating wind speed using hellman equation.") - closest_height = weather_df["wind_speed"].columns[ - min( - range(len(weather_df["wind_speed"].columns)), - key=lambda i: abs( - weather_df["wind_speed"].columns[i] - - self.power_plant.hub_height - ), - ) - ] + closest_height = self._get_closest_height( + weather_df["wind_speed"].columns + ) wind_speed_hub = wind_speed.hellman( weather_df["wind_speed"][closest_height], closest_height, @@ -503,7 +481,7 @@ def run_model(self, weather_df): >>> my_weather_df = pd.DataFrame(np.random.rand(2,6), ... index=pd.date_range('1/1/2012', ... periods=2, - ... freq='H'), + ... freq='h'), ... columns=[np.array(['wind_speed', ... 'wind_speed', ... 'temperature', diff --git a/windpowerlib/tools.py b/windpowerlib/tools.py index f6e4c13..cfca550 100644 --- a/windpowerlib/tools.py +++ b/windpowerlib/tools.py @@ -69,12 +69,12 @@ def linear_interpolation_extrapolation(df, target_height): ... wind_speed_80m)), ... index=pd.date_range('1/1/2012', ... periods=2, - ... freq='H'), + ... freq='h'), ... columns=[np.array(['wind_speed', ... 'wind_speed']), ... np.array([10, 80])]) >>> value=linear_interpolation_extrapolation( - ... weather_df['wind_speed'], 100)[0] + ... weather_df['wind_speed'], 100).iloc[0] """ # find closest heights diff --git a/windpowerlib/turbine_cluster_modelchain.py b/windpowerlib/turbine_cluster_modelchain.py index 4f3258a..62d4705 100644 --- a/windpowerlib/turbine_cluster_modelchain.py +++ b/windpowerlib/turbine_cluster_modelchain.py @@ -275,7 +275,7 @@ def run_model(self, weather_df): >>> my_weather_df = pd.DataFrame(np.random.rand(2,6), ... index=pd.date_range('1/1/2012', ... periods=2, - ... freq='H'), + ... freq='h'), ... columns=[np.array(['wind_speed', ... 'wind_speed', ... 'temperature', diff --git a/windpowerlib/wind_farm.py b/windpowerlib/wind_farm.py index 7c9b8f9..047d8fb 100644 --- a/windpowerlib/wind_farm.py +++ b/windpowerlib/wind_farm.py @@ -12,7 +12,7 @@ import warnings -class WindFarm(object): +class WindFarm: r""" Defines a standard set of wind farm attributes. diff --git a/windpowerlib/wind_turbine.py b/windpowerlib/wind_turbine.py index fd068fa..31b6ccc 100644 --- a/windpowerlib/wind_turbine.py +++ b/windpowerlib/wind_turbine.py @@ -14,7 +14,7 @@ from typing import NamedTuple -class WindTurbine(object): +class WindTurbine: r""" Defines a standard set of wind turbine attributes. diff --git a/windpowerlib/wind_turbine_cluster.py b/windpowerlib/wind_turbine_cluster.py index da540ac..b03a812 100644 --- a/windpowerlib/wind_turbine_cluster.py +++ b/windpowerlib/wind_turbine_cluster.py @@ -12,7 +12,7 @@ import pandas as pd -class WindTurbineCluster(object): +class WindTurbineCluster: r""" Defines a standard set of wind turbine cluster attributes.