From 33a173003f5d1df56b3a7afb2285185015513af1 Mon Sep 17 00:00:00 2001 From: uvchik Date: Thu, 13 Feb 2020 17:48:10 +0100 Subject: [PATCH 01/10] Download weather file if not present --- example/modelchain_example.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/example/modelchain_example.py b/example/modelchain_example.py index acf85b8e..916ce24a 100644 --- a/example/modelchain_example.py +++ b/example/modelchain_example.py @@ -15,6 +15,7 @@ """ import os import pandas as pd +import requests try: from matplotlib import pyplot as plt @@ -65,11 +66,16 @@ def get_weather_data(filename='weather.csv', **kwargs): """ if "datapath" not in kwargs: - kwargs["datapath"] = os.path.join( - os.path.split(os.path.dirname(__file__))[0], "example" - ) + kwargs["datapath"] = os.path.dirname(__file__) + file = os.path.join(kwargs["datapath"], filename) + if not os.path.isfile(file): + logging.debug("Download weather data for example.") + req = requests.get("https://osf.io/59bqn/download") + with open(file, "wb") as fout: + fout.write(req.content) + # read csv file weather_df = pd.read_csv( file, From ca2f4277e74d8be92b66fdab534db934e676003a Mon Sep 17 00:00:00 2001 From: uvchik Date: Thu, 13 Feb 2020 17:48:40 +0100 Subject: [PATCH 02/10] Add comments to make example cleaner --- example/modelchain_example.py | 69 +++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/example/modelchain_example.py b/example/modelchain_example.py index 916ce24a..7a73a222 100644 --- a/example/modelchain_example.py +++ b/example/modelchain_example.py @@ -10,26 +10,27 @@ you need to specify your wind turbine, and in the last step call the windpowerlib functions to calculate the feed-in time series. +Install the windpowerlib and optionally matplotlib to see the plots: + + pip install windpowerlib + pip install matplotlib + +Go down to the "run_example()" function to start the example. + SPDX-FileCopyrightText: 2019 oemof developer group SPDX-License-Identifier: MIT """ import os import pandas as pd import requests +import logging +from windpowerlib import ModelChain, WindTurbine try: from matplotlib import pyplot as plt except ImportError: plt = None -from windpowerlib import ModelChain -from windpowerlib import WindTurbine - -# You can use the logging package to get logging messages from the windpowerlib -# Change the logging level if you want more or less messages -import logging -logging.getLogger().setLevel(logging.DEBUG) - def get_weather_data(filename='weather.csv', **kwargs): r""" @@ -114,18 +115,18 @@ def initialize_wind_turbines(): :class:`~.wind_turbine.WindTurbine`) """ + # ************************************************************************ + # **** Data is provided in the oedb turbine library ********************** - # specification of wind turbine where data is provided in the oedb - # turbine library enercon_e126 = { "turbine_type": "E-126/4200", # turbine type as in register "hub_height": 135, # in m } - # initialize WindTurbine object e126 = WindTurbine(**enercon_e126) - # specification of own wind turbine (Note: power values and nominal power - # have to be in Watt) + # ************************************************************************ + # **** Specification of wind turbine with your own data ****************** + # **** NOTE: power values and nominal power have to be in Watt my_turbine = { "nominal_power": 3e6, # in W "hub_height": 105, # in m @@ -139,11 +140,10 @@ def initialize_wind_turbines(): } ), # in m/s } - # initialize WindTurbine object my_turbine = WindTurbine(**my_turbine) - # specification of wind turbine where power coefficient curve and nominal - # power is provided in an own csv file + # ************************************************************************ + # **** Specification of wind turbine with data in own file *************** csv_path = os.path.join(os.path.dirname(__file__), "data") dummy_turbine = { "turbine_type": "DUMMY 1", @@ -151,7 +151,6 @@ def initialize_wind_turbines(): "rotor_diameter": 70, # in m "path": csv_path, } - # initialize WindTurbine object dummy_turbine = WindTurbine(**dummy_turbine) return my_turbine, e126, dummy_turbine @@ -183,15 +182,9 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine): """ - # power output calculation for my_turbine - # initialize ModelChain with default parameters and use run_model method - # to calculate power output - mc_my_turbine = ModelChain(my_turbine).run_model(weather) - # write power output time series to WindTurbine object - my_turbine.power_output = mc_my_turbine.power_output - - # power output calculation for e126 - # own specifications for ModelChain setup + # ************************************************************************ + # **** Data is provided in the oedb turbine library ********************** + # **** ModelChain with non-default specifications modelchain_data = { "wind_speed_model": "logarithmic", # 'logarithmic' (default), # 'hellman' or @@ -212,8 +205,16 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine): # write power output time series to WindTurbine object e126.power_output = mc_e126.power_output - # power output calculation for example_turbine - # own specification for 'power_output_model' + # ************************************************************************ + # **** Specification of wind turbine with your own data ****************** + # **** ModelChain with default parameter + mc_my_turbine = ModelChain(my_turbine).run_model(weather) + # write power output time series to WindTurbine object + my_turbine.power_output = mc_my_turbine.power_output + + # ************************************************************************ + # **** Specification of wind turbine with data in own file *************** + # **** Using "power_coefficient_curve" as "power_output_model". mc_example_turbine = ModelChain( dummy_turbine, power_output_model="power_coefficient_curve" ).run_model(weather) @@ -284,10 +285,16 @@ def run_example(): Runs the basic example. """ + # You can use the logging package to get logging messages from the + # windpowerlib. Change the logging level if you want more or less messages: + # logging.DEBUG -> many messages + # logging.INFO -> few messages + logging.getLogger().setLevel(logging.DEBUG) + weather = get_weather_data("weather.csv") - my_turbine, e126, dummy_turbine = initialize_wind_turbines() - calculate_power_output(weather, my_turbine, e126, dummy_turbine) - plot_or_print(my_turbine, e126, dummy_turbine) + my_turbine, e126 = initialize_wind_turbines() + calculate_power_output(weather, my_turbine, e126) + plot_or_print(my_turbine, e126) if __name__ == "__main__": From 777cf9798f1eaa59d5d050c8812a70a0d8dc6c24 Mon Sep 17 00:00:00 2001 From: uvchik Date: Thu, 13 Feb 2020 20:20:00 +0100 Subject: [PATCH 03/10] Move data from data dir to parent dir --- example/modelchain_example.ipynb | 2 +- example/modelchain_example.py | 3 +-- example/{data => }/power_coefficient_curves.csv | 0 example/{data => }/power_curves.csv | 0 example/{data => }/turbine_data.csv | 0 tests/data/power_coefficient_curves.csv | 3 +++ tests/data/power_curves.csv | 3 +++ tests/data/turbine_data.csv | 5 +++++ tests/test_wind_turbine.py | 2 +- windpowerlib/wind_turbine.py | 4 ++-- 10 files changed, 16 insertions(+), 6 deletions(-) rename example/{data => }/power_coefficient_curves.csv (100%) rename example/{data => }/power_curves.csv (100%) rename example/{data => }/turbine_data.csv (100%) create mode 100755 tests/data/power_coefficient_curves.csv create mode 100755 tests/data/power_curves.csv create mode 100644 tests/data/turbine_data.csv diff --git a/example/modelchain_example.ipynb b/example/modelchain_example.ipynb index f4b1f748..1b4dfa9e 100644 --- a/example/modelchain_example.ipynb +++ b/example/modelchain_example.ipynb @@ -288,7 +288,7 @@ "source": [ "# specification of wind turbine where power coefficient curve and nominal\n", "# power is provided in an own csv file\n", - "csv_path = 'data'\n", + "csv_path = ''\n", "dummy_turbine = {\n", " 'turbine_type': 'DUMMY 1', # turbine type as in file\n", " 'hub_height': 100, # in m\n", diff --git a/example/modelchain_example.py b/example/modelchain_example.py index 7a73a222..b1d68c7b 100644 --- a/example/modelchain_example.py +++ b/example/modelchain_example.py @@ -144,12 +144,11 @@ def initialize_wind_turbines(): # ************************************************************************ # **** Specification of wind turbine with data in own file *************** - csv_path = os.path.join(os.path.dirname(__file__), "data") dummy_turbine = { "turbine_type": "DUMMY 1", "hub_height": 100, # in m "rotor_diameter": 70, # in m - "path": csv_path, + "path": os.path.dirname(__file__), } dummy_turbine = WindTurbine(**dummy_turbine) diff --git a/example/data/power_coefficient_curves.csv b/example/power_coefficient_curves.csv similarity index 100% rename from example/data/power_coefficient_curves.csv rename to example/power_coefficient_curves.csv diff --git a/example/data/power_curves.csv b/example/power_curves.csv similarity index 100% rename from example/data/power_curves.csv rename to example/power_curves.csv diff --git a/example/data/turbine_data.csv b/example/turbine_data.csv similarity index 100% rename from example/data/turbine_data.csv rename to example/turbine_data.csv diff --git a/tests/data/power_coefficient_curves.csv b/tests/data/power_coefficient_curves.csv new file mode 100755 index 00000000..a3c70cc1 --- /dev/null +++ b/tests/data/power_coefficient_curves.csv @@ -0,0 +1,3 @@ +turbine_type,0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10,10.5,11,11.5,12,12.5,13,13.5,14,14.5,15,15.5,16,16.5,17,17.5,18,18.5,19,19.5,20,20.5,21,21.5,22,22.5,23,23.5,24,24.5,25,25.5,26 +DUMMY 1,0,,0,,0,,0,0,0.13,,0.38,,0.46,,0.48,,0.47,,0.44,,0.4,,0.36,,0.31,,0.26,,0.23,,0.2,,0.18,,0.14,,0.11,,0.1,,0.09,,0.07,,0.05,,0.04,,0.04,,0.03,,0 +DUMMY 2,0,,0,,0,,0.16,0.29,0.35,0.38,0.4,0.41,0.42,0.43,0.43,0.44,0.44,0.44,0.44,0.43,0.42,0.39,0.36,0.32,0.29,0.26,0.23,0.2,0.18,0.16,0.15,0.14,0.12,0.11,0.1,0.09,0.09,0.08,0.07,0.07,0.06,0.06,0.05,0.05,0.05,0.04,0.04,0.04,0.04,0.03,0.03,0,0 diff --git a/tests/data/power_curves.csv b/tests/data/power_curves.csv new file mode 100755 index 00000000..85890d50 --- /dev/null +++ b/tests/data/power_curves.csv @@ -0,0 +1,3 @@ +turbine_type,0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10,10.5,11,11.5,12,12.5,13,13.5,14,14.5,15,15.5,16,16.5,17,17.5,18,18.5,19,19.5,20,20.5,21,21.5,22,22.5,23,23.5,24,24.5,25,25.5,26 +DUMMY 3,0,0,0,0,0,0,0,18000,34000,70000,10000,150000,190000,260000,330000,420000,510000,620000,740000,880000,1020000,1180000,1330000,1420000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,1500000,0, +DUMMY 4,0,,0,,0,,0,,4000,,22000,,46000,,76000,,111000,,147000,,184000,,219000,,249000,,274000,,290000,,297000,,302000,,307000,,307000,,305000,,295000,,280000,,260000,,240000,,230000,,225000,0, diff --git a/tests/data/turbine_data.csv b/tests/data/turbine_data.csv new file mode 100644 index 00000000..0e9b9f9f --- /dev/null +++ b/tests/data/turbine_data.csv @@ -0,0 +1,5 @@ +turbine_type,nominal_power +DUMMY 1,4200000 +DUMMY 2,4200000 +DUMMY 3,1500000 +DUMMY 4,225000 diff --git a/tests/test_wind_turbine.py b/tests/test_wind_turbine.py index 4140911f..fb23f084 100644 --- a/tests/test_wind_turbine.py +++ b/tests/test_wind_turbine.py @@ -22,7 +22,7 @@ class TestWindTurbine: @classmethod def setup_class(cls): """Setup default values""" - cls.source = os.path.join(os.path.dirname(__file__), "../example/data") + cls.source = os.path.join(os.path.dirname(__file__), "data") def test_warning(self, recwarn): test_turbine_data = { diff --git a/windpowerlib/wind_turbine.py b/windpowerlib/wind_turbine.py index 6ab1c52a..0b4fb2fb 100644 --- a/windpowerlib/wind_turbine.py +++ b/windpowerlib/wind_turbine.py @@ -101,7 +101,7 @@ class WindTurbine(object): >>> print(e126.nominal_power) 4200000.0 >>> # Example with own path - >>> path=os.path.join(os.path.dirname(__file__), '../example/data') + >>> path=os.path.join(os.path.dirname(__file__), '../tests/data') >>> example_turbine={ ... 'hub_height': 100, ... 'rotor_diameter': 70, @@ -378,7 +378,7 @@ def get_turbine_data_from_file(turbine_type, path): -------- >>> from windpowerlib import wind_turbine >>> import os - >>> path=os.path.join(os.path.dirname(__file__), '../example/data', + >>> path=os.path.join(os.path.dirname(__file__), '../tests/data', ... 'power_curves.csv') >>> d3=get_turbine_data_from_file('DUMMY 3', path) >>> print(d3['value'][7]) From d643f48590a57ab21a1c801f3e8176dee2f21d17 Mon Sep 17 00:00:00 2001 From: uvchik Date: Thu, 13 Feb 2020 20:24:43 +0100 Subject: [PATCH 04/10] Fix pylint issues --- windpowerlib/__init__.py | 12 ++++++------ windpowerlib/power_curves.py | 2 +- windpowerlib/wind_farm.py | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/windpowerlib/__init__.py b/windpowerlib/__init__.py index a206ff5a..445ddaae 100644 --- a/windpowerlib/__init__.py +++ b/windpowerlib/__init__.py @@ -2,9 +2,9 @@ __license__ = "MIT" __version__ = "0.2.1dev" -from windpowerlib.wind_turbine import WindTurbine -from windpowerlib.wind_farm import WindFarm -from windpowerlib.wind_turbine_cluster import WindTurbineCluster -from windpowerlib.modelchain import ModelChain -from windpowerlib.turbine_cluster_modelchain import TurbineClusterModelChain -from windpowerlib.wind_turbine import get_turbine_types +from .wind_turbine import WindTurbine +from .wind_farm import WindFarm +from .wind_turbine_cluster import WindTurbineCluster +from .modelchain import ModelChain +from .turbine_cluster_modelchain import TurbineClusterModelChain +from .wind_turbine import get_turbine_types diff --git a/windpowerlib/power_curves.py b/windpowerlib/power_curves.py index ef9eb138..c9f36728 100644 --- a/windpowerlib/power_curves.py +++ b/windpowerlib/power_curves.py @@ -159,7 +159,7 @@ def smooth_power_curve(power_curve_wind_speeds, power_curve_values, # Get standard deviation for Gauss function standard_deviation = ( (power_curve_wind_speed * normalized_standard_deviation + 0.6) - if standard_deviation_method is "Staffell_Pfenninger" + if standard_deviation_method == "Staffell_Pfenninger" else power_curve_wind_speed * normalized_standard_deviation ) # Get the smoothed value of the power output diff --git a/windpowerlib/wind_farm.py b/windpowerlib/wind_farm.py index e7deb42d..af31ca43 100644 --- a/windpowerlib/wind_farm.py +++ b/windpowerlib/wind_farm.py @@ -9,7 +9,6 @@ from windpowerlib import tools, power_curves, WindTurbine import numpy as np import pandas as pd -import logging import warnings From c058db50ff489fb49b16b055649b2d8a3b0e6d4c Mon Sep 17 00:00:00 2001 From: uvchik Date: Thu, 13 Feb 2020 20:29:39 +0100 Subject: [PATCH 05/10] Revert import changes --- windpowerlib/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/windpowerlib/__init__.py b/windpowerlib/__init__.py index 445ddaae..a206ff5a 100644 --- a/windpowerlib/__init__.py +++ b/windpowerlib/__init__.py @@ -2,9 +2,9 @@ __license__ = "MIT" __version__ = "0.2.1dev" -from .wind_turbine import WindTurbine -from .wind_farm import WindFarm -from .wind_turbine_cluster import WindTurbineCluster -from .modelchain import ModelChain -from .turbine_cluster_modelchain import TurbineClusterModelChain -from .wind_turbine import get_turbine_types +from windpowerlib.wind_turbine import WindTurbine +from windpowerlib.wind_farm import WindFarm +from windpowerlib.wind_turbine_cluster import WindTurbineCluster +from windpowerlib.modelchain import ModelChain +from windpowerlib.turbine_cluster_modelchain import TurbineClusterModelChain +from windpowerlib.wind_turbine import get_turbine_types From e19d52b5d662a02c6aba6f264c8020b247498da5 Mon Sep 17 00:00:00 2001 From: uvchik Date: Thu, 13 Feb 2020 20:40:26 +0100 Subject: [PATCH 06/10] Add badge --- README.rst | 3 +++ doc/getting_started.rst | 3 +++ 2 files changed, 6 insertions(+) diff --git a/README.rst b/README.rst index 37f0bb75..11ae0ca0 100644 --- a/README.rst +++ b/README.rst @@ -8,6 +8,9 @@ :target: https://mybinder.org/v2/gh/wind-python/windpowerlib/dev?filepath=example .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/psf/black + +.. image:: https://img.shields.io/lgtm/grade/python/g/wind-python/windpowerlib.svg?logo=lgtm&logoWidth=18 + :target: https://lgtm.com/projects/g/wind-python/windpowerlib/context:python Introduction ============= diff --git a/doc/getting_started.rst b/doc/getting_started.rst index c4373330..c7a40c1d 100644 --- a/doc/getting_started.rst +++ b/doc/getting_started.rst @@ -13,6 +13,9 @@ Getting started .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/psf/black +.. image:: https://img.shields.io/lgtm/grade/python/g/wind-python/windpowerlib.svg?logo=lgtm&logoWidth=18 + :target: https://lgtm.com/projects/g/wind-python/windpowerlib/context:python + Introduction ============= From d5614d5586566ee78413b8f00ef4f890cdc33b96 Mon Sep 17 00:00:00 2001 From: uvchik Date: Thu, 13 Feb 2020 20:43:33 +0100 Subject: [PATCH 07/10] Fixe example --- example/modelchain_example.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/modelchain_example.py b/example/modelchain_example.py index b1d68c7b..e35684d0 100644 --- a/example/modelchain_example.py +++ b/example/modelchain_example.py @@ -291,9 +291,9 @@ def run_example(): logging.getLogger().setLevel(logging.DEBUG) weather = get_weather_data("weather.csv") - my_turbine, e126 = initialize_wind_turbines() - calculate_power_output(weather, my_turbine, e126) - plot_or_print(my_turbine, e126) + my_turbine, e126, dummy_turbine = initialize_wind_turbines() + calculate_power_output(weather, my_turbine, e126, dummy_turbine) + plot_or_print(my_turbine, e126, dummy_turbine) if __name__ == "__main__": From 239ed62c8bb1dcb975ea59fd1cd983f321abd3a5 Mon Sep 17 00:00:00 2001 From: uvchik Date: Mon, 24 Feb 2020 16:20:08 +0100 Subject: [PATCH 08/10] Add create power curve function --- windpowerlib/wind_turbine.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/windpowerlib/wind_turbine.py b/windpowerlib/wind_turbine.py index 0b4fb2fb..3b43aca5 100644 --- a/windpowerlib/wind_turbine.py +++ b/windpowerlib/wind_turbine.py @@ -176,7 +176,7 @@ def __init__( self.rotor_diameter = float(turbine_data["rotor_diameter"]) if self.rotor_diameter: - if self.hub_height <= 0.5*self.rotor_diameter: + if self.hub_height <= 0.5 * self.rotor_diameter: msg = "1/2rotor_diameter cannot be greater than hub_height" raise ValueError(msg) @@ -409,6 +409,29 @@ def get_turbine_data_from_file(turbine_type, path): return wpp_df +def create_power_curve(wind_speed, power): + """ + A list, numpy.array, pandas.Series or other iterables can be passed to + define the wind speed and the power output. Make sure that the order is + not mutable because, values from both parameters will be used as value + pairs. + + Parameters + ---------- + wind_speed : iterable + A series of wind speed values in meter per second [m/s]. + power : iterable + A series of power values in Watt [W]. + + Returns + ------- + pandas.DataFrame + """ + return pd.DataFrame( + data={"value": power, "wind_speed": wind_speed, } + ) + + def load_turbine_data_from_oedb(schema="supply", table="wind_turbine_library"): r""" Loads turbine library from the OpenEnergy database (oedb). From 085f90b6e17b33dc84526600e4dea49d01660dad Mon Sep 17 00:00:00 2001 From: uvchik Date: Mon, 24 Feb 2020 16:20:51 +0100 Subject: [PATCH 09/10] Use another variant of my_turbine instead of dummy_turbine --- example/modelchain_example.py | 101 +++++++++++++++++++++------------- windpowerlib/__init__.py | 4 +- 2 files changed, 65 insertions(+), 40 deletions(-) diff --git a/example/modelchain_example.py b/example/modelchain_example.py index e35684d0..028f94fe 100644 --- a/example/modelchain_example.py +++ b/example/modelchain_example.py @@ -24,7 +24,7 @@ import pandas as pd import requests import logging -from windpowerlib import ModelChain, WindTurbine +from windpowerlib import ModelChain, WindTurbine, create_power_curve try: from matplotlib import pyplot as plt @@ -32,7 +32,7 @@ plt = None -def get_weather_data(filename='weather.csv', **kwargs): +def get_weather_data(filename="weather.csv", **kwargs): r""" Imports weather data from a file. @@ -127,6 +127,7 @@ def initialize_wind_turbines(): # ************************************************************************ # **** Specification of wind turbine with your own data ****************** # **** NOTE: power values and nominal power have to be in Watt + my_turbine = { "nominal_power": 3e6, # in W "hub_height": 105, # in m @@ -144,18 +145,31 @@ def initialize_wind_turbines(): # ************************************************************************ # **** Specification of wind turbine with data in own file *************** - dummy_turbine = { - "turbine_type": "DUMMY 1", - "hub_height": 100, # in m - "rotor_diameter": 70, # in m - "path": os.path.dirname(__file__), + + # Read your turbine data from your data file using functions like + # pandas.read_csv(). + # >>> import pandas as pd + # >>> my_data = pd.read_csv("path/to/my/data/file") + # >>> my_power = my_data["my_power"] + # >>> my_wind_speed = my_data["my_wind_speed"] + + my_power = pd.Series( + [0.0, 39000.0, 270000.0, 2250000.0, 4500000.0, 4500000.0]) + my_wind_speed = (0.0, 3.0, 5.0, 10.0, 15.0, 25.0) + + my_turbine2 = { + "nominal_power": 6e6, # in W + "hub_height": 115, # in m + "power_curve": create_power_curve( + wind_speed=my_wind_speed, power=my_power + ), } - dummy_turbine = WindTurbine(**dummy_turbine) + my_turbine2 = WindTurbine(**my_turbine2) - return my_turbine, e126, dummy_turbine + return my_turbine, e126, my_turbine2 -def calculate_power_output(weather, my_turbine, e126, dummy_turbine): +def calculate_power_output(weather, my_turbine, e126, my_turbine2): r""" Calculates power output of wind turbines using the :class:`~.modelchain.ModelChain`. @@ -176,7 +190,7 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine): e126 : :class:`~.wind_turbine.WindTurbine` WindTurbine object with power curve from the OpenEnergy Database turbine library. - dummy_turbine : :class:`~.wind_turbine.WindTurbine` + my_turbine2 : :class:`~.wind_turbine.WindTurbine` WindTurbine object with power coefficient curve from example file. """ @@ -215,14 +229,14 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine): # **** Specification of wind turbine with data in own file *************** # **** Using "power_coefficient_curve" as "power_output_model". mc_example_turbine = ModelChain( - dummy_turbine, power_output_model="power_coefficient_curve" + my_turbine2, power_output_model="power_curve" ).run_model(weather) - dummy_turbine.power_output = mc_example_turbine.power_output + my_turbine2.power_output = mc_example_turbine.power_output return -def plot_or_print(my_turbine, e126, dummy_turbine): +def plot_or_print(my_turbine, e126, my_turbine2): r""" Plots or prints power output and power (coefficient) curves. @@ -233,44 +247,55 @@ def plot_or_print(my_turbine, e126, dummy_turbine): e126 : :class:`~.wind_turbine.WindTurbine` WindTurbine object with power curve from the OpenEnergy Database turbine library. - dummy_turbine : :class:`~.wind_turbine.WindTurbine` + my_turbine2 : :class:`~.wind_turbine.WindTurbine` WindTurbine object with power coefficient curve from example file. """ # plot or print turbine power output if plt: - e126.power_output.plot(legend=True, label='Enercon E126') - my_turbine.power_output.plot(legend=True, label='myTurbine') - dummy_turbine.power_output.plot(legend=True, label='dummyTurbine') - plt.xlabel('Time') - plt.ylabel('Power in W') + e126.power_output.plot(legend=True, label="Enercon E126") + my_turbine.power_output.plot(legend=True, label="myTurbine") + my_turbine2.power_output.plot(legend=True, label="dummyTurbine") + plt.xlabel("Time") + plt.ylabel("Power in W") plt.show() else: print(e126.power_output) print(my_turbine.power_output) - print(dummy_turbine.power_output) + print(my_turbine2.power_output) # plot or print power curve if plt: if e126.power_curve is not False: - e126.power_curve.plot(x='wind_speed', y='value', style='*', - title='Enercon E126 power curve') - plt.xlabel('Wind speed in m/s') - plt.ylabel('Power in W') + e126.power_curve.plot( + x="wind_speed", + y="value", + style="*", + title="Enercon E126 power curve", + ) + plt.xlabel("Wind speed in m/s") + plt.ylabel("Power in W") plt.show() if my_turbine.power_curve is not False: - my_turbine.power_curve.plot(x='wind_speed', y='value', style='*', - title='myTurbine power curve') - plt.xlabel('Wind speed in m/s') - plt.ylabel('Power in W') + my_turbine.power_curve.plot( + x="wind_speed", + y="value", + style="*", + title="myTurbine power curve", + ) + plt.xlabel("Wind speed in m/s") + plt.ylabel("Power in W") plt.show() - if dummy_turbine.power_coefficient_curve is not False: - dummy_turbine.power_coefficient_curve.plot( - x='wind_speed', y='value', style='*', - title='dummyTurbine power coefficient curve') - plt.xlabel('Wind speed in m/s') - plt.ylabel('Power coefficient') + if my_turbine2.power_curve is not False: + my_turbine2.power_curve.plot( + x="wind_speed", + y="value", + style="*", + title="myTurbine2 power curve", + ) + plt.xlabel("Wind speed in m/s") + plt.ylabel("Power in W") plt.show() else: if e126.power_coefficient_curve is not False: @@ -291,9 +316,9 @@ def run_example(): logging.getLogger().setLevel(logging.DEBUG) weather = get_weather_data("weather.csv") - my_turbine, e126, dummy_turbine = initialize_wind_turbines() - calculate_power_output(weather, my_turbine, e126, dummy_turbine) - plot_or_print(my_turbine, e126, dummy_turbine) + my_turbine, e126, my_turbine2 = initialize_wind_turbines() + calculate_power_output(weather, my_turbine, e126, my_turbine2) + plot_or_print(my_turbine, e126, my_turbine2) if __name__ == "__main__": diff --git a/windpowerlib/__init__.py b/windpowerlib/__init__.py index a206ff5a..eaba869f 100644 --- a/windpowerlib/__init__.py +++ b/windpowerlib/__init__.py @@ -2,9 +2,9 @@ __license__ = "MIT" __version__ = "0.2.1dev" -from windpowerlib.wind_turbine import WindTurbine +from windpowerlib.wind_turbine import (WindTurbine, get_turbine_types, + create_power_curve) from windpowerlib.wind_farm import WindFarm from windpowerlib.wind_turbine_cluster import WindTurbineCluster from windpowerlib.modelchain import ModelChain from windpowerlib.turbine_cluster_modelchain import TurbineClusterModelChain -from windpowerlib.wind_turbine import get_turbine_types From a8b43f4dc7ddc3a30284a46e4fc7cc13fb159a2c Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 24 Feb 2020 15:21:08 +0000 Subject: [PATCH 10/10] Fixing style errors. --- example/modelchain_example.py | 3 ++- windpowerlib/__init__.py | 7 +++++-- windpowerlib/wind_turbine.py | 4 +--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/example/modelchain_example.py b/example/modelchain_example.py index 028f94fe..1f9aaf62 100644 --- a/example/modelchain_example.py +++ b/example/modelchain_example.py @@ -154,7 +154,8 @@ def initialize_wind_turbines(): # >>> my_wind_speed = my_data["my_wind_speed"] my_power = pd.Series( - [0.0, 39000.0, 270000.0, 2250000.0, 4500000.0, 4500000.0]) + [0.0, 39000.0, 270000.0, 2250000.0, 4500000.0, 4500000.0] + ) my_wind_speed = (0.0, 3.0, 5.0, 10.0, 15.0, 25.0) my_turbine2 = { diff --git a/windpowerlib/__init__.py b/windpowerlib/__init__.py index eaba869f..51c03086 100644 --- a/windpowerlib/__init__.py +++ b/windpowerlib/__init__.py @@ -2,8 +2,11 @@ __license__ = "MIT" __version__ = "0.2.1dev" -from windpowerlib.wind_turbine import (WindTurbine, get_turbine_types, - create_power_curve) +from windpowerlib.wind_turbine import ( + WindTurbine, + get_turbine_types, + create_power_curve, +) from windpowerlib.wind_farm import WindFarm from windpowerlib.wind_turbine_cluster import WindTurbineCluster from windpowerlib.modelchain import ModelChain diff --git a/windpowerlib/wind_turbine.py b/windpowerlib/wind_turbine.py index 3b43aca5..0e213342 100644 --- a/windpowerlib/wind_turbine.py +++ b/windpowerlib/wind_turbine.py @@ -427,9 +427,7 @@ def create_power_curve(wind_speed, power): ------- pandas.DataFrame """ - return pd.DataFrame( - data={"value": power, "wind_speed": wind_speed, } - ) + return pd.DataFrame(data={"value": power, "wind_speed": wind_speed,}) def load_turbine_data_from_oedb(schema="supply", table="wind_turbine_library"):