Skip to content

Commit 36f82c2

Browse files
committed
Add function for reading turbine data from oedb
1 parent 0f9132a commit 36f82c2

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

windpowerlib/wind_turbine.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
import os
1515
import numpy as np
1616

17+
try:
18+
import requests as rq
19+
except ImportError:
20+
rq = None
1721

1822
class WindTurbine(object):
1923
r"""
@@ -250,7 +254,46 @@ def read_turbine_data(source='oedb', **kwargs):
250254
return df
251255

252256

253-
def get_turbine_types(print_out=True, **kwargs):
257+
def load_turbine_data_from_oedb():
258+
r"""
259+
260+
261+
Returns
262+
-------
263+
turbine_data : pd.DataFrame
264+
Contains turbine data of different turbine types like 'manufacturer',
265+
nominal power ('installed_capacity_kw')
266+
267+
"""
268+
if rq:
269+
# url of Open Energy Platform that contains the oedb
270+
oep_url = 'http://oep.iks.cs.ovgu.de/'
271+
# location of data
272+
schema = 'model_draft'
273+
table = 'openfred_windpower_powercurve'
274+
# column = 'column=id&column=version'
275+
# orderby = 'order_by=version'
276+
277+
# load data
278+
result = rq.get(oep_url + '/api/v0/schema/' + schema +
279+
'/tables/' + table + '/rows/?', )
280+
if result.status_code == 200:
281+
logging.info("Data base connection successful.")
282+
else:
283+
raise ConnectionError("Data base connection not successful. " +
284+
"Error: ".format(result.status_code))
285+
# extract data
286+
turbine_data = pd.DataFrame(result.json())
287+
# dump data as csv
288+
turbine_data.to_csv(os.path.join(os.path.dirname(__file__), 'data',
289+
'turbine_data_oedb.csv'))
290+
else:
291+
raise ImportError('If you want to load turbine data from the oedb' +
292+
'you have to install the requests package.' +
293+
'see https://pypi.org/project/requests/')
294+
return turbine_data
295+
296+
def get_turbine_types(print_out=True):
254297
r"""
255298
Get the names of all possible wind turbine types for which the power
256299
coefficient curve or power curve is provided in the data files in

0 commit comments

Comments
 (0)