@@ -169,13 +169,18 @@ def restructure_data():
169169 the corresponding wind speeds in m/s.
170170
171171 """
172- df = read_turbine_data ( source = data_source )
172+
173173 if data_source == 'oedb' :
174- df .set_index ('wea_type' , inplace = True )
175- data = df .loc [self .name ]['power_curve' ]
174+ df = load_turbine_data_from_oedb ()
175+ df .set_index ('turbine_type' , inplace = True )
176+ # Set `curve` depending on `fetch_curve` to match names in oedb
177+ curve = ('cp_curve' if fetch_curve == 'power_coefficient_curve'
178+ else fetch_curve )
179+ data = df .loc [self .name ][curve ]
176180 nominal_power = df .loc [self .name ][
177181 'installed_capacity_kw' ] * 1000
178182 else :
183+ df = read_turbine_data (filename = data_source )
179184 wpp_df = df [df .turbine_id == self .name ]
180185 # if turbine not in data file
181186 if wpp_df .shape [0 ] == 0 :
@@ -184,9 +189,10 @@ def restructure_data():
184189 pd .reset_option ('display.max_rows' )
185190 sys .exit ('Cannot find the wind converter type: {0}' .format (
186191 self .name ))
187- # if turbine in data file write power (coefficient) curve values
188- # to 'data' array
189- ncols = ['turbine_id' , 'p_nom' , 'source' , 'modificationtimestamp' ]
192+ # if turbine in data file write power (coefficient) curve
193+ # values to 'data' array
194+ ncols = ['turbine_id' , 'p_nom' , 'source' ,
195+ 'modificationtimestamp' ]
190196 data = np .array ([0 , 0 ])
191197 for col in wpp_df .keys ():
192198 if col not in ncols :
@@ -218,46 +224,47 @@ def restructure_data():
218224 return self
219225
220226
221- def read_turbine_data (source = 'oedb' , ** kwargs ):
227+ def read_turbine_data (filename , ** kwargs ):
222228 r"""
223- Fetches power (coefficient) curves from a database or a file.
224-
229+ Fetches power (coefficient) curves from a or a file.
225230 Turbine data is provided by the Open Energy Database (oedb) or can be
226- provided by the user via a file. In the directory windpowerlib/data an
227- example file is provided.
231+ provided by the user via a file. In the directory windpowerlib/data example
232+ files are provided.
228233
229234 Parameters
230235 ----------
231- source : string
232- Specifies the source of the turbine data as 'oedb' (Open Energy
233- Database: https://openenergy-platform.org/dataedit/) or as the name of
234- a data file. Use 'example_turbine_data' to use the example data.
235- Default: 'oedb'. TODO add example file!
236+ filename : string
237+ Specifies the source of the turbine data.
238+ Use 'example_power_coefficient_curves.csv' or
239+ 'example_power_curves.csv' to use the example data.
236240
237241 Other Parameters
238242 ----------------
239243 datapath : string, optional
240- Path where the data file is stored if `source` is ' csv' .
244+ Path where the data file is stored if `source` is name of a csv file .
241245 Default: './data'
242246
243247 Returns
244248 -------
245249 pandas.DataFrame
246250 Power coefficient curve values (dimensionless) or power curve values
247251 in kW with corresponding wind speeds in m/s of all available wind
248- turbines with turbine name in column 'turbine_id ', turbine nominal
252+ turbines with turbine name in column 'turbine_type ', turbine nominal
249253 power in column 'p_nom'.
250254
251255 """
252- if source == 'oedb' :
253- df = load_turbine_data_from_oedb ()
254- else :
255- if 'datapath' not in kwargs :
256- kwargs ['datapath' ] = os .path .join (os .path .dirname (__file__ ),
257- 'data' )
258- df = pd .read_csv (os .path .join (kwargs ['datapath' ], source ),
256+
257+ if 'datapath' not in kwargs :
258+ kwargs ['datapath' ] = os .path .join (os .path .dirname (__file__ ),
259+ 'data' )
260+ try :
261+ df = pd .read_csv (os .path .join (kwargs ['datapath' ], filename ),
259262 index_col = 0 )
260- # todo: add raising error message if file does not exist.
263+ except FileNotFoundError :
264+ raise FileNotFoundError (
265+ "The file '{}' was not found. Check spelling " .format (filename ) +
266+ "and `datapath` - is '{}' " .format (kwargs ['datapath' ]) +
267+ "and can be changed in read_turbine_data()" )
261268 return df
262269
263270
0 commit comments