Skip to content

Commit ad6904f

Browse files
committed
Combine datapath and filename
1 parent 5509957 commit ad6904f

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

example/modelchain_example.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,15 @@ def initialize_wind_turbines():
133133

134134
# specification of wind turbine where power coefficient curve is provided
135135
# by a csv file
136+
csv_file = os.path.join(os.path.dirname(__file__), 'data',
137+
'example_power_coefficient_curves.csv')
138+
# todo adapt in jupyter notebook!!!
136139
dummy_turbine = {
137140
'name': 'DUMMY 1', # turbine type as in file #
138141
'hub_height': 100, # in m
139142
'rotor_diameter': 70, # in m
140143
'fetch_curve': 'power_coefficient_curve', # fetch cp curve #
141-
'data_source': 'example_power_coefficient_curves.csv' # data source
144+
'data_source': csv_file # data source
142145
}
143146
# initialize WindTurbine object
144147
dummy_turbine = WindTurbine(**dummy_turbine)

windpowerlib/wind_turbine.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,15 @@ def fetch_turbine_data(self, fetch_curve, data_source):
169169
>>> print(e126.nominal_power)
170170
4200000.0
171171
172+
>>> import os
173+
>>> source = os.path.join(os.path.dirname(__file__), '../example/data',
174+
... 'example_power_curves.csv')
172175
>>> example_turbine = {
173176
... 'hub_height': 100,
174177
... 'rotor_diameter': 70,
175178
... 'name': 'DUMMY 3',
176179
... 'fetch_curve': 'power_curve',
177-
... 'data_source': 'example_power_curves.csv'}
180+
... 'data_source': source}
178181
>>> e_t_1 = wind_turbine.WindTurbine(**example_turbine)
179182
>>> print(e_t_1.power_curve['power'][7])
180183
18000.0
@@ -211,7 +214,7 @@ def restructure_data():
211214
nominal_power = df.loc[self.name][
212215
'installed_capacity_kw'] * 1000
213216
else:
214-
df = read_turbine_data(filename=data_source)
217+
df = read_turbine_data(data_source)
215218
wpp_df = df[df.turbine_id == self.name]
216219
# if turbine not in data file
217220
if wpp_df.shape[0] == 0:
@@ -256,7 +259,7 @@ def restructure_data():
256259
return self
257260

258261

259-
def read_turbine_data(filename, **kwargs):
262+
def read_turbine_data(file_):
260263
r"""
261264
Fetches power (coefficient) curves from a or a file.
262265
Turbine data is provided by the Open Energy Database (oedb) or can be
@@ -265,17 +268,11 @@ def read_turbine_data(filename, **kwargs):
265268
266269
Parameters
267270
----------
268-
filename : string
271+
file_ : string
269272
Specifies the source of the turbine data.
270-
Use 'example_power_coefficient_curves.csv' or
273+
Use 'example_power_coefficient_curves.csv' or # todo adapt
271274
'example_power_curves.csv' to use the example data.
272275
273-
Other Parameters
274-
----------------
275-
datapath : string, optional
276-
Path where the data file is stored if `source` is name of a csv file.
277-
Default: './data'
278-
279276
Returns
280277
-------
281278
pandas.DataFrame
@@ -286,17 +283,10 @@ def read_turbine_data(filename, **kwargs):
286283
287284
"""
288285

289-
if 'datapath' not in kwargs:
290-
kwargs['datapath'] = os.path.join(os.path.dirname(__file__),
291-
'data')
292286
try:
293-
df = pd.read_csv(os.path.join(kwargs['datapath'], filename),
294-
index_col=0)
287+
df = pd.read_csv(file_, index_col=0)
295288
except FileNotFoundError:
296-
raise FileNotFoundError(
297-
"The file '{}' was not found. Check spelling ".format(filename) +
298-
"and `datapath` - is '{}' ".format(kwargs['datapath']) +
299-
"and can be changed in read_turbine_data()")
289+
raise FileNotFoundError("The file '{}' was not found.".format(file_))
300290
return df
301291

302292

0 commit comments

Comments
 (0)