Skip to content

Commit

Permalink
Merge 2156caa into 3e58a6a
Browse files Browse the repository at this point in the history
  • Loading branch information
uvchik committed Aug 27, 2019
2 parents 3e58a6a + 2156caa commit c0a4392
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 38 deletions.
9 changes: 5 additions & 4 deletions tests/test_wind_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ def test_initialization_dataframe(self):

def test_initialization_1(self):
"""test catching error when wind_turbine_fleet not provided as list"""
msg = 'Wind turbine fleet not provided properly.'
msg = 'Wind turbine must be provided as WindTurbine object'
with pytest.raises(ValueError, match=msg):
WindFarm(wind_turbine_fleet=[{'wind_turbine': 'turbine',
'number_of_turbines': 2}, 'dummy'])
WindFarm(wind_turbine_fleet={'wind_turbine': 'turbine',
'number_of_turbines': 2},
name='dummy')

def test_initialization_2(self):
"""test catching error when WindTurbine in wind_turbine_fleet
Expand All @@ -71,7 +72,7 @@ def test_initialization_3(self):
WindTurbine(**self.test_turbine_2)],
'number_of_turbines': [3, 2]})
msg = 'Missing wind_turbine key/column in wind_turbine_fleet'
with pytest.raises(ValueError, match=msg):
with pytest.raises(KeyError, match=msg):
WindFarm(wind_turbine_fleet=wind_turbine_fleet)

def test_initialization_4(self, recwarn):
Expand Down
32 changes: 30 additions & 2 deletions tests/test_wind_turbine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

class TestWindTurbine:

@classmethod
def setup_class(cls):
"""Setup default values"""
cls.source = os.path.join(os.path.dirname(__file__), '../example/data')

def test_warning(self, recwarn):
source = os.path.join(os.path.dirname(__file__), '../example/data')
test_turbine_data = {'hub_height': 100,
'rotor_diameter': 80,
'turbine_type': 'turbine_not_in_file',
'path': source}
'path': self.source}
assert(WindTurbine(**test_turbine_data).power_curve is None)
assert recwarn.pop(WindpowerlibUserWarning)

Expand Down Expand Up @@ -50,3 +54,27 @@ def test_wrong_url_load_turbine_data(self):
@pytest.mark.filterwarnings("ignore:The WindTurbine")
def test_string_representation_of_wind_turbine(self):
assert "Wind turbine: ['hub height=120 m'" in repr(WindTurbine(120))

def test_to_group_method(self):
example_turbine = {
'hub_height': 100,
'rotor_diameter': 70,
'turbine_type': 'DUMMY 3',
'path': self.source}
e_t_1 = WindTurbine(**example_turbine)
assert(isinstance(e_t_1.to_group(5), dict))
assert(e_t_1.to_group(5)['number_of_turbines'] == 5)
assert(e_t_1.to_group(number_turbines=5)['number_of_turbines'] == 5)
assert(e_t_1.to_group(total_capacity=3e6)['number_of_turbines'] == 2.0)

def test_wrongly_defined_to_group_method(self):
example_turbine = {
'hub_height': 100,
'rotor_diameter': 70,
'turbine_type': 'DUMMY 3',
'path': self.source}
e_t_1 = WindTurbine(**example_turbine)
with pytest.raises(ValueError,
match="The 'number' and the 'total_capacity"
" parameter are mutually exclusive."):
e_t_1.to_group(5, 3000)
30 changes: 12 additions & 18 deletions windpowerlib/wind_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ class WindFarm(object):
>>> example_farm = wind_farm.WindFarm(**example_farm_data)
>>> print(example_farm.nominal_power)
31200000.0
>>> # turbine fleet as list of WindTurbine using the 'to_group' method.
>>> wind_turbine_fleet = [e126.to_group(number_turbines=5),
... e126.to_group(),
... v90.to_group(total_capacity=3 * 2e6)]
>>> example_farm = wind_farm.WindFarm(wind_turbine_fleet)
>>> print(example_farm.nominal_power)
31200000.0
"""

def __init__(self, wind_turbine_fleet, efficiency=None, name='', **kwargs):
Expand All @@ -120,10 +126,7 @@ def check_and_complete_wind_turbine_fleet(self):
"""
# convert list to dataframe if necessary
if isinstance(self.wind_turbine_fleet, list):
try:
self.wind_turbine_fleet = pd.DataFrame(self.wind_turbine_fleet)
except:
raise ValueError("Wind turbine fleet not provided properly.")
self.wind_turbine_fleet = pd.DataFrame(self.wind_turbine_fleet)

# check wind turbines
try:
Expand All @@ -133,8 +136,8 @@ def check_and_complete_wind_turbine_fleet(self):
'Wind turbine must be provided as WindTurbine object '
'but was provided as {}.'.format(type(turbine)))
except KeyError:
raise ValueError('Missing wind_turbine key/column in '
'wind_turbine_fleet parameter.')
raise KeyError('Missing wind_turbine key/column in '
'wind_turbine_fleet parameter.')

# add columns for number of turbines and total capacity if they don't
# yet exist
Expand All @@ -159,7 +162,7 @@ def check_and_complete_wind_turbine_fleet(self):
else:
self.wind_turbine_fleet.loc[ix, 'number_of_turbines'] = \
number_of_turbines
except:
except TypeError:
raise ValueError(msg.format(row['wind_turbine']))

# calculate total capacity if necessary and check that total capacity
Expand All @@ -170,7 +173,7 @@ def check_and_complete_wind_turbine_fleet(self):
self.wind_turbine_fleet.loc[ix, 'total_capacity'] = \
row['number_of_turbines'] * \
row['wind_turbine'].nominal_power
except:
except TypeError:
raise ValueError(
'Total capacity of turbines of type {turbine} cannot '
'be deduced. Please check if the nominal power of the '
Expand Down Expand Up @@ -205,11 +208,6 @@ def nominal_power(self):
See :attr:`~.wind_farm.WindFarm.nominal_power` for further information.
Parameters
-----------
nominal_power : float
Nominal power of the wind farm in W.
Returns
-------
float
Expand Down Expand Up @@ -308,10 +306,6 @@ def assign_power_curve(self, wake_losses_model='wind_farm_efficiency',
Turbulence intensity at hub height of the wind farm for power curve
smoothing with 'turbulence_intensity' method. Can be calculated
from `roughness_length` instead. Default: None.
roughness_length : float (optional)
Roughness length. If `standard_deviation_method` is
'turbulence_intensity' and `turbulence_intensity` is not given
the turbulence intensity is calculated via the roughness length.
Returns
-------
Expand Down
31 changes: 30 additions & 1 deletion windpowerlib/wind_turbine.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ class WindTurbine(object):
18000.0
>>> print(e_t_1.nominal_power)
1500000.0
>>> print(e_t_1.to_group(5)['number_of_turbines'])
5
>>> print(e_t_1.to_group()['number_of_turbines'])
1
>>> print(e_t_1.to_group(number_turbines=7)['number_of_turbines'])
7
>>> print(e_t_1.to_group(total_capacity=4500000)['number_of_turbines'])
3.0
"""

def __init__(self, hub_height, nominal_power=None, path='oedb',
Expand Down Expand Up @@ -198,6 +205,28 @@ def __repr__(self):

return turbine_repr

def to_group(self, number_turbines=None, total_capacity=None):
"""
Parameters
----------
number_turbines : float
Number of turbines of the defined type.
total_capacity : float
Total capacity of the group of wind turbines of the same type.
Returns
-------
"""
if number_turbines is not None and total_capacity is not None:
raise ValueError("The 'number' and the 'total_capacity parameter "
"are mutually exclusive. Use just one of them.")
elif total_capacity is not None:
number_turbines = total_capacity / self.nominal_power
elif number_turbines is None:
number_turbines = 1
return {'wind_turbine': self, 'number_of_turbines': number_turbines}


def get_turbine_data_from_file(turbine_type, path):
r"""
Expand Down
16 changes: 3 additions & 13 deletions windpowerlib/wind_turbine_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import numpy as np
import pandas as pd
import warnings


class WindTurbineCluster(object):
Expand Down Expand Up @@ -55,13 +54,13 @@ def __init__(self, wind_farms, name='', **kwargs):

def __repr__(self):
if self.name is not '':
repr = 'Wind turbine cluster: {name}'.format(name=self.name)
wf_repr = 'Wind turbine cluster: {name}'.format(name=self.name)
else:
info = []
for wind_farm in self.wind_farms:
info.append(wind_farm)
repr = r'Wind turbine cluster with: {info}'.format(info=info)
return repr
wf_repr = r'Wind turbine cluster with: {info}'.format(info=info)
return wf_repr

@property
def nominal_power(self):
Expand All @@ -71,11 +70,6 @@ def nominal_power(self):
See :attr:`~.wind_turbine_cluster.WindTurbineCluster.nominal_power`
for further information.
Parameters
-----------
nominal_power : float
Nominal power of the wind turbine cluster in w.
Returns
-------
float
Expand Down Expand Up @@ -189,10 +183,6 @@ def assign_power_curve(self, wake_losses_model='wind_farm_efficiency',
wind turbine cluster for power curve smoothing with
'turbulence_intensity' method. Can be calculated from
`roughness_length` instead. Default: None.
roughness_length : float (optional)
Roughness length. If `standard_deviation_method` is
'turbulence_intensity' and `turbulence_intensity` is not given
the turbulence intensity is calculated via the roughness length.
Returns
-------
Expand Down

0 comments on commit c0a4392

Please sign in to comment.