|
12 | 12 | windIO_path = Path(wiop[0]) |
13 | 13 |
|
14 | 14 |
|
15 | | -def _run_foxes(wes_dir): |
| 15 | +def _run_foxes(wes_dir, output_dir): |
| 16 | + """Run FOXES on all system.yaml files in the given directory.""" |
16 | 17 | assert wes_dir.is_dir(), f"{wes_dir} is not a directory" |
17 | 18 |
|
18 | 19 | for yaml_input in wes_dir.glob("system.yaml"): |
19 | 20 | print("\nRUNNING FOXES ON", yaml_input, "\n") |
20 | 21 | validate_yaml(yaml_input, Path("plant/wind_energy_system")) |
21 | | - output_dir_name = Path("output_test_foxes") |
22 | | - output_dir_name.mkdir(parents=True, exist_ok=True) |
23 | | - run_foxes(yaml_input, output_dir=output_dir_name) |
24 | | - rmtree(output_dir_name) |
| 22 | + run_foxes(yaml_input, output_dir=output_dir) |
25 | 23 |
|
26 | 24 |
|
27 | | -def test_foxes_KUL(): |
| 25 | +def test_foxes_KUL(output_dir): |
28 | 26 | wes_dir = test_path / "../examples/cases/KUL_LES/wind_energy_system/" |
29 | | - _run_foxes(wes_dir) |
| 27 | + _run_foxes(wes_dir, output_dir) |
30 | 28 |
|
31 | 29 |
|
32 | | -def test_foxes_4wts(): |
| 30 | +def test_foxes_4wts(output_dir): |
33 | 31 | wes_dir = test_path / "../examples/cases/windio_4turbines/wind_energy_system/" |
34 | | - _run_foxes(wes_dir) |
| 32 | + _run_foxes(wes_dir, output_dir) |
35 | 33 |
|
36 | 34 |
|
37 | | -def test_foxes_abl(): |
| 35 | +def test_foxes_abl(output_dir): |
38 | 36 | wes_dir = test_path / "../examples/cases/windio_4turbines_ABL/wind_energy_system/" |
39 | | - _run_foxes(wes_dir) |
| 37 | + _run_foxes(wes_dir, output_dir) |
40 | 38 |
|
41 | 39 |
|
42 | | -def test_foxes_abl_stable(): |
| 40 | +def test_foxes_abl_stable(output_dir): |
43 | 41 | wes_dir = ( |
44 | 42 | test_path / "../examples/cases/windio_4turbines_ABL_stable/wind_energy_system/" |
45 | 43 | ) |
46 | | - _run_foxes(wes_dir) |
| 44 | + _run_foxes(wes_dir, output_dir) |
47 | 45 |
|
48 | 46 |
|
49 | | -def test_foxes_profiles(): |
| 47 | +def test_foxes_profiles(output_dir): |
50 | 48 | wes_dir = ( |
51 | 49 | test_path |
52 | 50 | / "../examples/cases/windio_4turbines_profiles_stable/wind_energy_system/" |
53 | 51 | ) |
54 | | - _run_foxes(wes_dir) |
| 52 | + _run_foxes(wes_dir, output_dir) |
55 | 53 |
|
56 | 54 |
|
57 | | -def test_foxes_heterogeneous_wind_rose_at_turbines(): |
| 55 | +def test_foxes_heterogeneous_wind_rose_at_turbines(output_dir): |
58 | 56 | wes_dir = ( |
59 | 57 | test_path |
60 | 58 | / "../examples/cases/heterogeneous_wind_rose_at_turbines/wind_energy_system/" |
61 | 59 | ) |
62 | | - _run_foxes(wes_dir) |
| 60 | + _run_foxes(wes_dir, output_dir) |
63 | 61 |
|
64 | 62 |
|
65 | | -def test_foxes_heterogeneous_wind_rose_map(): |
| 63 | +def test_foxes_heterogeneous_wind_rose_map(output_dir): |
66 | 64 | wes_dir = ( |
67 | 65 | test_path / "../examples/cases/heterogeneous_wind_rose_map/wind_energy_system/" |
68 | 66 | ) |
69 | | - _run_foxes(wes_dir) |
| 67 | + _run_foxes(wes_dir, output_dir) |
70 | 68 |
|
71 | 69 |
|
72 | | -def test_foxes_simple_wind_rose(): |
| 70 | +def test_foxes_simple_wind_rose(output_dir): |
73 | 71 | wes_dir = test_path / "../examples/cases/simple_wind_rose/wind_energy_system/" |
74 | | - _run_foxes(wes_dir) |
| 72 | + _run_foxes(wes_dir, output_dir) |
75 | 73 |
|
76 | 74 |
|
77 | | -def test_foxes_timeseries_with_operating_flag(): |
| 75 | +def test_foxes_timeseries_with_operating_flag(output_dir): |
78 | 76 | wes_dir = ( |
79 | 77 | test_path |
80 | 78 | / "../examples/cases/timeseries_with_operating_flag/wind_energy_system/" |
81 | 79 | ) |
82 | | - _run_foxes(wes_dir) |
| 80 | + _run_foxes(wes_dir, output_dir) |
83 | 81 |
|
84 | 82 |
|
85 | | -def test_timeseries_per_turbine_with_density(tmp_path=Path(".")): |
| 83 | +def test_timeseries_per_turbine_with_density(output_dir): |
86 | 84 | import foxes.variables as FV |
87 | 85 | from conftest import make_timeseries_per_turbine_system_dict |
88 | 86 |
|
89 | 87 | # Run with density |
90 | 88 | system_dict = make_timeseries_per_turbine_system_dict("foxes") |
91 | | - output_dir = tmp_path / "output_foxes_ts" |
92 | | - farm_results = run_foxes(system_dict, verbosity=0, output_dir=str(output_dir))[0] |
| 89 | + out_with = output_dir / "output_foxes_ts" |
| 90 | + farm_results = run_foxes(system_dict, verbosity=0, output_dir=str(out_with))[0] |
93 | 91 | farmP_with = farm_results[FV.P].sum() |
94 | | - # print("Farm power with density:", farmP_with) |
95 | 92 | assert np.isfinite(farmP_with) and farmP_with > 0 |
96 | 93 |
|
97 | 94 | # Run without density — same config but density removed |
98 | 95 | system_dict_no = make_timeseries_per_turbine_system_dict("foxes") |
99 | 96 | del system_dict_no["site"]["energy_resource"]["wind_resource"]["density"] |
100 | | - output_dir_no = tmp_path / "output_foxes_ts_no_density" |
| 97 | + out_without = output_dir / "output_foxes_ts_no_density" |
101 | 98 | farm_results_no = run_foxes( |
102 | | - system_dict_no, verbosity=0, output_dir=str(output_dir_no) |
| 99 | + system_dict_no, verbosity=0, output_dir=str(out_without) |
103 | 100 | )[0] |
104 | 101 | farmP_without = farm_results_no[FV.P].sum() |
105 | | - # print("Farm power without density:", farmP_without) |
106 | | - |
107 | | - rmtree(output_dir) |
108 | | - rmtree(output_dir_no) |
109 | 102 |
|
110 | 103 | # Density correction should change AEP (test data varies around 1.225) |
111 | 104 | assert farmP_with != farmP_without |
112 | | - |
113 | | - |
114 | | -if __name__ == "__main__": |
115 | | - test_foxes_KUL() |
116 | | - test_foxes_4wts() |
117 | | - test_foxes_abl() |
118 | | - test_foxes_abl_stable() |
119 | | - test_foxes_profiles() |
120 | | - test_foxes_heterogeneous_wind_rose_at_turbines() |
121 | | - test_foxes_heterogeneous_wind_rose_map() |
122 | | - test_foxes_simple_wind_rose() |
123 | | - test_timeseries_per_turbine_with_density() |
0 commit comments