Skip to content

Commit ffc395b

Browse files
authored
Merge pull request #53 from wind-python/api_changes_deprecation_warnings
Deprecation warnings for future API changes
2 parents 8eacb7f + d46642e commit ffc395b

File tree

8 files changed

+142
-28
lines changed

8 files changed

+142
-28
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ pip-log.txt
3535
pip-delete-this-directory.txt
3636

3737
# Doc
38-
doc/temp/
38+
doc/temp/*
39+
!doc/temp/windpowerlib.wind_farm.WindFarm.rst
40+
!doc/temp/windpowerlib.wind_turbine_cluster.WindTurbineCluster.rst
3941
.doctrees
4042
.buildinfo
4143

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ matrix:
1414

1515
install:
1616
- pip install .
17-
- pip install coveralls sphinx nbformat pytest-cov jupyter
17+
- pip install coveralls sphinx sphinx_rtd_theme nbformat pytest-cov jupyter
1818

1919
# command to run tests
2020
script:

doc/conf.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,23 @@
3535
# ones.
3636
extensions = [
3737
'sphinx.ext.autodoc',
38+
'sphinx.ext.intersphinx',
39+
'sphinx.ext.extlinks', # enables external links with a key
3840
'sphinx.ext.viewcode',
3941
'sphinx.ext.imgmath',
4042
'sphinx.ext.napoleon',
4143
'sphinx.ext.autosummary',
4244
'nbsphinx'
43-
4445
]
4546

47+
autodoc_member_order = 'bysource'
48+
49+
extlinks = {'pandas':('http://pandas.pydata.org/pandas-docs/stable/reference/%s.html',
50+
'pandas.')
51+
}
52+
# Example configuration for intersphinx: refer to the Python standard library.
53+
intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
54+
4655
#
4756
autoclass_content = 'both'
4857

@@ -117,11 +126,9 @@
117126
# -- Options for HTML output ----------------------------------------------
118127
# The theme to use for HTML and HTML Help pages. See the documentation for
119128
# a list of builtin themes.
120-
on_rtd = os.environ.get('READTHEDOCS') == 'True'
121-
if on_rtd:
122-
html_theme = 'default'
123-
else:
124-
html_theme = 'bizstyle'
129+
import sphinx_rtd_theme
130+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
131+
html_theme = 'sphinx_rtd_theme'
125132

126133
# Theme options are theme-specific and customize the look and feel of a theme
127134
# further. For a list of options available for each theme, see the
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
windpowerlib.wind\_farm.WindFarm
2+
======================================
3+
4+
.. currentmodule:: windpowerlib.wind_farm
5+
6+
.. autoclass:: WindFarm
7+
:members:
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
windpowerlib.wind\_turbine\_cluster.WindTurbineCluster
2+
======================================================
3+
4+
.. currentmodule:: windpowerlib.wind_turbine_cluster
5+
6+
.. autoclass:: WindTurbineCluster
7+
:members:
8+

example/test_examples.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ def test_turbine_cluster_modelchain_example_flh(self):
3232
example_farm, example_farm_2)
3333
tc_mc_e.calculate_power_output(weather, example_farm, example_cluster)
3434
assert_allclose(1956.164053, (example_farm.power_output.sum() /
35-
example_farm.installed_power), 0.01)
36-
example_cluster.installed_power = example_cluster.get_installed_power()
35+
example_farm.nominal_power), 0.01)
3736
assert_allclose(2156.794154, (example_cluster.power_output.sum() /
38-
example_cluster.installed_power), 0.01)
37+
example_cluster.nominal_power), 0.01)
3938

4039
def _notebook_run(self, path):
4140
"""

windpowerlib/wind_farm.py

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from windpowerlib import tools, power_curves
1212
import numpy as np
1313
import pandas as pd
14+
import warnings
1415

1516

1617
class WindFarm(object):
@@ -54,11 +55,15 @@ class WindFarm(object):
5455
dimensionless wind farm efficiency. Default: None.
5556
hub_height : float
5657
The calculated mean hub height of the wind farm.
57-
installed_power : float
58-
The calculated installed power of the wind farm.
5958
power_curve : pandas.DataFrame or None
6059
The calculated power curve of the wind farm.
6160
power_output : pandas.Series
61+
nominal_power : float
62+
The nominal power is the sum of the nominal power of all turbines in
63+
the wind farm in W.
64+
installed_power : float
65+
Installed nominal power of the wind farm in W. Deprecated! Use
66+
:attr:`~.wind_farm.WindFarm.nominal_power` instead.
6267
The calculated power output of the wind farm.
6368
6469
Examples
@@ -77,8 +82,7 @@ class WindFarm(object):
7782
... 'wind_turbine_fleet': [{'wind_turbine': e126,
7883
... 'number_of_turbines': 6}]}
7984
>>> example_farm = wind_farm.WindFarm(**example_farm_data)
80-
>>> example_farm.installed_power = example_farm.get_installed_power()
81-
>>> print(example_farm.installed_power)
85+
>>> print(example_farm.nominal_power)
8286
25200000.0
8387
8488
"""
@@ -91,10 +95,52 @@ def __init__(self, name, wind_turbine_fleet, coordinates=None,
9195
self.efficiency = efficiency
9296

9397
self.hub_height = None
94-
self.installed_power = None
98+
self._nominal_power = None
99+
self._installed_power = None
95100
self.power_curve = None
96101
self.power_output = None
97102

103+
@property
104+
def installed_power(self):
105+
r"""
106+
The installed nominal power of the wind farm. (Deprecated!)
107+
108+
"""
109+
warnings.warn(
110+
'installed_power is deprecated, use nominal_power instead.',
111+
FutureWarning)
112+
return self.nominal_power
113+
114+
@installed_power.setter
115+
def installed_power(self, installed_power):
116+
self._installed_power = installed_power
117+
118+
@property
119+
def nominal_power(self):
120+
r"""
121+
The nominal power of the wind farm.
122+
123+
See :attr:`~.wind_farm.WindFarm.nominal_power` for further information.
124+
125+
Parameters
126+
-----------
127+
nominal_power : float
128+
Nominal power of the wind farm in W.
129+
130+
Returns
131+
-------
132+
float
133+
Nominal power of the wind farm in W.
134+
135+
"""
136+
if not self._nominal_power:
137+
self.nominal_power = self.get_installed_power()
138+
return self._nominal_power
139+
140+
@nominal_power.setter
141+
def nominal_power(self, nominal_power):
142+
self._nominal_power = nominal_power
143+
98144
def mean_hub_height(self):
99145
r"""
100146
Calculates the mean hub height of the wind farm.
@@ -139,17 +185,13 @@ def mean_hub_height(self):
139185

140186
def get_installed_power(self):
141187
r"""
142-
Calculates the installed power of the wind farm.
143-
144-
The installed power of wind farms is necessary when a
145-
:class:`~.wind_turbine_cluster.WindTurbineCluster` object is used and
146-
it's power weighed mean hub height is calculated with
147-
:py:func:`~.wind_turbine_cluster.WindTurbineCluster.mean_hub_height`.
188+
Calculates :py:attr:`~nominal_power` of the wind farm.
148189
149190
Returns
150191
-------
151192
float
152-
Installed power of the wind farm.
193+
Nominal power of the wind farm in W. See :py:attr:`~nominal_power`
194+
for further information.
153195
154196
"""
155197
return sum(

windpowerlib/wind_turbine_cluster.py

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import numpy as np
1515
import pandas as pd
16+
import warnings
1617

1718

1819
class WindTurbineCluster(object):
@@ -40,6 +41,9 @@ class WindTurbineCluster(object):
4041
weather data. Default: None.
4142
hub_height : float
4243
The calculated average hub height of the wind turbine cluster.
44+
nominal_power : float
45+
The nominal power is the sum of the nominal power of all turbines in
46+
the wind turbine cluster in W.
4347
installed_power : float
4448
The calculated installed power of the wind turbine cluster.
4549
power_curve : pandas.DataFrame or None
@@ -55,10 +59,53 @@ def __init__(self, name, wind_farms, coordinates=None, **kwargs):
5559
self.coordinates = coordinates
5660

5761
self.hub_height = None
58-
self.installed_power = None
62+
self._nominal_power = None
63+
self._installed_power = None
5964
self.power_curve = None
6065
self.power_output = None
6166

67+
@property
68+
def installed_power(self):
69+
r"""
70+
The installed nominal power of the wind turbine cluster. (Deprecated!)
71+
72+
"""
73+
warnings.warn(
74+
'installed_power is deprecated, use nominal_power instead.',
75+
FutureWarning)
76+
return self.nominal_power
77+
78+
@installed_power.setter
79+
def installed_power(self, installed_power):
80+
self._installed_power = installed_power
81+
82+
@property
83+
def nominal_power(self):
84+
r"""
85+
The nominal power of the wind turbine cluster.
86+
87+
See :attr:`~.wind_turbine_cluster.WindTurbineCluster.nominal_power`
88+
for further information.
89+
90+
Parameters
91+
-----------
92+
nominal_power : float
93+
Nominal power of the wind turbine cluster in w.
94+
95+
Returns
96+
-------
97+
float
98+
Nominal power of the wind turbine cluster in w.
99+
100+
"""
101+
if not self._nominal_power:
102+
self.nominal_power = self.get_installed_power()
103+
return self._nominal_power
104+
105+
@nominal_power.setter
106+
def nominal_power(self, nominal_power):
107+
self._nominal_power = nominal_power
108+
62109
def mean_hub_height(self):
63110
r"""
64111
Calculates the mean hub height of the wind turbine cluster.
@@ -99,17 +146,18 @@ def mean_hub_height(self):
99146

100147
def get_installed_power(self):
101148
r"""
102-
Calculates the installed power of a wind turbine cluster.
149+
Calculates the :py:attr:`~nominal_power` of a wind turbine cluster.
103150
104151
Returns
105152
-------
106153
float
107-
Installed power of the wind turbine cluster.
154+
Nominal power of the wind farm in W. See :py:attr:`~nominal_power`
155+
for further information.
108156
109157
"""
110158
for wind_farm in self.wind_farms:
111-
wind_farm.installed_power = wind_farm.get_installed_power()
112-
return sum(wind_farm.installed_power for wind_farm in self.wind_farms)
159+
wind_farm.nominal_power = wind_farm.get_installed_power()
160+
return sum(wind_farm.nominal_power for wind_farm in self.wind_farms)
113161

114162
def assign_power_curve(self, wake_losses_model='power_efficiency_curve',
115163
smoothing=False, block_width=0.5,

0 commit comments

Comments
 (0)