Skip to content

Commit 616b0f0

Browse files
committed
Used default data instead of backup files
1 parent 7a32ea6 commit 616b0f0

File tree

7 files changed

+304
-71
lines changed

7 files changed

+304
-71
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
turbine_type,0.0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.2,4.5,5.0,5.2,5.5,6.0,6.2,6.5,7.0,7.5,8.0,8.1,8.5,8.8,9.0,9.5,10.0,10.2,10.5,11.0,11.1,11.5,12.0,12.5,13.0,13.5,14.0,14.5,15.0,15.5,16.0,16.5,17.0,17.5,18.0,18.5,19.0,19.5,20.0,20.5,21.0,21.5,22.0,22.5,23.0,23.5,24.0,24.5,25.0,26.0
2+
E48/800,,,0.0,,0.0,,0.17,,0.35,,,0.43,,,0.46,,,0.47,,0.48,,,,0.5,,0.5,,,0.45,,,0.39,,0.32,,0.27,,0.22,,0.18,,0.15,,0.13,,0.11,,0.09,,0.08,,0.07,,0.06,,0.05,,0.05,
3+
E-115/3200,,,0.0,,0.06,,0.28,,0.38,,,0.42,,,0.45,,,0.47,,0.46,,,,0.45,,0.42,,,0.35,,,0.29,,0.23,,0.18,,0.15,,0.12,,0.1,,0.09,,0.07,,0.06,,0.05,,0.05,,0.04,,0.04,,0.03,
4+
E-101/3500,,,0.0,,0.08,,0.28,,0.37,,,0.41,,,0.44,,,0.46,,0.47,,,,0.47,,0.46,,,0.43,,,0.38,,0.32,,0.26,,0.21,,0.17,,0.15,,0.12,,0.1,,0.09,,0.08,,0.07,,0.06,,0.05,,0.05,
5+
E-126/4200,,,0.0,,0.0,,0.28,,0.37,,,0.41,,,0.44,,,0.45,,0.45,,,,0.43,,0.4,,,0.35,,,0.3,,0.24,,0.2,,0.16,,0.13,,0.11,,0.09,,0.08,,0.07,,0.06,,0.05,,0.04,,0.04,,0.03,
6+
E-101/3050,,,0.adfsf076,,0.279,,0.376,,,0.421,,,0.452,,,0.469,,0.478,,,,0.478,,0.477,,,0.439,,,0.358,,0.283,,0.227,,0.184,,0.152,,0.127,,0.107,,0.091,,0.078,,0.067,,0.058,,0.051,,0.045,,0.04,
7+
E-115/3000,,,0.0,,0.058,,0.279,,0.376,,,0.421,,,0.451,,,0.469,,0.47,,,,0.445,,0.401,,,0.338,,,0.27,,0.212,,fas.11,,0.09,,0.08,,0.07,,0.06,,0.05,,0.05,,0.04,
8+
E-53/800,,,0.0,,0.19,,0.39,,0.44,,,0.46,,,0.48,,,0.49,,0.49,,,,0.49,,0.48,,,0.42,,,0.34,,0.27,,0.22,,0.18,,0.15,,0.12,,0.1,,0.09,,0.08,,0.06,,0.06,,0.05,,0.04,,0.04,
9+
GE130/3200,,,,,,,0.255,0.367,0.413,,0.433,0.442,,0.448,0.45,,0.452,0.443,0.451,0.446,,0.436,,0.417,0.393,0.361,,0.326,0.292,,0.259,0.229,0.203,0.181,0.161,0.145,0.13,0.118,0.107,0.097,0.088,0.081,0.074,0.068,0.063,0.058,0.054,0.05,0.046,0.043,0.04,0.037,0.035,0.033,0.031,0.029,0.027,0.025,
10+
GE120/2750,0.0,0.0,0.0,0.0,0.0,0.0,0.13,0.3,0.39,,0.43,0.45,,0.46,0.47,,0.48,0.48,0.48,0.47,,0.46,,0.43,0.4,0.36,,0.33,0.29,,0.26,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,0.23,
11+
GE103/2750,0.0,0.0,0.0,0.0,ads,0.25,0.32,,0.36,0.39,,0.42,0.43,,0.44,0.44,0.45,0.45,,0.45,,0.45,0.43,0.42,,0.39,0.36,,0.33,0.3,0.27,0.25,0.22,0.2,0.18,0.16,0.15,0.13,0.12,0.11,0.1,0.09,0.09,0.08,0.07,0.07,0.06,0.06,0.06,0.05,0.05,0.05,0.04,0.04,0.04,0.04,
12+
GE120/2500,0.0,0.0,0.0,0.0,0.0,0.0,0.13,0.3,0.39,,0.43,0.45,,0.46,0.47,,0.48,0.48,0.48,0.47,,0.46,,0.43,0.39,0.35,,0.31,0.27,,0.24,0.21,0.19,0.17,0.15,0.13,0.12,0.11,0.1,0.09,0.08,0.07,0.065,0.06,0.055,0.05,0.05,0.05,,,,,,,,,,,
13+
ENO126/3500,,,,,,,0.155,,0.419,,,0.444,,,0.442,,,0.446,,0.45,,,,0.419,,0.39,,,0.331,,,0.265,,0.209,,0.167,,0.136,,0.112,,0.093,,0.079,,0.067,,0.057,,0.049,,0.043,,0.038,,0.033,,0.029,
14+
ENO114/3500,,,,,,,0.138,,,0.384,,,0.426,,,0.428,,0.421,,,0.427,,0.42,,,,0.404,,,0.378,,0.315,,0.251,,0.201,,0.163,,0.135,,0.112,,0.094,,0.08,,0.069,,0.06,,0.052,,0.045,,0.04,,0.035,

tests/oedb/turbine_data_broken.csv

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
turbine_type,calculated,has_cp_curve,has_ct_curve,has_power_curve,hub_height,id,manufacturer,max_speed_drive,name,nominal_power,power_density,power_density_2,rotor_area,rotor_diameter,source,turbine_id,turbine_type_v2,wind_class_iec,wind_zone_dibt
2+
AD135/5050,,False,False,False,,80,Adwen/Areva,14,AD 5-135,5050000,353,3,14312,135,https://www.wind-turbine-models.com/turbines/1122-adwen-ad-5-135,86,AD-135_5050,IEC I (GL-TK 1 & GL-TK S),
3+
GE158/4800,,"False",False,False,101;hallo;149;169,111,GE Wind,,GE 4.8-158,"capacity",,,19604,158,https://www.gerenewableenergy.com/wind-energy/turbines/4mw-platform; https://www.wind-turbine-models.com/turbines/1719-general-electric-ge-4.8-158,120,GE-158_4800,,
4+
GE137/3400,True,False,False,False,85;110;131;134;155,113,GE Wind,,GE 3.4-137,3400000,,,14739,137,https://www.wind-turbine-models.com/turbines/1339-general-electric-ge-3.4-137,122,GE-137_3400,,
5+
GE137/3600,,False,False,False,85;110;131.4;164.5,112,GE Wind,,GE 3.6-137,3600000,,,14739,137,https://www.wind-turbine-models.com/turbines/1551-general-electric-ge-3.6-137,121,GE-137_3600,IIIb,
6+
ENO92/2200,,False,False,False,,129,Eno,,ENO 92,2200000,,,6647,92,https://www.wind-turbine-models.com/turbines/652-eno-energy-eno-92,140,ENO-92_2200,,
7+
GE103/2500,True,False,False,False,85; 110; 139,120,GE Wind,,GE 2.5-103,2500000,243,4,8331,103,https://www.wind-turbine-models.com/turbines/1293-general-electric-ge-2.5-103,129,GE-103_2500,IIIa,WZ 2
8+
ENO114/4000,,False,False,False,,126,Eno,,ENO 114 4.0,4000000,,,10206,114,https://www.wind-turbine-models.com/turbines/1473-eno-energy-eno-114-4.0,137,ENO-114_4000,,
9+
E48/800,,True,False,True,50;55; 60;65;76,132,Enercon,,E-48 800,800000,,,1809,48,http://www.windenergie-im-binnenland.de/powercurve.php,144,E48_800,,
10+
E-115/3200,True,True,False,True,92; 122; 135; 149,3,Enercon,13,E-115/3200,3200000,304,3,10512,116,https://www.enercon.de/fileadmin/Redakteur/Medien-Portal/broschueren/pdf/ENERCON_Produkt_de_042017.pdf; https://www.wind-turbine-models.com/turbines/,4,E-115_3200,IEC/EN IIA,WZ 4 GKI; WZ 4 GK II
11+
AD132/5000,,False,False,False,80; 94,81,Adwen/Areva,12,AD 5-132,5000000,365,3,13683,132,https://www.wind-turbine-models.com/turbines/1123-adwen-ad-5-132,87,AD-132_5000,IEC IIA/IEC S,
12+
GE103/2850,,False,False,False,75;85;98.3,115,GE Wind,,GE 2.85-103,3850000,,,8331,103,https://www.wind-turbine-models.com/turbines/750-general-electric-ge-2.85-103,124,GE-103_2850,,
13+
ENO126/4800,,False,False,False,,122,Eno,,ENO 126 4.8,4800000,,,12467,126,https://www.wind-turbine-models.com/turbines/1741-eno-energy-eno-126-4.8,133,ENO-126_4800,,
14+
ENO126/4000,,False,False,False,,123,Eno,,ENO 126 4.0,4000000,,,12467,126,https://www.wind-turbine-models.com/turbines/1484-eno-energy-eno-126-4.0,134,ENO-126_4000,,
15+
ENO114/4800,,False,False,False,,125,Eno,,ENO 114 4.8,4800000,,,10206,114,https://www.wind-turbine-models.com/turbines/1742-eno-energy-eno-114-4.8,136,ENO-114_4800,,
16+
ENO82/2050,True,False,False,False,,130,Eno,,ENO 82,2050000,,,5280,82,http://www.eno-energy.com/produkte-leistungen/windenergieanlagen/eno-82-205-mw/#c86; https://www.wind-turbine-models.com/turbines/108-eno-energy-eno-82,141,ENO-82_2050,,
17+
GE100/2750,,False,False,False, 75;85;98.3;123.5,118,GE Wind,,GE 2.75-100,2750000,,,7853,100,https://www.wind-turbine-models.com/turbines/748-general-electric-ge-2.75-100,127,GE-100_2750,,
18+
E-101/3500,True,True,False,True,74; 99,2,Enercon,15,E-101/3500 E2,3500000,437,2,8011,101,https://www.enercon.de/fileadmin/Redakteur/Medien-Portal/broschueren/pdf/ENERCON_Produkt_de_042017.pdf; https://www.wind-turbine-models.com/turbines/,3,E-101_3500,IEC/EN IA,WZ 4 GK I; WZ 4 GK II
19+
E-126/4200,True,True,False,True,99; 135; 159,1,Enercon,12,E-126/4200 EP4,4200000,331,3,12666,127,https://www.enercon.de/fileadmin/Redakteur/Medien-Portal/broschueren/pdf/ENERCON_Produkt_de_042017.pdf; https://www.wind-turbine-models.com/turbines/,2,E-126_4200,IEC/EN IA; IEC/EN IIA,WZ4 GK I; WZ4 GK II; WZ3 GK I; WZ3 GK II
20+
E-101/3050,True,True,False,True,99; 124; 135; 149,4,Enercon,15,E-101/3050 E2,3050000,381,3,8011,101,https://www.enercon.de/fileadmin/Redakteur/Medien-Portal/broschueren/pdf/ENERCON_Produkt_de_042017.pdf; https://www.wind-turbine-models.com/turbines/,5,E-101_3050,IEC/EN IIA,WZ III; WZ 4 GK I

tests/test_data_handling.py

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
import os
77
from datetime import datetime
88
from shutil import copyfile
9-
9+
import filecmp
1010
import pandas as pd
1111
import pytest
1212

1313
from windpowerlib.data import (
1414
check_data_integrity,
15-
check_imported_data,
15+
check_turbine_data,
1616
get_turbine_types,
1717
store_turbine_data_from_oedb,
18+
restore_default_turbine_data,
1819
)
1920

2021

@@ -24,61 +25,51 @@ def setup_class(cls):
2425
cls.path = os.path.join(os.path.dirname(__file__), "oedb")
2526
cls.filename = os.path.join(cls.path, "{0}.csv")
2627
cls.df = pd.read_csv(cls.filename.format("turbine_data"), index_col=0)
27-
cls.time_stamp = datetime.now().strftime("%Y%m%d%H%M%S")
28-
cls.broken_fn = os.path.join(cls.path, "power_curves_broken.csv")
29-
cls.backup_fn = os.path.join(cls.path, "power_curves_backup.csv")
28+
cls.broken_fn = os.path.join(cls.path, "{0}_broken.csv")
29+
cls.backup_fn = os.path.join(cls.path, "{0}_backup.csv")
30+
cls.tmp_fn = os.path.join(cls.path, "{0}_tmp.csv")
3031
cls.orig_path = os.path.join(
3132
os.path.dirname(__file__), os.pardir, "windpowerlib", "oedb"
3233
)
33-
cls.orig_fn = os.path.join(cls.orig_path, "power_curves.csv")
34+
cls.orig_fn = os.path.join(cls.orig_path, "{0}.csv")
3435

3536
@classmethod
3637
def teardown_class(cls):
3738
cls.path = os.path.join(os.path.dirname(__file__), "oedb")
38-
cls.backup_fn = os.path.join(cls.path, "power_curves_backup.csv")
39-
orig_path = os.path.join(
40-
os.path.dirname(__file__), os.pardir, "windpowerlib", "oedb"
41-
)
42-
cls.orig_fn = os.path.join(orig_path, "power_curves.csv")
43-
copyfile(cls.backup_fn, cls.orig_fn)
4439
for f in os.listdir(cls.path):
45-
if "error" in f:
40+
if "error" in f or "backup" in f or "tmp" in f:
4641
os.remove(os.path.join(cls.path, f))
42+
restore_default_turbine_data()
4743

4844
def test_normal_data_check(self):
49-
copyfile(
50-
self.filename.format("turbine_data"),
51-
self.filename.format("turbine_data_{0}".format(self.time_stamp)),
52-
)
53-
for curve_type in ["power_curve", "power_coefficient_curve"]:
54-
copyfile(
55-
self.filename.format("{}s".format(curve_type)),
56-
self.filename.format(
57-
"{0}s_{1}".format(curve_type, self.time_stamp)
58-
),
59-
)
60-
check_imported_data(self.df, self.filename, self.time_stamp)
45+
check_turbine_data(self.filename.format("turbine_data"))
6146

6247
def test_data_check_logging_warnings(self, caplog):
6348
self.df.loc["GE158/4800", "has_power_curve"] = True
6449
self.df.loc["GE100/2750", "has_cp_curve"] = True
65-
check_data_integrity(self.df, min_pc_length=26)
50+
self.df.to_csv(self.tmp_fn.format("turbine_data"))
51+
check_data_integrity(self.tmp_fn, min_pc_length=26)
6652
assert "E48/800: power_curve is too short (25 values)" in caplog.text
6753
assert "GE158/4800: No power curve" in caplog.text
6854
assert "GE100/2750: No cp-curve but has_cp_curve" in caplog.text
6955

7056
def test_global_error(self):
71-
msg = "Must have equal len keys"
57+
msg = r"could not convert string to*"
58+
name = "turbine_data"
59+
copyfile(self.orig_fn.format(name), self.backup_fn.format(name))
60+
copyfile(self.broken_fn.format(name), self.orig_fn.format(name))
7261
with pytest.raises(ValueError, match=msg):
73-
self.df.loc["GE158/4800", "has_cp_curve"] = [5, 3]
74-
check_imported_data(self.df, self.filename, self.time_stamp)
62+
check_turbine_data(self.orig_fn)
63+
copyfile(self.backup_fn.format(name), self.orig_fn.format(name))
7564

7665
def test_broken_pwr_curve(self):
77-
copyfile(self.orig_fn, self.backup_fn)
78-
copyfile(self.broken_fn, self.orig_fn)
66+
name = "power_curves"
67+
copyfile(self.orig_fn.format(name), self.backup_fn.format(name))
68+
copyfile(self.broken_fn.format(name), self.orig_fn.format(name))
7969
msg = "could not convert string to float"
8070
with pytest.raises(ValueError, match=msg):
81-
check_imported_data(self.df, self.filename, self.time_stamp)
71+
check_turbine_data(self.orig_fn)
72+
copyfile(self.backup_fn.format(name), self.orig_fn.format(name))
8273

8374
def test_get_turbine_types(self, capsys):
8475
get_turbine_types()
@@ -100,6 +91,27 @@ def test_store_turbine_data_from_oedb(self):
10091
def test_wrong_url_load_turbine_data(self):
10192
"""Load turbine data from oedb."""
10293
with pytest.raises(
103-
ConnectionError, match="Database connection not successful"
94+
ConnectionError,
95+
match=r"Database \(oep\) connection not successful*",
10496
):
10597
store_turbine_data_from_oedb("wrong_schema")
98+
99+
def test_restore_default_data(self):
100+
names = ["turbine_data", "power_curves", "power_coefficient_curves"]
101+
default_path = os.path.join(
102+
self.orig_path, os.pardir, "data", "default_turbine_data"
103+
)
104+
for name in names:
105+
copyfile(self.broken_fn.format(name), self.orig_fn.format(name))
106+
file = self.orig_fn.format(name)
107+
default_file = os.path.join(
108+
default_path, os.path.basename(self.orig_fn.format(name))
109+
)
110+
assert not filecmp.cmp(file, default_file)
111+
restore_default_turbine_data()
112+
for name in names:
113+
file = self.orig_fn.format(name)
114+
default_file = os.path.join(
115+
default_path, os.path.basename(self.orig_fn.format(name))
116+
)
117+
assert filecmp.cmp(file, default_file)

windpowerlib/data.py

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
SPDX-License-Identifier: MIT
66
"""
77

8+
import filecmp
89
import logging
910
import os
1011
import warnings
@@ -13,9 +14,8 @@
1314

1415
import pandas as pd
1516
import requests
16-
17-
from windpowerlib.wind_turbine import WindTurbine
1817
from windpowerlib.tools import WindpowerlibUserWarning
18+
from windpowerlib.wind_turbine import WindTurbine
1919

2020

2121
def get_turbine_types(turbine_library="local", print_out=True, filter_=True):
@@ -187,7 +187,6 @@ def store_turbine_data_from_oedb(
187187
# standard file name for saving data
188188
filename = os.path.join(os.path.dirname(__file__), "oedb", "{0}.csv")
189189

190-
time_stamp = datetime.now().strftime("%Y%m%d%H%M%S")
191190
# get all power (coefficient) curves and save to file
192191
# for curve_type in ['power_curve', 'power_coefficient_curve']:
193192
for curve_type in ["power_curve", "power_coefficient_curve"]:
@@ -228,10 +227,6 @@ def store_turbine_data_from_oedb(
228227
if curve_type == "power_curve":
229228
curves_df *= 1000
230229
curves_df.index.name = "turbine_type"
231-
copyfile(
232-
filename.format("{}s".format(curve_type)),
233-
filename.format("{0}s_{1}".format(curve_type, time_stamp)),
234-
)
235230
curves_df.to_csv(filename.format("{}s".format(curve_type)))
236231

237232
# get turbine data and save to file (excl. curves)
@@ -248,13 +243,8 @@ def store_turbine_data_from_oedb(
248243
).set_index("turbine_type")
249244
# nominal power in W
250245
turbine_data_df["nominal_power"] *= 1000
251-
copyfile(
252-
filename.format("turbine_data"),
253-
filename.format("turbine_data_{0}".format(time_stamp)),
254-
)
255-
check_imported_data(turbine_data_df, filename, time_stamp)
256246
turbine_data_df.to_csv(filename.format("turbine_data"))
257-
remove_tmp_file(filename, time_stamp)
247+
check_turbine_data(filename)
258248
return turbine_data
259249

260250

@@ -264,44 +254,26 @@ def remove_tmp_file(filename, time_stamp):
264254
os.remove(filename.format("{0}s_{1}".format(curve_type, time_stamp)))
265255

266256

267-
def check_imported_data(data, filename, time_stamp):
257+
def check_turbine_data(filename):
268258
try:
269-
data = check_data_integrity(data)
259+
data = check_data_integrity(filename)
270260
except Exception as e:
271-
copyfile(
272-
filename.format("turbine_data"),
273-
filename.format("turbine_data_error{0}".format(time_stamp)),
274-
)
275-
copyfile(
276-
filename.format("turbine_data_{0}".format(time_stamp)),
277-
filename.format("turbine_data"),
278-
)
279-
for curve_type in ["power_curve", "power_coefficient_curve"]:
280-
copyfile(
281-
filename.format("{}s".format(curve_type)),
282-
filename.format(
283-
"{0}s_error_{1}".format(curve_type, time_stamp)
284-
),
285-
)
286-
copyfile(
287-
filename.format("{0}s_{1}".format(curve_type, time_stamp)),
288-
filename.format("{}s".format(curve_type)),
289-
)
290-
remove_tmp_file(filename, time_stamp)
261+
restore_default_turbine_data()
291262
raise e
292263
return data
293264

294265

295-
def check_data_integrity(data, min_pc_length=5):
266+
def check_data_integrity(filename, min_pc_length=5):
267+
data = pd.read_csv(filename.format("turbine_data"), index_col=[0])
296268
for data_set in data.iterrows():
297269
wt_type = data_set[0]
298-
enercon_e126 = {
270+
turbine_data_set = {
299271
"turbine_type": "{0}".format(wt_type),
300272
"hub_height": 135,
301273
}
302274
with warnings.catch_warnings():
303275
warnings.simplefilter("ignore")
304-
wt = WindTurbine(**enercon_e126)
276+
wt = WindTurbine(**turbine_data_set)
305277
if wt.power_curve is None and data_set[1].has_power_curve is True:
306278
logging.warning(
307279
"{0}: No power curve but has_power_curve=True.".format(
@@ -325,6 +297,28 @@ def check_data_integrity(data, min_pc_length=5):
325297
return data
326298

327299

300+
def restore_default_turbine_data():
301+
"""
302+
303+
Returns
304+
-------
305+
306+
Examples
307+
--------
308+
>>> restore_default_turbine_data()
309+
310+
"""
311+
src_path = os.path.join(
312+
os.path.dirname(__file__), "data", "default_turbine_data"
313+
)
314+
dst_path = os.path.join(os.path.dirname(__file__), "oedb")
315+
316+
for file in os.listdir(src_path):
317+
src = os.path.join(src_path, file)
318+
dst = os.path.join(dst_path, file)
319+
copyfile(src, dst)
320+
321+
328322
def check_weather_data(weather_data):
329323
"""
330324
Check weather Data Frame.

0 commit comments

Comments
 (0)