Skip to content

Commit b049dee

Browse files
committed
move cp_values and integrate them in the model
By now the model is relient on an external server to download the cp- values. Due to technical problems this might not be a good idea in the future.
1 parent b34a547 commit b049dee

File tree

3 files changed

+18
-46
lines changed

3 files changed

+18
-46
lines changed

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@author: uwe
44
"""
55

6-
import sys
6+
import os
77
from setuptools import setup
88

99
setup(name='windpowerlib',
@@ -14,6 +14,8 @@
1414
author_email='mail',
1515
license=None,
1616
packages=['windpowerlib'],
17+
package_data={
18+
'windpowerlib': [os.path.join('data', '*.csv')]},
1719
zip_safe=False,
1820
install_requires=['numpy >= 1.7.0',
1921
'pandas >= 0.13.1',

windpowerlib/basicmodel.py

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
import numpy as np
55
import pandas as pd
6-
import requests
76

87

98
class 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,50 +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-
req = requests.get(url + suffix)
330-
with open(filepath + suffix, 'wb') as fout:
331-
fout.write(req.content)
332-
logging.info('Copying cp_values from {0} to {1}'.format(
333-
url, filepath + suffix))
334-
logging.debug('Retrieving cp values from {0}'.format(
335-
filename + suffix))
336-
try:
337-
df = pd.read_hdf(filepath + suffix, 'cp')
338-
except ValueError:
339-
suffix = '.csv'
340-
logging.info('Failed loading cp values from hdf file, trying csv.')
341-
logging.debug('Retrieving cp values from {0}'.format(
342-
filename + suffix))
343-
if not os.path.isfile(filename + suffix):
344-
req = requests.get(url + suffix)
345-
with open(filename + suffix, 'wb') as fout:
346-
fout.write(req.content)
347-
logging.info('Copying cp_values from {0} to {1}'.format(
348-
url, filename + suffix))
349-
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)
350320
return df
351321

352322

@@ -367,7 +337,7 @@ def get_wind_pp_types(print_out=True):
367337
(91, 2)
368338
>>> print(valid_types_df.iloc[5])
369339
rli_anlagen_id DEWIND D8 2000
370-
p_nenn 2000.0
340+
p_nenn 2000
371341
Name: 5, dtype: object
372342
"""
373343
df = read_wpp_data()

0 commit comments

Comments
 (0)