Skip to content

Commit 696199a

Browse files
committed
Restructure function for connection to oedb
1 parent 14dee34 commit 696199a

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

doc/whatsnew/v0-1-0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ New functions
1717
* logarithmic interpolation/extrapolation for wind speed time series
1818
* gauss distribution
1919
* estimation of turbulence intensity by roughness length
20+
* retrieve power curves from Open Energy Database
2021

2122

2223
Testing

windpowerlib/wind_turbine.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,27 @@ def restructure_data():
208208
return self
209209

210210

211-
def read_turbine_data(**kwargs):
211+
def read_turbine_data(source='oedb', **kwargs):
212212
r"""
213-
Fetches power (coefficient) curves from a file.
213+
Fetches power (coefficient) curves from a database or a file.
214214
215-
The data files are provided along with the windpowerlib and are located in
216-
the directory windpowerlib/data.
215+
Turbine data is provided by the Open Energy Database (oedb) or can be
216+
provided by the user via a file. In the directory windpowerlib/data an
217+
example file is provided.
218+
219+
Parameters
220+
----------
221+
source : string
222+
Specifies the source of the turbine data as 'oedb' (Open Energy
223+
Database: https://openenergy-platform.org/dataedit/) or as the name of
224+
a data file. Use 'example_turbine_data' to use the example data.
225+
Default: 'oedb'. TODO add example file!
217226
218227
Other Parameters
219228
----------------
220229
datapath : string, optional
221-
Path where the data file is stored. Default: './data'
222-
filename : string, optional
223-
Name of data file. Provided data files are 'power_curves.csv' and
224-
'power_coefficient_curves.csv'. Default: 'power_curves.csv'.
230+
Path where the data file is stored if `source` is 'csv'.
231+
Default: './data'
225232
226233
Returns
227234
-------
@@ -232,14 +239,16 @@ def read_turbine_data(**kwargs):
232239
power in column 'p_nom'.
233240
234241
"""
235-
if 'datapath' not in kwargs:
236-
kwargs['datapath'] = os.path.join(os.path.dirname(__file__), 'data')
237-
238-
if 'filename' not in kwargs:
239-
kwargs['filename'] = 'power_curves.csv'
240-
241-
df = pd.read_csv(os.path.join(kwargs['datapath'], kwargs['filename']),
242-
index_col=0)
242+
if source == 'oedb':
243+
# todo: add connection to oedb
244+
pass
245+
else:
246+
if 'datapath' not in kwargs:
247+
kwargs['datapath'] = os.path.join(os.path.dirname(__file__),
248+
'data')
249+
df = pd.read_csv(os.path.join(kwargs['datapath'], source),
250+
index_col=0)
251+
# todo: add raising error message if file does not exist.
243252
return df
244253

245254

0 commit comments

Comments
 (0)