Skip to content

Commit 421b316

Browse files
committed
Merge branch 'dev' of github.com:wind-python/windpowerlib into dev
2 parents 6a0a806 + d89d6ff commit 421b316

File tree

6 files changed

+52
-22
lines changed

6 files changed

+52
-22
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ ENV/
9696

9797
# tests
9898
.pytest_cache
99+
100+
# oedb data dump
101+
/windpowerlib/data/turbine_data_oedb.h5

doc/whatsnew/v0-1-2.txt

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
v0.1.2 ()
22
++++++++++++++++++++++++++++++
33

4-
5-
New functions
6-
#############
7-
8-
9-
10-
Testing
11-
#######
12-
4+
New features
5+
############
136

147

158
Documentation
169
#############
1710

1811

12+
Testing
13+
#######
1914

20-
API changes
21-
###########
2215

16+
Bug fixes
17+
#########
2318

2419

2520
Other changes
2621
#############
22+
* Make windpowerlib work offline: turbine data from oedb is stored in a hdf5 file for offline usage
2723
* Make :py:func:`~windpowerlib.wind_turbine.get_turbine_types` also accessible via `get_turbine_types()` --> from windpowerlib import get_turbine_types
2824

2925

3026
Contributors
3127
############
32-
* Sabine Haas
28+
* Sabine Haas
29+

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ def read(fname):
1818
'windpowerlib': [os.path.join('data', '*.csv')]},
1919
long_description=read('README.rst'),
2020
zip_safe=False,
21-
install_requires=['pandas >= 0.19.1',
22-
'requests'])
21+
install_requires=['numpy <= 1.15.4', # remove after PyTables release 3.4.5
22+
'pandas >= 0.19.1',
23+
'requests',
24+
'tables']) # PyTables needed for pandas.HDFStore

windpowerlib/turbine_cluster_modelchain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TurbineClusterModelChain(ModelChain):
2424
A :class:`~.wind_farm.WindFarm` object representing the wind farm or
2525
a :class:`~.wind_turbine_cluster.WindTurbineCluster` object
2626
representing the wind turbine cluster.
27-
wake_losses_model : string
27+
wake_losses_model : string or None
2828
Defines the method for talking wake losses within the farm into
2929
consideration. Options: None, 'power_efficiency_curve' or
3030
'constant_efficiency' or the name of a wind efficiency curve like
@@ -82,7 +82,7 @@ class TurbineClusterModelChain(ModelChain):
8282
A :class:`~.wind_farm.WindFarm` object representing the wind farm or
8383
a :class:`~.wind_turbine_cluster.WindTurbineCluster` object
8484
representing the wind turbine cluster.
85-
wake_losses_model : string
85+
wake_losses_model : string or None
8686
Defines the method for talking wake losses within the farm into
8787
consideration. Options: None, 'power_efficiency_curve' or
8888
'constant_efficiency' or the name of a wind efficiency curve like

windpowerlib/wind_farm.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ def assign_power_curve(self, wake_losses_model='power_efficiency_curve',
218218
"each wind turbine needs a power curve " +
219219
"but `power_curve` of wind turbine " +
220220
"{} is {}.".format(
221-
item['wind_turbine'].name,
221+
item['wind_turbine'].name if
222+
item['wind_turbine'].name else '',
222223
item['wind_turbine'].power_curve))
223224
# Initialize data frame for power curve values
224225
df = pd.DataFrame()
@@ -246,8 +247,8 @@ def assign_power_curve(self, wake_losses_model='power_efficiency_curve',
246247
"`efficiency` is needed if " +
247248
"`wake_losses_model´ is '{0}', but ".format(
248249
wake_losses_model) +
249-
"`efficiency` of {0} is {1}.".format(
250-
self.name, self.efficiency))
250+
"`efficiency` of wind farm {0} is {1}.".format(
251+
self.name if self.name else '', self.efficiency))
251252
# Get original power curve
252253
power_curve = pd.DataFrame(
253254
turbine_type_dict['wind_turbine'].power_curve)

windpowerlib/wind_turbine.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import logging
1313
import sys
1414
import requests
15+
import os
1516

1617

1718
class WindTurbine(object):
@@ -264,10 +265,17 @@ def isfloat(x):
264265
return df, nominal_power
265266

266267

267-
def get_turbine_data_from_oedb(turbine_type, fetch_curve):
268+
def get_turbine_data_from_oedb(turbine_type, fetch_curve, overwrite=False):
268269
r"""
269270
Fetches data for one wind turbine type from the OpenEnergy Database (oedb).
270271
272+
If turbine data exists in local repository it is loaded from this file. The
273+
file is created when turbine data was loaded from oedb in
274+
:py:func:`~.load_turbine_data_from_oedb`. Use this function with
275+
`overwrite=True` to overwrite your file with newly fetched data.
276+
Use :py:func:`~.check_local_turbine_data` to check
277+
weather your local file is up to date.
278+
271279
Parameters
272280
----------
273281
turbine_type : string
@@ -278,6 +286,9 @@ def get_turbine_data_from_oedb(turbine_type, fetch_curve):
278286
Parameter to specify whether a power or power coefficient curve
279287
should be retrieved from the provided turbine data. Valid options are
280288
'power_curve' and 'power_coefficient_curve'. Default: None.
289+
overwrite : boolean
290+
If True local file is overwritten by newly fetch data from oedb, if
291+
False turbine data is fetched from previously saved file.
281292
282293
Returns
283294
-------
@@ -288,8 +299,15 @@ def get_turbine_data_from_oedb(turbine_type, fetch_curve):
288299
power curve values in W with the corresponding wind speeds in m/s.
289300
290301
"""
291-
# Extract data
292-
turbine_data = load_turbine_data_from_oedb()
302+
# hdf5 filename
303+
filename = os.path.join(os.path.dirname(__file__), 'data',
304+
'turbine_data_oedb.h5')
305+
if os.path.isfile(filename) and not overwrite:
306+
logging.debug("Turbine data is fetched from {}".format(filename))
307+
with pd.HDFStore(filename) as hdf_store:
308+
turbine_data = hdf_store.get('turbine_data')
309+
else:
310+
turbine_data = load_turbine_data_from_oedb()
293311
turbine_data.set_index('turbine_type', inplace=True)
294312
# Set `curve` depending on `fetch_curve` to match names in oedb
295313
curve = ('cp_curve' if fetch_curve == 'power_coefficient_curve'
@@ -320,6 +338,8 @@ def load_turbine_data_from_oedb():
320338
r"""
321339
Loads turbine data from the OpenEnergy Database (oedb).
322340
341+
Turbine data is saved to `filename` for offline usage of windpowerlib.
342+
323343
Returns
324344
-------
325345
turbine_data : pd.DataFrame
@@ -341,6 +361,13 @@ def load_turbine_data_from_oedb():
341361
"Response: [{}]".format(result.status_code))
342362
# extract data to data frame
343363
turbine_data = pd.DataFrame(result.json())
364+
# store data as hdf5
365+
filename = os.path.join(os.path.dirname(__file__), 'data',
366+
'turbine_data_oedb.h5')
367+
with pd.HDFStore(filename) as hdf_store:
368+
hdf_store.put('turbine_data', turbine_data)
369+
logging.debug("Turbine data is fetched from oedb and saved "
370+
"to {}".format(filename))
344371
return turbine_data
345372

346373

0 commit comments

Comments
 (0)