Skip to content
Snippets Groups Projects
Commit a6a098ec authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

Moved pyFuga + turbine_site_list_reader + lib_reader to Colonel

parent 8258c58a
No related branches found
No related tags found
1 merge request!35Moved pyFuga + turbine_site_list_reader + lib_reader to Colonel
Subproject commit 4910e86f1297f55d40f57a62be8f0f287b6e55e7
Subproject commit c1ac1ebd438d6a923ed7cb03d93a7ca784319225
'''
Created on 25. apr. 2018
@author: mmpe
'''
import os
import numpy as np
from topfarm.tests.test_files import tfp
def read_lib(filename):
with open(filename) as fid:
lines = fid.readlines()
descriptor = lines[0]
nRoughnessClasses, nHeights, nSectorslib = map(int, lines[2].split())
z0ref_lst = list(map(float, lines[4].split()))
# TODO: Implement for specified z0 and height
#
#
# for i:=0 to nRoughnessClasses-1 do read(fil,z0reflib[i]);
# readln(fil);
# for i:=0 to nHeights-1 do read(fil,zreflib[i]);
# readln(fil);
# for k:=0 to nRoughnessClasses-1 do
# begin
# for i:=0 to nSectorslib-1 do
# begin
# read(fil,freq[k,i]);
# freq[k,i]:=freq[k,i]/100;
# end;
# readln(fil);
# for i:=0 to nHeights-1 do
# begin
# for j:=0 to nSectorslib-1 do read(fil,WAlib[k,i,j]);
# readln(fil);
# for j:=0 to nSectorslib-1 do read(fil,Wklib[k,i,j]);
# readln(fil);
# end;
# end;
f, A, k = [np.array(lines[i].split()[:nSectorslib], dtype=np.float) for i in [8, 10, 12]]
return f / 100, A, k
def try_me():
if __name__ == '__main__':
print(read_lib(tfp + "fuga_files/hornsrev2.lib"))
try_me()
\ No newline at end of file
from ctypes import cdll, c_char_p, c_double
class PascalDLL(object):
def __init__(self, path):
self.lib = cdll.LoadLibrary(path)
def __getattr__(self, name):
def func_wrap(*args):
func = getattr(self.lib, name)
func.restype = c_char_p
def fmt(arg):
if isinstance(arg, str):
return arg.encode()
if isinstance(arg, float):
return c_double(arg)
return arg
fmt_args = list(map(fmt, args))
err = func(*fmt_args)
if err:
raise Exception("Exception from Fugalib: " + err.decode())
return func_wrap
'''
Created on 23. mar. 2018
@author: mmpe
'''
from _ctypes import POINTER
import atexit
from ctypes import c_double, c_int
import ctypes
import os
from tempfile import NamedTemporaryFile
import pytest
import numpy as np
from topfarm.cost_models.cost_model_wrappers import AEPCostModelComponent
from topfarm.cost_models.fuga.pascal_dll import PascalDLL
c_double_p = POINTER(c_double)
c_int_p = POINTER(ctypes.c_int32)
try:
from topfarm.cost_models.fuga.Colonel.py_colonel import PyColonel
from topfarm.cost_models.fuga.Colonel.py_colonel.py_colonel_exe import colonel_path
fuga_path = colonel_path
except ImportError:
PyColonel = object
fuga_path = os.path.abspath(os.path.dirname(__file__)) + '/Colonel/'
fugalib_path = os.path.dirname(__file__) + "/Colonel/FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt']
class PyFuga(object):
class PyFuga(PyColonel):
interface_version = 3
def __init__(self):
atexit.register(self.cleanup)
with NamedTemporaryFile() as f:
self.stdout_filename = f.name + "pyfuga.txt"
if os.path.isfile(fugalib_path) is False:
raise Exception("Fuga lib cannot be found: '%s'" % fugalib_path)
self.lib = PascalDLL(fugalib_path)
self.lib.CheckInterfaceVersion(self.interface_version)
self.lib.Initialize(self.stdout_filename)
def setup(self, farm_name='Horns Rev 1',
turbine_model_path='./LUT/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=67.00]',
tb_x=[423974, 424033], tb_y=[6151447, 6150889],
mast_position=(0, 0, 70), z0=0.0001, zi=400, zeta0=0,
farms_dir='./LUT/', wind_atlas_path='Horns Rev 1\hornsrev.lib', climate_interpolation=True):
self.lib.Setup(float(mast_position[0]), float(mast_position[1]), float(mast_position[2]),
float(z0), float(zi), float(zeta0))
assert len(tb_x) == len(tb_y)
tb_x_ctype, tb_y_ctype = self.tb_ctypes(tb_x, tb_y)
self.lib.AddWindFarm(farm_name, turbine_model_path, turbine_model_name,
len(tb_x), tb_x_ctype.data_as(c_double_p), tb_y_ctype.data_as(c_double_p))
assert os.path.isfile(farms_dir + wind_atlas_path), farms_dir + wind_atlas_path
self.lib.SetupWindClimate(farms_dir, wind_atlas_path, climate_interpolation)
assert len(tb_x) == self.get_no_turbines(), self.log + "\n%d!=%d" % (self.get_no_turbines(), len(tb_x))
def cleanup(self):
if hasattr(self, 'lib'):
try:
self.lib.Exit() # raises exception
except:
pass
del self.lib
tmp_folder = os.path.dirname(self.stdout_filename)
for f in os.listdir(tmp_folder):
if f.endswith('pyfuga.txt'):
try:
os.remove(os.path.join(tmp_folder, f))
except Exception:
pass
def get_no_turbines(self):
no_turbines_p = c_int_p(c_int(0))
self.lib.GetNoTurbines(no_turbines_p)
return no_turbines_p.contents.value
def tb_ctypes(self, tb_x, tb_y):
assert len(tb_x) == len(tb_y)
# remove mean offset to avoid loosing precision due to high offset
self.tb_x_offset, self.tb_y_offset = np.mean(tb_x), np.mean(tb_y)
tb_x = np.array(tb_x, dtype=np.float) - self.tb_x_offset
tb_y = np.array(tb_y, dtype=np.float) - self.tb_y_offset
return tb_x.ctypes, tb_y.ctypes
def move_turbines(self, tb_x, tb_y):
assert len(tb_x) == len(tb_y) == self.get_no_turbines(), (len(tb_x), len(tb_y), self.get_no_turbines())
tb_x_ctype, tb_y_ctype = self.tb_ctypes(tb_x, tb_y)
self.lib.MoveTurbines(tb_x_ctype.data_as(c_double_p), tb_y_ctype.data_as(c_double_p))
def get_aep(self, turbine_positions=None):
if turbine_positions is not None:
self.move_turbines(turbine_positions[:, 0], turbine_positions[:, 1])
AEPNet_p = c_double_p(c_double(0))
AEPGros_p = c_double_p(c_double(0))
capacity_p = c_double_p(c_double(0))
self.lib.GetAEP(AEPNet_p, AEPGros_p, capacity_p)
net, gros, cap = [p.contents.value for p in [AEPNet_p, AEPGros_p, capacity_p]]
return (net, gros, cap, net / gros)
def get_aep_gradients(self, turbine_positions=None):
if turbine_positions is not None:
self.move_turbines(turbine_positions[:, 0], turbine_positions[:, 1])
n_wt = self.get_no_turbines()
dAEPdxyz = np.zeros(n_wt), np.zeros(n_wt), np.zeros(n_wt)
dAEPdxyz_ctype = [dAEP.ctypes for dAEP in dAEPdxyz]
self.lib.GetAEPGradients(*[dAEP_ctype.data_as(c_double_p) for dAEP_ctype in dAEPdxyz_ctype])
return np.array(dAEPdxyz)
def get_TopFarm_cost_component(self):
n_wt = self.get_no_turbines()
return AEPCostModelComponent(n_wt,
lambda *args: self.get_aep(*args)[0], # only aep
lambda *args: self.get_aep_gradients(*args)[:2]) # only dAEPdx and dAEPdy
@property
def log(self):
with open(self.stdout_filename) as fid:
return fid.read()
def execute(self, script):
res = self.lib.ExecuteScript(script.encode())
print("#" + str(res) + "#")
def try_me():
if __name__ == '__main__':
from topfarm.cost_models import fuga
if not os.path.isdir(os.path.dirname(fuga.__file__) + "/Colonel/py_colonel"):
pytest.xfail("Colonel submodule not found\n")
pyFuga = PyFuga()
pyFuga.setup(farm_name='Horns Rev 1',
turbine_model_path=fuga_path + 'LUTs-T/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=70.00]',
......
import numpy as np
def read_turbine_site_list(filename):
with open(filename) as fid:
lines = fid.readlines()
turbine_model_name = lines[0].strip()
data = np.array([l.replace(",", ".").split()[:4] for l in lines[1:] if l.strip() != ""])
turbine_ids = data[:, 0]
turbine_positions = data[:, 1:].astype(np.float)
return turbine_model_name, turbine_ids, turbine_positions
def read_MR_turbine_site_list(filename):
with open(filename) as fid:
lines = fid.readlines()
farm_name = lines[0].strip()
nPairs = int(lines[1])
nacelle_models = ([(lines[2 + 2 * i].strip(), list(map(float, lines[2 + 2 * i + 1].split()))) for i in range(nPairs)])
turbine_positions = np.array([l.replace(",", ".").split()[:4] for l in lines[2 + 2 * nPairs:] if l.strip() != ""]).astype(np.float)
return farm_name, nacelle_models, turbine_positions
4xV52Farm
2
V52-0.85MWLower[h=50.00]
50. 30
V52-0.85MWUpper[h=108.00]
108. 30
-8879 2367
-8253 4048
-7730 5610
-8383 548
-6810 1800
-6230 3900
-6768 -395
-6000 5800
-4860 2500
-4740 600
-5153 -1319
-4030 5900
-3890 4200
-2990 -300
-2850 2100
-1932 -3215
-2050 6100
-1790 4200
-1320 600
-1140 -1500
-720 2600
-70 6000
520 4100
610 -600
680 1200
700 -4700
902 -2700
1750 2600
1910 5800
2009 459
2440 -5600
2830 -3600
2900 4100
3890 2400
3970 -1400
4130 -6700
4710 -4900
4870 600
4970 -3200
5850 -7700
5860 -1100
6490 -5800
6850 -2800
7820 -7900
7840 -4500
8830 -6200
9800 -7900
-3553 -2250
\ No newline at end of file
Vestas_V80_(2_MW_offshore)[h=67.00]
1 423974 6151447 67,0 9,99 10,00 1341 100,5 Vestas V80 (2 MW offshore)(Tab #1)
2 424033 6150889 67,0 9,99 10,00 1341 100,5 Vestas V80 (2 MW offshore)(Tab #1)
3 424092 6150332 67,0 9,99 10,00 1341 100,5 Vestas V80 (2 MW offshore)(Tab #1)
4 424151 6149774 67,0 9,99 10,00 1341 100,5 Vestas V80 (2 MW offshore)(Tab #1)
5 424210 6149216 67,0 9,99 10,00 1341 100,5 Vestas V80 (2 MW offshore)(Tab #1)
6 424268 6148658 67,0 9,99 10,00 1341 100,5 Vestas V80 (2 MW offshore)(Tab #1)
7 424327 6148101 67,0 9,99 9,99 1334 100,0 Vestas V80 (2 MW offshore)(Tab #1)
8 424386 6147543 67,0 9,99 9,99 1334 100,0 Vestas V80 (2 MW offshore)(Tab #1)
11 424534 6151447 67,0 9,99 10,05 1354 101,5 Vestas V80 (2 MW offshore)(Tab #1)
12 424593 6150889 67,0 9,99 10,05 1360 102,0 Vestas V80 (2 MW offshore)(Tab #1)
13 424652 6150332 67,0 9,99 10,05 1360 102,0 Vestas V80 (2 MW offshore)(Tab #1)
14 424711 6149774 67,0 9,99 10,05 1360 102,0 Vestas V80 (2 MW offshore)(Tab #1)
15 424770 6149216 67,0 9,99 10,05 1360 102,0 Vestas V80 (2 MW offshore)(Tab #1)
16 424829 6148658 67,0 9,99 10,05 1354 101,5 Vestas V80 (2 MW offshore)(Tab #1)
17 424888 6148101 67,0 9,99 10,03 1347 101,0 Vestas V80 (2 MW offshore)(Tab #1)
18 424947 6147543 67,0 9,99 10,01 1341 100,5 Vestas V80 (2 MW offshore)(Tab #1)
21 425094 6151447 67,0 9,99 9,20 1065 79,8 Vestas V80 (2 MW offshore)(Tab #1)
22 425153 6150889 67,0 9,99 9,23 1079 80,9 Vestas V80 (2 MW offshore)(Tab #1)
23 425212 6150332 67,0 9,99 9,22 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
24 425271 6149774 67,0 9,99 9,22 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
25 425330 6149216 67,0 9,99 9,23 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
26 425389 6148658 67,0 9,99 9,23 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
27 425448 6148101 67,0 9,99 9,19 1058 79,3 Vestas V80 (2 MW offshore)(Tab #1)
28 425507 6147543 67,0 9,99 10,03 1347 101,0 Vestas V80 (2 MW offshore)(Tab #1)
31 425654 6151447 67,0 9,99 9,22 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
32 425713 6150889 67,0 9,99 9,25 1079 80,9 Vestas V80 (2 MW offshore)(Tab #1)
33 425772 6150332 67,0 9,99 9,24 1079 80,9 Vestas V80 (2 MW offshore)(Tab #1)
34 425831 6149774 67,0 9,99 9,24 1079 80,9 Vestas V80 (2 MW offshore)(Tab #1)
35 425890 6149216 67,0 9,99 9,23 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
36 425950 6148659 67,0 9,99 9,22 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
37 426009 6148101 67,0 9,99 9,20 1065 79,8 Vestas V80 (2 MW offshore)(Tab #1)
38 426068 6147543 67,0 9,99 10,03 1354 101,5 Vestas V80 (2 MW offshore)(Tab #1)
41 426214 6151447 67,0 9,99 9,10 1031 77,2 Vestas V80 (2 MW offshore)(Tab #1)
42 426273 6150889 67,0 9,99 9,13 1037 77,8 Vestas V80 (2 MW offshore)(Tab #1)
43 426332 6150332 67,0 9,99 9,11 1037 77,8 Vestas V80 (2 MW offshore)(Tab #1)
44 426392 6149774 67,0 9,99 9,12 1037 77,8 Vestas V80 (2 MW offshore)(Tab #1)
45 426451 6149216 67,0 9,99 9,11 1037 77,8 Vestas V80 (2 MW offshore)(Tab #1)
46 426510 6148659 67,0 9,99 9,08 1024 76,7 Vestas V80 (2 MW offshore)(Tab #1)
47 426569 6148101 67,0 9,99 9,22 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
48 426628 6147543 67,0 9,99 10,04 1354 101,5 Vestas V80 (2 MW offshore)(Tab #1)
51 426774 6151447 67,0 9,99 9,00 996 74,7 Vestas V80 (2 MW offshore)(Tab #1)
52 426833 6150889 67,0 9,99 9,03 1010 75,7 Vestas V80 (2 MW offshore)(Tab #1)
53 426892 6150332 67,0 9,99 9,02 1003 75,2 Vestas V80 (2 MW offshore)(Tab #1)
54 426952 6149774 67,0 9,99 9,02 1003 75,2 Vestas V80 (2 MW offshore)(Tab #1)
55 427011 6149216 67,0 9,99 9,01 1003 75,2 Vestas V80 (2 MW offshore)(Tab #1)
56 427070 6148659 67,0 9,99 9,09 1024 76,7 Vestas V80 (2 MW offshore)(Tab #1)
57 427129 6148101 67,0 9,99 9,21 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
58 427189 6147543 67,0 9,99 10,04 1354 101,5 Vestas V80 (2 MW offshore)(Tab #1)
61 427334 6151447 67,0 9,99 8,98 990 74,2 Vestas V80 (2 MW offshore)(Tab #1)
62 427393 6150889 67,0 9,99 9,00 996 74,7 Vestas V80 (2 MW offshore)(Tab #1)
63 427453 6150332 67,0 9,99 8,99 996 74,7 Vestas V80 (2 MW offshore)(Tab #1)
64 427512 6149774 67,0 9,99 8,98 990 74,2 Vestas V80 (2 MW offshore)(Tab #1)
65 427571 6149216 67,0 9,99 8,97 990 74,2 Vestas V80 (2 MW offshore)(Tab #1)
66 427631 6148659 67,0 9,99 9,11 1031 77,2 Vestas V80 (2 MW offshore)(Tab #1)
67 427690 6148101 67,0 9,99 9,23 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
68 427749 6147543 67,0 9,99 10,04 1354 101,5 Vestas V80 (2 MW offshore)(Tab #1)
71 427894 6151447 67,0 9,99 8,76 924 69,3 Vestas V80 (2 MW offshore)(Tab #1)
72 427953 6150889 67,0 9,99 8,79 936 70,2 Vestas V80 (2 MW offshore)(Tab #1)
73 428013 6150332 67,0 9,99 8,77 930 69,7 Vestas V80 (2 MW offshore)(Tab #1)
74 428072 6149774 67,0 9,99 8,76 924 69,3 Vestas V80 (2 MW offshore)(Tab #1)
75 428132 6149216 67,0 9,99 8,99 996 74,7 Vestas V80 (2 MW offshore)(Tab #1)
76 428191 6148659 67,0 9,99 9,11 1031 77,2 Vestas V80 (2 MW offshore)(Tab #1)
77 428250 6148101 67,0 9,99 9,22 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
78 428310 6147543 67,0 9,99 10,04 1354 101,5 Vestas V80 (2 MW offshore)(Tab #1)
81 428454 6151447 67,0 9,99 8,75 918 68,8 Vestas V80 (2 MW offshore)(Tab #1)
82 428513 6150889 67,0 9,99 8,77 924 69,3 Vestas V80 (2 MW offshore)(Tab #1)
83 428573 6150332 67,0 9,99 8,75 924 69,3 Vestas V80 (2 MW offshore)(Tab #1)
84 428632 6149774 67,0 9,99 8,75 924 69,3 Vestas V80 (2 MW offshore)(Tab #1)
85 428692 6149216 67,0 9,99 8,99 996 74,7 Vestas V80 (2 MW offshore)(Tab #1)
86 428751 6148659 67,0 9,99 9,10 1031 77,2 Vestas V80 (2 MW offshore)(Tab #1)
87 428811 6148101 67,0 9,99 9,23 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
88 428870 6147543 67,0 9,99 10,04 1354 101,5 Vestas V80 (2 MW offshore)(Tab #1)
91 429014 6151447 67,0 9,99 8,50 846 63,4 Vestas V80 (2 MW offshore)(Tab #1)
92 429074 6150889 67,0 9,99 8,52 852 63,9 Vestas V80 (2 MW offshore)(Tab #1)
93 429133 6150332 67,0 9,99 8,49 846 63,4 Vestas V80 (2 MW offshore)(Tab #1)
94 429193 6149774 67,0 9,99 8,75 924 69,3 Vestas V80 (2 MW offshore)(Tab #1)
95 429252 6149216 67,0 9,99 9,00 996 74,7 Vestas V80 (2 MW offshore)(Tab #1)
96 429312 6148659 67,0 9,99 9,11 1037 77,8 Vestas V80 (2 MW offshore)(Tab #1)
97 429371 6148101 67,0 9,99 9,22 1072 80,3 Vestas V80 (2 MW offshore)(Tab #1)
98 429431 6147543 67,0 9,99 10,04 1354 101,5 Vestas V80 (2 MW offshore)(Tab #1)
\ No newline at end of file
wrf_HRI 173 183 0 0.0004 <coordinates>7.83191,55.48940,0.0</coordinates>
1 1 12
0.000 0.030 0.100 0.400 1.500
70.0
3.597152 3.948682 5.167395 7.000154 8.364547 6.43485 8.643194 11.77051 15.15757 14.73792 10.01205 5.165975
9.176929 9.782334 9.531809 9.909545 10.04269 9.593921 9.584007 10.51499 11.39895 11.68746 11.63732 10.08803
2.392578 2.447266 2.412109 2.591797 2.755859 2.595703 2.583984 2.548828 2.470703 2.607422 2.626953 2.326172
\ No newline at end of file
'''
Created on 25. apr. 2018
@author: mmpe
'''
import unittest
import numpy as np
from topfarm.tests.test_files import testfilepath
from topfarm.cost_models.fuga import py_fuga, lib_reader
from topfarm.cost_models.fuga.lib_reader import read_lib
class Test(unittest.TestCase):
def test_lib_reader(self):
f, A, k = read_lib(testfilepath + "wind_resources/hornsrev2.lib")
np.testing.assert_array_almost_equal(f, [0.035972, 0.039487, 0.051674, 0.070002, 0.083645, 0.064349,
0.086432, 0.117705, 0.151576, 0.147379, 0.100121, 0.05166])
np.testing.assert_array_almost_equal(A, [9.176929, 9.782334, 9.531809, 9.909545, 10.04269, 9.593921,
9.584007, 10.51499, 11.39895, 11.68746, 11.63732, 10.08803])
np.testing.assert_array_almost_equal(k, [2.392578, 2.447266, 2.412109, 2.591797, 2.755859, 2.595703,
2.583984, 2.548828, 2.470703, 2.607422, 2.626953, 2.326172])
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.test_lib_reader']
unittest.main()
import os
import threading
import time
import numpy as np
import pytest
from topfarm.cost_models.fuga.pascal_dll import PascalDLL
from topfarm.cost_models.fuga.py_fuga import PyFuga, fugalib_path
import os
from topfarm.cost_models.fuga import py_fuga
from topfarm import TopFarm
import pytest
fuga_path = os.path.abspath(os.path.dirname(py_fuga.__file__)) + '/Colonel/'
import numpy as np
from topfarm import TopFarm
from topfarm.cost_models import fuga
def check_lib_exists():
if not os.path.isdir(os.path.dirname(fuga.__file__) + "/Colonel/py_colonel/"):
pytest.xfail("Colonel submodule not found\n")
from topfarm.cost_models.fuga.Colonel.py_colonel.py_colonel_lib import fugalib_path
if os.path.isfile(fugalib_path) is False:
pytest.xfail("Fugalib '%s' not found\n" % fugalib_path)
......@@ -21,6 +21,7 @@ def check_lib_exists():
def get_fuga():
def _fuga(tb_x=[423974, 424033], tb_y=[6151447, 6150889]):
check_lib_exists()
from topfarm.cost_models.fuga.py_fuga import PyFuga, fuga_path
pyFuga = PyFuga()
pyFuga.setup(farm_name='Horns Rev 1',
turbine_model_path=fuga_path + 'LUTs-T/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=70.00]',
......@@ -47,6 +48,8 @@ def _test_parallel(i):
def testCheckVersion(get_fuga):
check_lib_exists()
from topfarm.cost_models.fuga.Colonel.py_colonel.py_colonel_lib import fugalib_path, PascalDLL
from topfarm.cost_models.fuga.py_fuga import fuga_path
lib = PascalDLL(fuga_path + "FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt'])
with pytest.raises(Exception, match="This version of FugaLib supports interface version "):
lib.CheckInterfaceVersion(1)
......@@ -104,6 +107,7 @@ def testAEP_topfarm(get_fuga):
def test_pyfuga_cmd():
check_lib_exists()
from topfarm.cost_models.fuga.py_fuga import PyFuga
pyFuga = PyFuga()
pyFuga.execute(r'echo "ColonelInit"')
assert pyFuga.log.strip().split("\n")[-1] == 'ColonelInit'
......
'''
Created on 14. maj 2018
@author: mmpe
'''
import unittest
import numpy as np
from topfarm.tests.test_files import tfp
from topfarm.tests.test_fuga.test_pyfuga import fuga_path
from topfarm.cost_models.fuga.turbine_site_list_reader import read_turbine_site_list,\
read_MR_turbine_site_list
class TestTurbineSiteListReader(unittest.TestCase):
def testRead(self):
model, ids, pos = read_turbine_site_list(tfp + "fuga_files/TurbineSiteList.txt")
self.assertEqual(model, "Vestas_V80_(2_MW_offshore)[h=67.00]")
self.assertEqual(ids[-1], "98")
np.testing.assert_array_equal(pos[-1], [429431, 6147543, 67])
def testMRRead(self):
farm_name, nacelle_models, pos = read_MR_turbine_site_list(tfp + "fuga_files/4xV52SiteList.txt")
self.assertEqual(farm_name, "4xV52Farm")
name, (z, arm) = nacelle_models[0]
self.assertEqual(name, "V52-0.85MWLower[h=50.00]")
self.assertEqual(z, 50)
self.assertEqual(arm, 30)
np.testing.assert_array_equal(pos[0], [-8879, 2367])
np.testing.assert_array_equal(pos[-1], [-3553., -2250.])
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment