From eb758890ce9098625635fe4bca2776054792ae4d Mon Sep 17 00:00:00 2001
From: "Mads M. Pedersen" <mmpe@dtu.dk>
Date: Wed, 16 May 2018 14:55:35 +0200
Subject: [PATCH] Fuga turbine_site_list_reader + test

---
 tests/test_files/fuga_files/4xV52SiteList.txt | 54 +++++++++++++
 .../test_files/fuga_files/TurbineSiteList.txt | 81 +++++++++++++++++++
 .../test_turbine_site_list_reader.py          | 36 +++++++++
 topfarm/cost_models/fuga/py_fuga.py           |  2 +-
 .../fuga/turbine_site_list_reader.py          | 23 ++++++
 5 files changed, 195 insertions(+), 1 deletion(-)
 create mode 100644 tests/test_files/fuga_files/4xV52SiteList.txt
 create mode 100644 tests/test_files/fuga_files/TurbineSiteList.txt
 create mode 100644 tests/test_fuga/test_turbine_site_list_reader.py
 create mode 100644 topfarm/cost_models/fuga/turbine_site_list_reader.py

diff --git a/tests/test_files/fuga_files/4xV52SiteList.txt b/tests/test_files/fuga_files/4xV52SiteList.txt
new file mode 100644
index 00000000..5fcefec4
--- /dev/null
+++ b/tests/test_files/fuga_files/4xV52SiteList.txt
@@ -0,0 +1,54 @@
+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
diff --git a/tests/test_files/fuga_files/TurbineSiteList.txt b/tests/test_files/fuga_files/TurbineSiteList.txt
new file mode 100644
index 00000000..03f2e5aa
--- /dev/null
+++ b/tests/test_files/fuga_files/TurbineSiteList.txt
@@ -0,0 +1,81 @@
+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
diff --git a/tests/test_fuga/test_turbine_site_list_reader.py b/tests/test_fuga/test_turbine_site_list_reader.py
new file mode 100644
index 00000000..0be6f8bf
--- /dev/null
+++ b/tests/test_fuga/test_turbine_site_list_reader.py
@@ -0,0 +1,36 @@
+'''
+Created on 14. maj 2018
+
+@author: mmpe
+'''
+import unittest
+
+import numpy as np
+from tests.test_files import tfp
+from 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()
diff --git a/topfarm/cost_models/fuga/py_fuga.py b/topfarm/cost_models/fuga/py_fuga.py
index a7e8f8be..6a8de07b 100644
--- a/topfarm/cost_models/fuga/py_fuga.py
+++ b/topfarm/cost_models/fuga/py_fuga.py
@@ -78,7 +78,7 @@ class PyFuga(object):
         return no_turbines_p.contents.value
 
     def move_turbines(self, tb_x, tb_y):
-        assert len(tb_x) == len(tb_y) == self.get_no_tubines()
+        assert len(tb_x) == len(tb_y) == self.get_no_tubines(), (len(tb_x) ,len(tb_y), self.get_no_tubines())
         tb_x_ctype = np.array(tb_x, dtype=np.float).ctypes
         tb_y_ctype = np.array(tb_y, dtype=np.float).ctypes
 
diff --git a/topfarm/cost_models/fuga/turbine_site_list_reader.py b/topfarm/cost_models/fuga/turbine_site_list_reader.py
new file mode 100644
index 00000000..31b0c517
--- /dev/null
+++ b/topfarm/cost_models/fuga/turbine_site_list_reader.py
@@ -0,0 +1,23 @@
+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
+
-- 
GitLab