Skip to content

Commit

Permalink
Merge 5f291d9 into dd3cd3a
Browse files Browse the repository at this point in the history
  • Loading branch information
SabineHaas committed Jan 14, 2019
2 parents dd3cd3a + 5f291d9 commit 5c9e917
Show file tree
Hide file tree
Showing 19 changed files with 595 additions and 537 deletions.
134 changes: 101 additions & 33 deletions doc/modelchain_example_notebook.ipynb

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions doc/turbine_cluster_modelchain_example_notebook.ipynb
Expand Up @@ -51,7 +51,20 @@
"height 10 80 2 10 0 \n",
"2010-01-01 00:00:00+01:00 5.32697 7.80697 267.60 267.57 98405.7\n",
"2010-01-01 01:00:00+01:00 5.46199 7.86199 267.60 267.55 98382.7\n",
"2010-01-01 02:00:00+01:00 5.67899 8.59899 267.61 267.54 98362.9\n",
"2010-01-01 02:00:00+01:00 5.67899 8.59899 267.61 267.54 98362.9\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:root:Data base connection successful.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"nominal power of my_turbine: 3000000.0\n"
]
Expand All @@ -63,7 +76,7 @@
"print(weather[['wind_speed', 'temperature', 'pressure']][0:3])\n",
"\n",
"# Initialize wind turbines\n",
"my_turbine, e126 = mc_e.initialize_wind_turbines()\n",
"my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()\n",
"print()\n",
"print('nominal power of my_turbine: {}'.format(my_turbine.nominal_power))"
]
Expand Down
1 change: 1 addition & 0 deletions doc/whatsnew/v0-1-0.txt
Expand Up @@ -17,6 +17,7 @@ New functions
* logarithmic interpolation/extrapolation for wind speed time series
* gauss distribution
* estimation of turbulence intensity by roughness length
* retrieve power curves from Open Energy Database


Testing
Expand Down
134 changes: 101 additions & 33 deletions example/modelchain_example.ipynb

Large diffs are not rendered by default.

70 changes: 48 additions & 22 deletions example/modelchain_example.py
Expand Up @@ -84,14 +84,13 @@ def initialize_wind_turbines():
r"""
Initializes two :class:`~.wind_turbine.WindTurbine` objects.
Function shows two ways to initialize a WindTurbine object. You can either
specify your own turbine, as done below for 'myTurbine', or fetch power
and/or power coefficient curve data from data files provided by the
windpowerlib, as done for the 'enerconE126'.
Execute ``windpowerlib.wind_turbine.get_turbine_types()`` or
``windpowerlib.wind_turbine.get_turbine_types(
filename='power_coefficient_curves.csv')`` to get a list of all wind
turbines for which power and power coefficient curves respectively are
Function shows three ways to initialize a WindTurbine object. You can
either specify your own turbine, as done below for 'myTurbine', or fetch
power and/or power coefficient curve data from the Open Energy Database
(oedb), as done for the 'enerconE126', or provide your turbine data in csv
files as done for 'dummyTurbine' with an example file.
Execute ``windpowerlib.wind_turbine.get_turbine_types()`` to get a list of
all wind turbines for which power and power coefficient curves are
provided.
Returns
Expand All @@ -100,8 +99,8 @@ def initialize_wind_turbines():
"""

# specification of own wind turbine (Note: power coefficient values and
# nominal power have to be in Watt)
# specification of own wind turbine (Note: power values and nominal power
# have to be in Watt)
myTurbine = {
'name': 'myTurbine',
'nominal_power': 3e6, # in W
Expand All @@ -115,30 +114,45 @@ def initialize_wind_turbines():
# initialize WindTurbine object
my_turbine = WindTurbine(**myTurbine)

# specification of wind turbine where power curve is provided
# specification of wind turbine where power curve is provided in the oedb
# if you want to use the power coefficient curve change the value of
# 'fetch_curve' to 'power_coefficient_curve'
enerconE126 = {
'name': 'ENERCON E 126 7500', # turbine name as in register
'name': 'E-126/4200', # turbine type as in register #
'hub_height': 135, # in m
'rotor_diameter': 127, # in m
'fetch_curve': 'power_curve' # fetch power curve
'fetch_curve': 'power_curve', # fetch power curve #
'data_source': 'oedb' # data source oedb or name of csv file
}
# initialize WindTurbine object
e126 = WindTurbine(**enerconE126)

return my_turbine, e126
# specification of wind turbine where power coefficient curve is provided
# by a csv file
dummyTurbine = {
'name': 'DUMMY 1', # turbine type as in file #
'hub_height': 100, # in m
'rotor_diameter': 70, # in m
'fetch_curve': 'power_coefficient_curve', # fetch cp curve #
'data_source': 'example_power_coefficient_curves.csv' # data source
}
# initialize WindTurbine object
dummy_turbine = WindTurbine(**dummyTurbine)

return my_turbine, e126, dummy_turbine


def calculate_power_output(weather, my_turbine, e126):
def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
r"""
Calculates power output of wind turbines using the
:class:`~.modelchain.ModelChain`.
The :class:`~.modelchain.ModelChain` is a class that provides all necessary
steps to calculate the power output of a wind turbine. You can either use
the default methods for the calculation steps, as done for 'my_turbine',
or choose different methods, as done for the 'e126'.
or choose different methods, as done for the 'e126'. Of course, you can
also use the default methods while only changing one or two of them, as
done for 'dummy_turbine'.
Parameters
----------
Expand All @@ -147,8 +161,9 @@ def calculate_power_output(weather, my_turbine, e126):
my_turbine : WindTurbine
WindTurbine object with self provided power curve.
e126 : WindTurbine
WindTurbine object with power curve from data file provided by the
windpowerlib.
WindTurbine object with power curve from the Open Energy Database.
dummy_turbine : WindTurbine
WindTurbine object with power coefficient curve from example file.
"""

Expand Down Expand Up @@ -180,10 +195,17 @@ def calculate_power_output(weather, my_turbine, e126):
# 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'
mc_example_turbine = ModelChain(
dummy_turbine,
power_output_model='power_coefficient_curve').run_model(weather)
dummy_turbine.power_output = mc_example_turbine.power_output

return


def plot_or_print(my_turbine, e126):
def plot_or_print(my_turbine, e126, dummy_turbine):
r"""
Plots or prints power output and power (coefficient) curves.
Expand All @@ -194,17 +216,21 @@ def plot_or_print(my_turbine, e126):
e126 : WindTurbine
WindTurbine object with power curve from data file provided by the
windpowerlib.
dummy_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.show()
else:
print(e126.power_output)
print(my_turbine.power_output)
print(dummy_turbine.power_output)

# plot or print power (coefficient) curve
if plt:
Expand Down Expand Up @@ -239,9 +265,9 @@ def run_example():
"""
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__":
Expand Down
12 changes: 6 additions & 6 deletions example/test_examples.py
Expand Up @@ -14,27 +14,27 @@ class TestExamples:
def test_modelchain_example_flh(self):
# tests full load hours
weather = mc_e.get_weather_data('weather.csv')
my_turbine, e126 = mc_e.initialize_wind_turbines()
mc_e.calculate_power_output(weather, my_turbine, e126)
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
mc_e.calculate_power_output(weather, my_turbine, e126, dummy_turbine)

assert_allclose(1766.6870, (e126.power_output.sum() /
assert_allclose(2764.194772, (e126.power_output.sum() /
e126.nominal_power), 0.01)
assert_allclose(1882.7567, (my_turbine.power_output.sum() /
my_turbine.nominal_power), 0.01)

def test_turbine_cluster_modelchain_example_flh(self):
# tests full load hours
weather = mc_e.get_weather_data('weather.csv')
my_turbine, e126 = mc_e.initialize_wind_turbines()
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
example_farm, example_farm_2 = tc_mc_e.initialize_wind_farms(
my_turbine, e126)
example_cluster = tc_mc_e.initialize_wind_turbine_cluster(
example_farm, example_farm_2)
tc_mc_e.calculate_power_output(weather, example_farm, example_cluster)
assert_allclose(1586.23527, (example_farm.power_output.sum() /
assert_allclose(1956.164053, (example_farm.power_output.sum() /
example_farm.installed_power), 0.01)
example_cluster.installed_power = example_cluster.get_installed_power()
assert_allclose(1813.66122, (example_cluster.power_output.sum() /
assert_allclose(2156.794154, (example_cluster.power_output.sum() /
example_cluster.installed_power), 0.01)

def _notebook_run(self, path):
Expand Down
17 changes: 15 additions & 2 deletions example/turbine_cluster_modelchain_example.ipynb
Expand Up @@ -51,7 +51,20 @@
"height 10 80 2 10 0 \n",
"2010-01-01 00:00:00+01:00 5.32697 7.80697 267.60 267.57 98405.7\n",
"2010-01-01 01:00:00+01:00 5.46199 7.86199 267.60 267.55 98382.7\n",
"2010-01-01 02:00:00+01:00 5.67899 8.59899 267.61 267.54 98362.9\n",
"2010-01-01 02:00:00+01:00 5.67899 8.59899 267.61 267.54 98362.9\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:root:Data base connection successful.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"nominal power of my_turbine: 3000000.0\n"
]
Expand All @@ -63,7 +76,7 @@
"print(weather[['wind_speed', 'temperature', 'pressure']][0:3])\n",
"\n",
"# Initialize wind turbines\n",
"my_turbine, e126 = mc_e.initialize_wind_turbines()\n",
"my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()\n",
"print()\n",
"print('nominal power of my_turbine: {}'.format(my_turbine.nominal_power))"
]
Expand Down
2 changes: 1 addition & 1 deletion example/turbine_cluster_modelchain_example.py
Expand Up @@ -212,7 +212,7 @@ def run_example():
"""
weather = mc_e.get_weather_data('weather.csv')
my_turbine, e126 = mc_e.initialize_wind_turbines()
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
example_farm, example_farm_2 = initialize_wind_farms(my_turbine, e126)
example_cluster = initialize_wind_turbine_cluster(example_farm,
example_farm_2)
Expand Down
17 changes: 10 additions & 7 deletions tests/test_modelchain.py
Expand Up @@ -13,7 +13,7 @@ class TestModelChain:
def setup_class(self):
self.test_turbine = {'hub_height': 100,
'rotor_diameter': 80,
'name': 'ENERCON E 126 7500',
'name': 'E-126/4200',
'fetch_curve': 'power_curve'}

def test_temperature_hub(self):
Expand Down Expand Up @@ -185,11 +185,12 @@ def test_run_model(self):

test_turbine = {'hub_height': 100,
'rotor_diameter': 80,
'name': 'ENERCON E 126 7500',
'name': 'E-126/4200',
'fetch_curve': 'power_curve'}

# Test with default parameters of modelchain (power curve)
power_output_exp = pd.Series(data=[1731887.39768, 3820152.27489],
power_output_exp = pd.Series(data=[1637405.4840444783,
3154438.3894902095],
name='feedin_power_plant')
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine))
test_mc.run_model(weather_df)
Expand All @@ -199,15 +200,17 @@ def test_run_model(self):
test_modelchain = {'wind_speed_model': 'hellman',
'power_output_model': 'power_curve',
'density_correction': True}
power_output_exp = pd.Series(data=[1433937.37959, 3285183.55084],
power_output_exp = pd.Series(data=[1366958.544547462,
2823402.837201821],
name='feedin_power_plant')
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine),
**test_modelchain)
test_mc.run_model(weather_df)
assert_series_equal(test_mc.power_output, power_output_exp)

# Test with power coefficient curve and hellman
power_output_exp = pd.Series(data=[559060.36156, 1251143.98621],
power_output_exp = pd.Series(data=[534137.5112701517,
1103611.1736067757],
name='feedin_power_plant')
test_turbine['fetch_curve'] = 'power_coefficient_curve'
test_modelchain = {'wind_speed_model': 'hellman',
Expand Down Expand Up @@ -252,7 +255,7 @@ def test_run_model(self):
with pytest.raises(TypeError):
test_turbine = {'hub_height': 100,
'rotor_diameter': 80,
'name': 'ENERCON E 126 7500',
'name': 'E-126/4200',
'fetch_curve': 'power_curve'}
test_modelchain = {'power_output_model': 'power_coefficient_curve',
'density_correction': True}
Expand All @@ -262,7 +265,7 @@ def test_run_model(self):
with pytest.raises(TypeError):
test_turbine = {'hub_height': 100,
'rotor_diameter': 80,
'name': 'ENERCON E 126 7500',
'name': 'E-126/4200',
'fetch_curve': 'power_coefficient_curve'}
test_modelchain = {'power_output_model': 'power_curve',
'density_corr': True}
Expand Down

0 comments on commit 5c9e917

Please sign in to comment.