diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3f8b4d3f68841c6d4d3a0d9247d628114eb5c08e..bac7087e6cf07a45826e2000d5f15a178d817206 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,6 +8,7 @@ test_topfarm: # name the job what we like stage: # build, test, deploy defined by default [2] test script: + - pip install --upgrade git+git://github.com/FUSED-Wind/FUSED-Wake@master - cd tests; py.test tags: # only runners with this tag can do the job [3] - python diff --git a/tests/test_costmodel_utils/test_aep_calculator.py b/tests/test_costmodel_utils/test_aep_calculator.py index 88823c6e569e524309b438e335887e7a7f72743d..64f653f1da2a6bebfdf64f669715efda8b9746b3 100644 --- a/tests/test_costmodel_utils/test_aep_calculator.py +++ b/tests/test_costmodel_utils/test_aep_calculator.py @@ -10,6 +10,7 @@ from topfarm.cost_models.utils.wind_resource import WindResource from tests.test_files import testfilepath from topfarm.cost_models.fused_wake_wrappers import FusedWakeGCLWakeModel from topfarm.cost_models.utils.aep_calculator import AEPCalculator +import warnings class TestAEPCalculator(unittest.TestCase): @@ -20,10 +21,11 @@ class TestAEPCalculator(unittest.TestCase): k = [2.392578,2,2,2] wr = WindResource(np.array(f), A, k, ti=np.zeros_like(f) + .1) wf_3tb = testfilepath + "wind_farms/3tb.yml" - wm = FusedWakeGCLWakeModel(wf_3tb) - aep_calc = AEPCalculator(wr, wm) - - self.assertAlmostEqual(aep_calc(np.array([[-1600, 0, 1600], [0, 0, 0]]).T), 22.3178800761) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + wm = FusedWakeGCLWakeModel(wf_3tb) + aep_calc = AEPCalculator(wr, wm) + self.assertAlmostEqual(aep_calc(np.array([[-1600, 0, 1600], [0, 0, 0]]).T), 22.3178800761) if __name__ == "__main__": diff --git a/tests/test_fusedwake_models/test_gcl.py b/tests/test_fusedwake_models/test_gcl.py index 0a8bf30aff988a340525921a2a7c7c1e920aa075..f1afc4e5f5e86fbf8fd18fb3babc05c741c1c7f4 100644 --- a/tests/test_fusedwake_models/test_gcl.py +++ b/tests/test_fusedwake_models/test_gcl.py @@ -5,6 +5,7 @@ from topfarm.cost_models.utils.wind_resource import WindResource from tests.test_files import tfp from topfarm._topfarm import TopFarm import pytest +import warnings @pytest.fixture() @@ -14,24 +15,32 @@ def aep_calc(): A = [9.176929, 9.782334, 9.531809, 9.909545] k = [2.392578, 2.447266, 2.412109, 2.591797] wr = WindResource(f, A, k, ti=np.zeros_like(f) + .1) - wm = FusedWakeGCLWakeModel(tfp + "wind_farms/3tb.yml") + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + wm = FusedWakeGCLWakeModel(tfp + "wind_farms/3tb.yml") return AEPCalculator(wr, wm) def test_input_shape_must_be_equal(): - wm = FusedWakeGCLWakeModel(tfp + "wind_farms/3tb.yml") - with pytest.raises(AssertionError, message="Shape of no_wake_wdir, no_wake_wsp and no_wake_ti must equal"): - wm(wm.windFarm.pos.T, no_wake_wdir=[[270]], no_wake_wsp=[[8, 9]], no_wake_ti=0.1) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + wm = FusedWakeGCLWakeModel(tfp + "wind_farms/3tb.yml") + with pytest.raises(AssertionError, message="Shape of no_wake_wdir, no_wake_wsp and no_wake_ti must equal"): + wm(wm.windFarm.pos.T, no_wake_wdir=[[270]], no_wake_wsp=[[8, 9]], no_wake_ti=0.1) def test_GCL(aep_calc): init_pos = aep_calc.wake_model.windFarm.pos.T - assert aep_calc(init_pos) == 19.85973533524627 # tb aligned north-south -> wake - assert aep_calc(np.array([[-500, 0, 500], [0, 0, 0]]).T) == 22.31788007605505 # tb aligned West-East -> no wake + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + assert aep_calc(init_pos) == 19.85973533524627 # tb aligned north-south -> wake + assert aep_calc(np.array([[-500, 0, 500], [0, 0, 0]]).T) == 22.31788007605505 # tb aligned West-East -> no wake def test_GCL_Topfarm(aep_calc): - init_pos = aep_calc.wake_model.windFarm.pos.T - tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square') - tf.evaluate() + init_pos = aep_calc.wake_model.windFarm.pos + with warnings.catch_warnings(): # suppress "warning, make sure that this position array is oriented in ndarray([n_wt, 2]) or ndarray([n_wt, 3])" + warnings.simplefilter("ignore") + tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square') + tf.evaluate() assert tf.get_cost() == -19.85973533524627 diff --git a/tests/test_fusedwake_models/test_noj.py b/tests/test_fusedwake_models/test_noj.py index 703a26a660074915ac1d2fcabd3c673c65d096fb..194485fe7e23d7ffb1030b68960e381d98e78cba 100644 --- a/tests/test_fusedwake_models/test_noj.py +++ b/tests/test_fusedwake_models/test_noj.py @@ -6,6 +6,7 @@ from topfarm._topfarm import TopFarm from topfarm.cost_models.fused_wake_wrappers import FusedWakeNOJWakeModel from topfarm.cost_models.utils.aep_calculator import AEPCalculator from topfarm.cost_models.utils.wind_resource import WindResource +import warnings @pytest.fixture() @@ -15,18 +16,24 @@ def aep_calc(): A = [9.176929, 9.782334, 9.531809, 9.909545] k = [2.392578, 2.447266, 2.412109, 2.591797] wr = WindResource(f, A, k, ti=np.zeros_like(f) + .1) - wm = FusedWakeNOJWakeModel(tfp + "wind_farms/3tb.yml") + with warnings.catch_warnings(): # suppress "warning, make sure that this position array is oriented in ndarray([n_wt, 2]) or ndarray([n_wt, 3])" + warnings.simplefilter("ignore") + wm = FusedWakeNOJWakeModel(tfp + "wind_farms/3tb.yml") return AEPCalculator(wr, wm) -def test_GCL(aep_calc): - init_pos = aep_calc.wake_model.windFarm.pos.T - assert aep_calc(init_pos) == 18.90684500124578 - assert aep_calc(np.array([[-500, 0, 500], [0, 0, 0]]).T) == 22.31788007605505 +def test_NOJ(aep_calc): + init_pos = aep_calc.wake_model.windFarm.pos + with warnings.catch_warnings(): # suppress "warning, make sure that this position array is oriented in ndarray([n_wt, 2]) or ndarray([n_wt, 3])" + warnings.simplefilter("ignore") + assert aep_calc(init_pos) == 18.90684500124578 + assert aep_calc(np.array([[-500, 0, 500], [0, 0, 0]]).T) == 22.31788007605505 -def test_GCL_Topfarm(aep_calc): - init_pos = aep_calc.wake_model.windFarm.pos.T - tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square') - tf.evaluate() +def test_NOJ_Topfarm(aep_calc): + init_pos = aep_calc.wake_model.windFarm.pos + with warnings.catch_warnings(): # suppress "warning, make sure that this position array is oriented in ndarray([n_wt, 2]) or ndarray([n_wt, 3])" + warnings.simplefilter("ignore") + tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square') + tf.evaluate() assert tf.get_cost() == -18.90684500124578 diff --git a/topfarm/cost_models/fused_wake_wrappers.py b/topfarm/cost_models/fused_wake_wrappers.py index 18dd10d023d59409b0e81f1941560828358fbca2..c09705ec54424b889bd719c7d55914ba8cc9cd91 100644 --- a/topfarm/cost_models/fused_wake_wrappers.py +++ b/topfarm/cost_models/fused_wake_wrappers.py @@ -23,13 +23,12 @@ class FusedWakeModel(object): self.windFarm = WindFarm(yml=yml) if version: self.version = version - try: - self.wake_model = self.wake_model_cls(WF=self.windFarm, version=self.version, **kwargs) - except ValueError as e: - pytest.xfail(str(e)) - + self.wake_model = self.wake_model_cls(WF=self.windFarm, version=self.version, **kwargs) + def __call__(self, turbine_positions, no_wake_wdir, no_wake_wsp, no_wake_ti): - self.wake_model.update_position(turbine_positions.T) + if not hasattr(self.wake_model, 'update_position'): + pytest.xfail("Method update_position missing in wakemodel") + self.wake_model.update_position(turbine_positions) WD, WS, TI = (np.atleast_2d(v) for v in [no_wake_wdir, no_wake_wsp, no_wake_ti]) assert WD.shape == WS.shape == TI.shape, "Shape of no_wake_wdir, no_wake_wsp and no_wake_ti must equal: %s != %s != %s" % (WD.shape, WS.shape, TI.shape) if len(WD.shape) == 3: