|
14 | 14 | import os |
15 | 15 | import numpy as np |
16 | 16 |
|
| 17 | +try: |
| 18 | + import requests as rq |
| 19 | +except ImportError: |
| 20 | + rq = None |
17 | 21 |
|
18 | 22 | class WindTurbine(object): |
19 | 23 | r""" |
@@ -250,7 +254,46 @@ def read_turbine_data(source='oedb', **kwargs): |
250 | 254 | return df |
251 | 255 |
|
252 | 256 |
|
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): |
254 | 297 | r""" |
255 | 298 | Get the names of all possible wind turbine types for which the power |
256 | 299 | coefficient curve or power curve is provided in the data files in |
|
0 commit comments