33import logging
44import numpy as np
55import pandas as pd
6- from urllib .request import urlretrieve
76
87
98class SimpleWindTurbine :
@@ -293,7 +292,7 @@ def read_wpp_data(**kwargs):
293292 r"""
294293 Fetch cp values from a file or download it from a server.
295294
296- The files are located in the ~/.oemof folder.
295+ The files are located in the data folder of the package root .
297296
298297 Returns
299298 -------
@@ -303,46 +302,21 @@ def read_wpp_data(**kwargs):
303302
304303 Other Parameters
305304 ----------------
306- cp_path : string, optional
307- Path where the cp file is stored. Default: $HOME/.windpower
305+ datapath : string, optional
306+ Path where the cp file is stored. Default: '$PACKAGE_ROOT/data'
308307 filename : string, optional
309- Filename of the cp file without suffix. The suffix of the file should be
310- csv or hf5.
311- url : string, optional
312- URL from where the cp file is loaded if not present
313-
314- Notes
315- -----
316- The files can be downloaded from
317- http://vernetzen.uni-flensburg.de/~git/
308+ Filename of the cp file.
309+
318310 """
319- default_cp_path = os .path .join (os .path .expanduser ("~" ), '.windpower' )
320- cp_path = kwargs .get ('cp_path' , default_cp_path )
321- filename = kwargs .get ('filename' , 'cp_values' )
322- filepath = os .path .join (cp_path , filename )
323- url = kwargs .get (
324- 'url' , 'http://vernetzen.uni-flensburg.de/~git/cp_values' )
325- suffix = '.hf5'
326- if not os .path .exists (cp_path ):
327- os .makedirs (cp_path )
328- if not os .path .isfile (filepath + suffix ):
329- urlretrieve (url + suffix , filepath + suffix )
330- logging .info ('Copying cp_values from {0} to {1}' .format (
331- url , filepath + suffix ))
332- logging .debug ('Retrieving cp values from {0}' .format (
333- filename + suffix ))
334- try :
335- df = pd .read_hdf (filepath + suffix , 'cp' )
336- except ValueError :
337- suffix = '.csv'
338- logging .info ('Failed loading cp values from hdf file, trying csv.' )
339- logging .debug ('Retrieving cp values from {0}' .format (
340- filename + suffix ))
341- if not os .path .isfile (filename + suffix ):
342- urlretrieve (url + suffix , filename + suffix )
343- logging .info ('Copying cp_values from {0} to {1}' .format (
344- url , filename + suffix ))
345- df = pd .read_csv (filename + suffix , index_col = 0 )
311+ if 'datapath' not in kwargs :
312+ kwargs ['datapath' ] = os .path .join (os .path .dirname (__file__ ), 'data' )
313+
314+ if 'filename' not in kwargs :
315+ kwargs ['filename' ] = 'cp_values.csv'
316+
317+ cp_file = os .path .join (kwargs ['datapath' ], kwargs ['filename' ])
318+
319+ df = pd .read_csv (cp_file , index_col = 0 )
346320 return df
347321
348322
@@ -363,7 +337,7 @@ def get_wind_pp_types(print_out=True):
363337 (91, 2)
364338 >>> print(valid_types_df.iloc[5])
365339 rli_anlagen_id DEWIND D8 2000
366- p_nenn 2000.0
340+ p_nenn 2000
367341 Name: 5, dtype: object
368342 """
369343 df = read_wpp_data ()
0 commit comments