Skip to content

Commit adf5c06

Browse files
committed
get_turbine_types() for local file and oedb turbine_library
1 parent 83cfc73 commit adf5c06

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

tests/test_wind_turbine.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,13 @@ def test_get_turbine_data_from_file(self):
142142
file_='not_existent')
143143

144144
def test_get_turbine_types(self):
145-
get_turbine_types(print_out=True, filter_=True)
146-
get_turbine_types(print_out=False, filter_=False)
145+
# local with and without filter
146+
get_turbine_types(turbine_library='local', print_out=True,
147+
filter_=True)
148+
get_turbine_types(turbine_library='local', print_out=False,
149+
filter_=False)
150+
# oedb with and without filter
151+
get_turbine_types(turbine_library='oedb', print_out=False,
152+
filter_=True)
153+
get_turbine_types(turbine_library='oedb', print_out=False,
154+
filter_=False)

windpowerlib/wind_turbine.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,23 @@ def load_turbine_data_from_oedb():
440440
return turbine_data
441441

442442

443-
def get_turbine_types(print_out=True, filter_=True):
443+
def get_turbine_types(turbine_library='local', print_out=True, filter_=True):
444444
r"""
445-
Get all wind turbine types provided in the oedb turbine library.
445+
Get all provided wind turbine types provided.
446446
447+
Choose by `turbine_library` whether to get wind turbine types provided by
448+
the OpenEnergy Database ('oedb') or wind turbine types provided in your
449+
local file(s) ('local').
447450
By default only turbine types for which a power coefficient curve or power
448451
curve is provided are returned. Set `filter_=False` to see all turbine
449452
types for which any data (e.g. hub height, rotor diameter, ...) is
450453
provided.
451454
452455
Parameters
453456
----------
457+
turbine_library : str
458+
Specifies if the oedb turbine library ('oedb') or your local turbine
459+
data file ('local') is evaluated. Default: 'local'.
454460
print_out : bool
455461
Directly prints a tabular containing the turbine types in column
456462
'turbine_type', the manufacturer in column 'manufacturer' and
@@ -496,8 +502,15 @@ def get_turbine_types(print_out=True, filter_=True):
496502
Name: 1, dtype: object
497503
498504
"""
499-
# ToDo Use local csv files instead of querying the oedb
500-
df = load_turbine_data_from_oedb()
505+
if turbine_library == 'local':
506+
filename = os.path.join(os.path.dirname(__file__), 'data',
507+
'oedb_turbine_data.csv')
508+
df = pd.read_csv(filename, index_col=0).reset_index()
509+
elif turbine_library == 'oedb':
510+
df = load_turbine_data_from_oedb()
511+
else:
512+
raise ValueError("`turbine_library` is {} ".format(turbine_library) +
513+
"but must be 'local' or 'oedb'.")
501514
if filter_:
502515
cp_curves_df = df.loc[df['has_cp_curve']][
503516
['manufacturer', 'turbine_type', 'has_cp_curve']]
@@ -513,3 +526,6 @@ def get_turbine_types(print_out=True, filter_=True):
513526
print(curves_df)
514527
pd.reset_option('display.max_rows')
515528
return curves_df
529+
530+
531+
if __name__ == "__main__":

0 commit comments

Comments
 (0)