Skip to content

Commit

Permalink
Small PEP8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
birgits committed Jul 7, 2017
1 parent da425e9 commit cbe4439
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 71 deletions.
6 changes: 4 additions & 2 deletions windpowerlib/density.py
Expand Up @@ -31,7 +31,8 @@ def barometric(pressure, pressure_height, hub_height, temperature_hub_height):
-------
pandas.Series or numpy.array
Density of air at hub height in kg/m³.
Returns a pd.Series if one of the input parameters is a pd.Series.
Returns a pandas.Series if one of the input parameters is a
pandas.Series.
Notes
-----
Expand Down Expand Up @@ -88,7 +89,8 @@ def ideal_gas(pressure, pressure_height, hub_height, temperature_hub_height):
-------
pandas.Series or numpy.array
Density of air at hub height in kg/m³.
Returns a pd.Series if one of the input parameters is a pd.Series.
Returns a pandas.Series if one of the input parameters is a
pandas.Series.
Notes
-----
Expand Down
127 changes: 63 additions & 64 deletions windpowerlib/modelchain.py
Expand Up @@ -20,9 +20,6 @@ class ModelChain(object):
wind_turbine : WindTurbine
A :class:`~.wind_turbine.WindTurbine` object representing the wind
turbine.
obstacle_height : float
Height of obstacles in the surrounding area of the wind turbine in m.
Set `obstacle_height` to zero for wide spread obstacles. Default: 0.
wind_speed_model : string
Parameter to define which model to use to calculate the wind speed at
hub height. Valid options are 'logarithmic', 'hellman' and
Expand All @@ -42,6 +39,9 @@ class ModelChain(object):
density_correction : boolean
If the parameter is True the density corrected power curve is used for
the calculation of the turbine power output. Default: False.
obstacle_height : float
Height of obstacles in the surrounding area of the wind turbine in m.
Set `obstacle_height` to zero for wide spread obstacles. Default: 0.
hellman_exp : float
The Hellman exponent, which combines the increase in wind speed due to
stability of atmospheric conditions and surface roughness into one
Expand All @@ -52,9 +52,6 @@ class ModelChain(object):
wind_turbine : WindTurbine
A :class:`~.wind_turbine.WindTurbine` object representing the wind
turbine.
obstacle_height : float
Height of obstacles in the surrounding area of the wind turbine in m.
Set `obstacle_height` to zero for wide spread obstacles. Default: 0.
wind_speed_model : string
Parameter to define which model to use to calculate the wind speed at
hub height. Valid options are 'logarithmic', 'hellman' and
Expand All @@ -78,6 +75,9 @@ class ModelChain(object):
The Hellman exponent, which combines the increase in wind speed due to
stability of atmospheric conditions and surface roughness into one
constant. Default: None.
obstacle_height : float
Height of obstacles in the surrounding area of the wind turbine in m.
Set `obstacle_height` to zero for wide spread obstacles. Default: 0.
power_output : pandas.Series
Electrical power output of the wind turbine in W.
Expand All @@ -98,12 +98,12 @@ class ModelChain(object):
"""

def __init__(self, wind_turbine,
obstacle_height=0,
wind_speed_model='logarithmic',
temperature_model='linear_gradient',
density_model='barometric',
power_output_model='power_curve',
density_correction=False,
obstacle_height=0,
hellman_exp=None):

self.wind_turbine = wind_turbine
Expand Down Expand Up @@ -145,29 +145,28 @@ def temperature_hub(self, weather_df):
temperature(s) closest to the hub height are used.
"""
try:
if self.wind_turbine.hub_height in weather_df['temperature']:
temperature_hub = weather_df['temperature'][
self.wind_turbine.hub_height]
except:
if self.temperature_model == 'linear_gradient':
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.wind_turbine.hub_height))]
temperature_hub = temperature.linear_gradient(
weather_df['temperature'][closest_height], closest_height,
self.wind_turbine.hub_height)
elif self.temperature_model == 'interpolation_extrapolation':
logging.debug('Calculating temperature using linear inter- or '
'extrapolation.')
temperature_hub = tools.linear_interpolation_extrapolation(
weather_df['temperature'], self.wind_turbine.hub_height)
else:
raise ValueError("'{0}' is an invalid value. ".format(
self.temperature_model) + "`temperature_model` must be "
"'linear_gradient' or 'interpolation_extrapolation'.")
elif self.temperature_model == 'linear_gradient':
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.wind_turbine.hub_height))]
temperature_hub = temperature.linear_gradient(
weather_df['temperature'][closest_height], closest_height,
self.wind_turbine.hub_height)
elif self.temperature_model == 'interpolation_extrapolation':
logging.debug('Calculating temperature using linear inter- or '
'extrapolation.')
temperature_hub = tools.linear_interpolation_extrapolation(
weather_df['temperature'], self.wind_turbine.hub_height)
else:
raise ValueError("'{0}' is an invalid value. ".format(
self.temperature_model) + "`temperature_model` must be "
"'linear_gradient' or 'interpolation_extrapolation'.")
return temperature_hub

def density_hub(self, weather_df):
Expand Down Expand Up @@ -269,43 +268,42 @@ def wind_speed_hub(self, weather_df):
wind speed(s) closest to the hub height are used.
"""
try:
if self.wind_turbine.hub_height in weather_df['wind_speed']:
wind_speed_hub = weather_df['wind_speed'][
self.wind_turbine.hub_height]
except:
if self.wind_speed_model == 'logarithmic':
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.wind_turbine.hub_height))]
wind_speed_hub = wind_speed.logarithmic_profile(
weather_df['wind_speed'][closest_height], closest_height,
self.wind_turbine.hub_height,
weather_df['roughness_length'].ix[:, 0],
self.obstacle_height)
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.wind_turbine.hub_height))]
wind_speed_hub = wind_speed.hellman(
weather_df['wind_speed'][closest_height], closest_height,
self.wind_turbine.hub_height,
weather_df['roughness_length'].ix[:, 0],
self.hellman_exp)
elif self.wind_speed_model == 'interpolation_extrapolation':
logging.debug('Calculating wind speed using linear inter- or '
'extrapolation.')
wind_speed_hub = tools.linear_interpolation_extrapolation(
weather_df['wind_speed'], self.wind_turbine.hub_height)
else:
raise ValueError("'{0}' is an invalid value. ".format(
self.wind_speed_model) + "`wind_speed_model` must be "
"'logarithmic', 'hellman' or "
"'interpolation_extrapolation'.")
elif self.wind_speed_model == 'logarithmic':
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.wind_turbine.hub_height))]
wind_speed_hub = wind_speed.logarithmic_profile(
weather_df['wind_speed'][closest_height], closest_height,
self.wind_turbine.hub_height,
weather_df['roughness_length'].ix[:, 0],
self.obstacle_height)
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.wind_turbine.hub_height))]
wind_speed_hub = wind_speed.hellman(
weather_df['wind_speed'][closest_height], closest_height,
self.wind_turbine.hub_height,
weather_df['roughness_length'].ix[:, 0],
self.hellman_exp)
elif self.wind_speed_model == 'interpolation_extrapolation':
logging.debug('Calculating wind speed using linear inter- or '
'extrapolation.')
wind_speed_hub = tools.linear_interpolation_extrapolation(
weather_df['wind_speed'], self.wind_turbine.hub_height)
else:
raise ValueError("'{0}' is an invalid value. ".format(
self.wind_speed_model) + "`wind_speed_model` must be "
"'logarithmic', 'hellman' or "
"'interpolation_extrapolation'.")
return wind_speed_hub

def turbine_power_output(self, wind_speed_hub, density_hub):
Expand Down Expand Up @@ -347,7 +345,8 @@ def turbine_power_output(self, wind_speed_hub, density_hub):
'curve.')
return (power_output.power_coefficient_curve(
wind_speed_hub,
self.wind_turbine.power_coefficient_curve['wind_speed'],
self.wind_turbine.power_coefficient_curve[
'wind_speed'],
self.wind_turbine.power_coefficient_curve['values'],
self.wind_turbine.rotor_diameter, density_hub,
self.density_correction))
Expand Down
5 changes: 2 additions & 3 deletions windpowerlib/tools.py
Expand Up @@ -41,7 +41,7 @@ def linear_interpolation_extrapolation(df, target_height):
For the inter- and extrapolation the following equation is used:
.. math:: f(x) = (f(x_2) - f(x_1)) / (x_2 - x_1) \cdot (x - x_1) + f(x_1)
.. math:: f(x) = \frac{(f(x_2) - f(x_1))}{(x_2 - x_1)} \cdot (x - x_1) + f(x_1)
Examples
---------
Expand All @@ -68,5 +68,4 @@ def linear_interpolation_extrapolation(df, target_height):
key=lambda i: abs(df.columns[i] - target_height))]
return ((df[heights_sorted[1]] - df[heights_sorted[0]]) /
(heights_sorted[1] - heights_sorted[0]) *
(target_height - heights_sorted[0]) +
df[heights_sorted[0]])
(target_height - heights_sorted[0]) + df[heights_sorted[0]])
2 changes: 1 addition & 1 deletion windpowerlib/wind_speed.py
Expand Up @@ -12,7 +12,7 @@


def logarithmic_profile(wind_speed, wind_speed_height, hub_height,
roughness_length, obstacle_height=0):
roughness_length, obstacle_height=0.0):
r"""
Calculates the wind speed at hub height using a logarithmic wind profile.
Expand Down
2 changes: 1 addition & 1 deletion windpowerlib/wind_turbine.py
Expand Up @@ -250,4 +250,4 @@ def get_turbine_types(print_out=True, **kwargs):
pd.set_option('display.max_rows', len(df))
print(df[['turbine_id', 'p_nom']])
pd.reset_option('display.max_rows')
return df[['turbine_id', 'p_nom']]
return df[['turbine_id', 'p_nom']]

0 comments on commit cbe4439

Please sign in to comment.