Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:wind-python/windpowerlib into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
birgits committed Apr 16, 2019
2 parents 6a0a806 + d89d6ff commit 421b316
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ ENV/

# tests
.pytest_cache

# oedb data dump
/windpowerlib/data/turbine_data_oedb.h5
21 changes: 9 additions & 12 deletions doc/whatsnew/v0-1-2.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
v0.1.2 ()
++++++++++++++++++++++++++++++


New functions
#############



Testing
#######

New features
############


Documentation
#############


Testing
#######

API changes
###########

Bug fixes
#########


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


Contributors
############
* Sabine Haas
* Sabine Haas

6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ def read(fname):
'windpowerlib': [os.path.join('data', '*.csv')]},
long_description=read('README.rst'),
zip_safe=False,
install_requires=['pandas >= 0.19.1',
'requests'])
install_requires=['numpy <= 1.15.4', # remove after PyTables release 3.4.5
'pandas >= 0.19.1',
'requests',
'tables']) # PyTables needed for pandas.HDFStore
4 changes: 2 additions & 2 deletions windpowerlib/turbine_cluster_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TurbineClusterModelChain(ModelChain):
A :class:`~.wind_farm.WindFarm` object representing the wind farm or
a :class:`~.wind_turbine_cluster.WindTurbineCluster` object
representing the wind turbine cluster.
wake_losses_model : string
wake_losses_model : string or None
Defines the method for talking wake losses within the farm into
consideration. Options: None, 'power_efficiency_curve' or
'constant_efficiency' or the name of a wind efficiency curve like
Expand Down Expand Up @@ -82,7 +82,7 @@ class TurbineClusterModelChain(ModelChain):
A :class:`~.wind_farm.WindFarm` object representing the wind farm or
a :class:`~.wind_turbine_cluster.WindTurbineCluster` object
representing the wind turbine cluster.
wake_losses_model : string
wake_losses_model : string or None
Defines the method for talking wake losses within the farm into
consideration. Options: None, 'power_efficiency_curve' or
'constant_efficiency' or the name of a wind efficiency curve like
Expand Down
7 changes: 4 additions & 3 deletions windpowerlib/wind_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ def assign_power_curve(self, wake_losses_model='power_efficiency_curve',
"each wind turbine needs a power curve " +
"but `power_curve` of wind turbine " +
"{} is {}.".format(
item['wind_turbine'].name,
item['wind_turbine'].name if
item['wind_turbine'].name else '',
item['wind_turbine'].power_curve))
# Initialize data frame for power curve values
df = pd.DataFrame()
Expand Down Expand Up @@ -246,8 +247,8 @@ def assign_power_curve(self, wake_losses_model='power_efficiency_curve',
"`efficiency` is needed if " +
"`wake_losses_model´ is '{0}', but ".format(
wake_losses_model) +
"`efficiency` of {0} is {1}.".format(
self.name, self.efficiency))
"`efficiency` of wind farm {0} is {1}.".format(
self.name if self.name else '', self.efficiency))
# Get original power curve
power_curve = pd.DataFrame(
turbine_type_dict['wind_turbine'].power_curve)
Expand Down
33 changes: 30 additions & 3 deletions windpowerlib/wind_turbine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import logging
import sys
import requests
import os


class WindTurbine(object):
Expand Down Expand Up @@ -264,10 +265,17 @@ def isfloat(x):
return df, nominal_power


def get_turbine_data_from_oedb(turbine_type, fetch_curve):
def get_turbine_data_from_oedb(turbine_type, fetch_curve, overwrite=False):
r"""
Fetches data for one wind turbine type from the OpenEnergy Database (oedb).
If turbine data exists in local repository it is loaded from this file. The
file is created when turbine data was loaded from oedb in
:py:func:`~.load_turbine_data_from_oedb`. Use this function with
`overwrite=True` to overwrite your file with newly fetched data.
Use :py:func:`~.check_local_turbine_data` to check
weather your local file is up to date.
Parameters
----------
turbine_type : string
Expand All @@ -278,6 +286,9 @@ def get_turbine_data_from_oedb(turbine_type, fetch_curve):
Parameter to specify whether a power or power coefficient curve
should be retrieved from the provided turbine data. Valid options are
'power_curve' and 'power_coefficient_curve'. Default: None.
overwrite : boolean
If True local file is overwritten by newly fetch data from oedb, if
False turbine data is fetched from previously saved file.
Returns
-------
Expand All @@ -288,8 +299,15 @@ def get_turbine_data_from_oedb(turbine_type, fetch_curve):
power curve values in W with the corresponding wind speeds in m/s.
"""
# Extract data
turbine_data = load_turbine_data_from_oedb()
# hdf5 filename
filename = os.path.join(os.path.dirname(__file__), 'data',
'turbine_data_oedb.h5')
if os.path.isfile(filename) and not overwrite:
logging.debug("Turbine data is fetched from {}".format(filename))
with pd.HDFStore(filename) as hdf_store:
turbine_data = hdf_store.get('turbine_data')
else:
turbine_data = load_turbine_data_from_oedb()
turbine_data.set_index('turbine_type', inplace=True)
# Set `curve` depending on `fetch_curve` to match names in oedb
curve = ('cp_curve' if fetch_curve == 'power_coefficient_curve'
Expand Down Expand Up @@ -320,6 +338,8 @@ def load_turbine_data_from_oedb():
r"""
Loads turbine data from the OpenEnergy Database (oedb).
Turbine data is saved to `filename` for offline usage of windpowerlib.
Returns
-------
turbine_data : pd.DataFrame
Expand All @@ -341,6 +361,13 @@ def load_turbine_data_from_oedb():
"Response: [{}]".format(result.status_code))
# extract data to data frame
turbine_data = pd.DataFrame(result.json())
# store data as hdf5
filename = os.path.join(os.path.dirname(__file__), 'data',
'turbine_data_oedb.h5')
with pd.HDFStore(filename) as hdf_store:
hdf_store.put('turbine_data', turbine_data)
logging.debug("Turbine data is fetched from oedb and saved "
"to {}".format(filename))
return turbine_data


Expand Down

0 comments on commit 421b316

Please sign in to comment.