|
1 | | -from twoaxistracking import layout |
| 1 | +from twoaxistracking import layout, twoaxistrackerfield |
2 | 2 | from shapely import geometry |
3 | 3 | import numpy as np |
4 | 4 | import pytest |
|
8 | 8 | def rectangular_geometry(): |
9 | 9 | collector_geometry = geometry.box(-2, -1, 2, 1) |
10 | 10 | total_collector_area = collector_geometry.area |
11 | | - l_min = layout._calculate_l_min(collector_geometry) |
12 | | - return collector_geometry, total_collector_area, l_min |
| 11 | + min_tracker_spacing = layout._calculate_min_tracker_spacing(collector_geometry) |
| 12 | + return collector_geometry, total_collector_area, min_tracker_spacing |
13 | 13 |
|
14 | 14 |
|
15 | 15 | @pytest.fixture |
16 | 16 | def square_field_layout(): |
17 | 17 | # Corresponds to GCR 0.125 with the rectangular_geometry |
18 | | - X = np.array([-8., 0., 8., -8., 8., -8., 0., 8.]) |
19 | | - Y = np.array([-8., -8., -8., 0., 0., 8., 8., 8.]) |
| 18 | + X = np.array([-8, 0, 8, -8, 8, -8, 0, 8]) |
| 19 | + Y = np.array([-8, -8, -8, 0, 0, 8, 8, 8]) |
20 | 20 | tracker_distance = (X**2 + Y**2)**0.5 |
21 | | - relative_azimuth = np.array([225., 180., 135., 270., 90., 315., 0., 45.]) |
| 21 | + relative_azimuth = np.array([225, 180, 135, 270, 90, 315, 0, 45]) |
22 | 22 | Z = np.zeros(8) |
23 | 23 | relative_slope = np.zeros(8) |
24 | 24 | return X, Y, Z, tracker_distance, relative_azimuth, relative_slope |
25 | 25 |
|
26 | 26 |
|
27 | | -def test_l_min_rectangle(rectangular_geometry): |
28 | | - # Test calculation of L_min for a rectangular collector |
29 | | - l_min = layout._calculate_l_min(rectangular_geometry[0]) |
30 | | - assert l_min == np.sqrt(4**2+2**2) |
| 27 | +def test_min_tracker_spacing_rectangle(rectangular_geometry): |
| 28 | + # Test calculation of min_tracker_spacing for a rectangular collector |
| 29 | + min_tracker_spacing = layout._calculate_min_tracker_spacing(rectangular_geometry[0]) |
| 30 | + assert min_tracker_spacing == np.sqrt(4**2+2**2) |
31 | 31 |
|
32 | 32 |
|
33 | | -def test_l_min_circle(): |
34 | | - # Test calculation of L_min for a circular collector with radius 1 |
| 33 | +def test_min_tracker_spacing_circle(): |
| 34 | + # Test calculation of min_tracker_spacing for a circular collector with radius 1 |
35 | 35 | collector_geometry = geometry.Point(0, 0).buffer(1) |
36 | | - l_min = layout._calculate_l_min(collector_geometry) |
37 | | - assert l_min == 2 |
| 36 | + min_tracker_spacing = layout._calculate_min_tracker_spacing(collector_geometry) |
| 37 | + assert min_tracker_spacing == 2 |
38 | 38 |
|
39 | 39 |
|
40 | | -def test_l_min_circle_offcenter(): |
41 | | - # Test calculation of L_min for a circular collector with radius 1 rotating |
| 40 | +def test_min_tracker_spacing_circle_offcenter(): |
| 41 | + # Test calculation of min_tracker_spacing for a circular collector with radius 1 rotating |
42 | 42 | # off-center around the point (0, 1) |
43 | 43 | collector_geometry = geometry.Point(0, 1).buffer(1) |
44 | | - l_min = layout._calculate_l_min(collector_geometry) |
45 | | - assert l_min == 4 |
| 44 | + min_tracker_spacing = layout._calculate_min_tracker_spacing(collector_geometry) |
| 45 | + assert min_tracker_spacing == 4 |
46 | 46 |
|
47 | 47 |
|
48 | | -def test_l_min_polygon(): |
49 | | - # Test calculation of L_min for a polygon |
| 48 | +def test_min_tracker_spacingpolygon(): |
| 49 | + # Test calculation of min_tracker_spacing for a polygon |
50 | 50 | collector_geometry = geometry.Polygon([(-1, -1), (3, 2), (4, 4), (1, 2), (-1, -1)]) |
51 | | - l_min = layout._calculate_l_min(collector_geometry) |
52 | | - assert l_min == 2 * np.sqrt(4**2 + 4**2) |
| 51 | + min_tracker_spacing = layout._calculate_min_tracker_spacing(collector_geometry) |
| 52 | + assert min_tracker_spacing == 2 * np.sqrt(4**2 + 4**2) |
53 | 53 |
|
54 | 54 |
|
55 | | -def test_square_layout_generation(rectangular_geometry): |
56 | | - # Test square field layout defined using tje built-in layout types |
57 | | - collector_geometry, total_collector_area, L_min = rectangular_geometry |
| 55 | +def test_square_layout_generation(rectangular_geometry, square_field_layout): |
| 56 | + # Test that a square field layout is returned correctly |
| 57 | + collector_geometry, total_collector_area, min_tracker_spacing = rectangular_geometry |
| 58 | + X_exp, Y_exp, Z_exp, tracker_distance_exp, relative_azimuth_exp, relative_slope_exp = \ |
| 59 | + square_field_layout |
58 | 60 |
|
59 | 61 | X, Y, Z, tracker_distance, relative_azimuth, relative_slope = \ |
60 | 62 | layout.generate_field_layout( |
61 | | - gcr=0.25, total_collector_area=total_collector_area, L_min=L_min, |
62 | | - neighbor_order=1, layout_type='square', |
63 | | - slope_azimuth=0, slope_tilt=0, plot=False) |
64 | | - assert np.isclose(X, np.array([-5.65685425, 0, 5.65685425, -5.65685425, |
65 | | - 5.65685425, -5.65685425, 0, 5.65685425]) |
66 | | - ).all() |
| 63 | + gcr=0.125, |
| 64 | + total_collector_area=total_collector_area, |
| 65 | + min_tracker_spacing=min_tracker_spacing, |
| 66 | + neighbor_order=1, |
| 67 | + aspect_ratio=1, |
| 68 | + offset=0, |
| 69 | + rotation=0) |
| 70 | + assert (X == X_exp).all() |
| 71 | + assert (Y == Y_exp).all() |
| 72 | + assert (Z == Z_exp).all() |
| 73 | + assert (tracker_distance_exp == tracker_distance_exp).all() |
| 74 | + assert (relative_azimuth == relative_azimuth_exp).all() |
| 75 | + assert (relative_slope == relative_slope_exp).all() |
67 | 76 |
|
68 | 77 |
|
69 | 78 | def test_layout_generation_value_error(rectangular_geometry): |
70 | 79 | # Test if value errors are correctly raised |
71 | | - collector_geometry, total_collector_area, L_min = rectangular_geometry |
72 | | - |
73 | | - # Test if ValueError is raised when an incorrect layout_type is specified |
74 | | - with pytest.raises(ValueError, match="layout type specified was not recognized"): |
75 | | - _ = layout.generate_field_layout( |
76 | | - gcr=0.25, total_collector_area=total_collector_area, L_min=L_min, |
77 | | - neighbor_order=1, layout_type='this_is_not_a_layout_type') |
78 | | - |
79 | | - # Test if ValueError is raised if too few layout parameters are specified |
80 | | - with pytest.raises(ValueError, match="no layout type has not been selected"): |
81 | | - _ = layout.generate_field_layout( |
82 | | - gcr=0.25, total_collector_area=total_collector_area, L_min=L_min, |
83 | | - neighbor_order=1, rotation=0) |
| 80 | + collector_geometry, total_collector_area, min_tracker_spacing = rectangular_geometry |
84 | 81 |
|
85 | 82 | # Test if ValueError is raised if offset is out of range |
86 | 83 | with pytest.raises(ValueError, match="offset is outside the valid range"): |
87 | 84 | _ = layout.generate_field_layout( |
88 | | - gcr=0.25, total_collector_area=total_collector_area, L_min=L_min, |
89 | | - neighbor_order=1, rotation=0, offset=1.1, aspect_ratio=1) |
| 85 | + gcr=0.25, total_collector_area=total_collector_area, |
| 86 | + min_tracker_spacing=min_tracker_spacing, neighbor_order=1, |
| 87 | + aspect_ratio=1, offset=1.1, rotation=0) |
90 | 88 |
|
91 | 89 | # Test if ValueError is raised if aspect ratio is too low |
92 | 90 | with pytest.raises(ValueError, match="Aspect ratio is too low"): |
93 | 91 | _ = layout.generate_field_layout( |
94 | | - gcr=0.25, total_collector_area=total_collector_area, L_min=L_min, |
95 | | - neighbor_order=1, rotation=0, offset=0, aspect_ratio=0.6) |
| 92 | + gcr=0.25, total_collector_area=total_collector_area, |
| 93 | + min_tracker_spacing=min_tracker_spacing, neighbor_order=1, |
| 94 | + aspect_ratio=0.6, offset=0, rotation=0) |
96 | 95 |
|
97 | 96 | # Test if ValueError is raised if aspect ratio is too high |
98 | 97 | with pytest.raises(ValueError, match="Aspect ratio is too high"): |
99 | 98 | _ = layout.generate_field_layout( |
100 | | - gcr=0.25, total_collector_area=total_collector_area, L_min=L_min, |
101 | | - neighbor_order=1, rotation=0, offset=0, aspect_ratio=5) |
| 99 | + gcr=0.25, total_collector_area=total_collector_area, |
| 100 | + min_tracker_spacing=min_tracker_spacing, neighbor_order=1, |
| 101 | + aspect_ratio=5, offset=0, rotation=0) |
102 | 102 |
|
103 | | - # Test if ValueError is raised if rotation is outside valid range |
| 103 | + # Test if ValueError is raised if rotation is greater than 180 degrees |
104 | 104 | with pytest.raises(ValueError, match="rotation is outside the valid range"): |
105 | 105 | _ = layout.generate_field_layout( |
106 | | - gcr=0.25, total_collector_area=total_collector_area, L_min=L_min, |
107 | | - neighbor_order=1, rotation=190, offset=0, aspect_ratio=1.2) |
| 106 | + gcr=0.25, total_collector_area=total_collector_area, |
| 107 | + min_tracker_spacing=min_tracker_spacing, neighbor_order=1, |
| 108 | + aspect_ratio=1.2, offset=0, rotation=190) |
108 | 109 |
|
109 | | - # Test if ValueError is raised if L_min is outside valid range |
| 110 | + # Test if ValueError is raised if rotation is less than 0 |
| 111 | + with pytest.raises(ValueError, match="rotation is outside the valid range"): |
| 112 | + _ = layout.generate_field_layout( |
| 113 | + gcr=0.5, total_collector_area=total_collector_area, |
| 114 | + min_tracker_spacing=min_tracker_spacing, neighbor_order=1, |
| 115 | + aspect_ratio=1, offset=0, rotation=-1) |
| 116 | + |
| 117 | + # Test if ValueError is raised if min_tracker_spacing is outside valid range |
110 | 118 | with pytest.raises(ValueError, match="Lmin is not physically possible"): |
111 | 119 | _ = layout.generate_field_layout( |
112 | | - gcr=0.25, total_collector_area=total_collector_area, L_min=1, |
113 | | - neighbor_order=1, rotation=90, offset=0, aspect_ratio=1.2) |
| 120 | + gcr=0.25, total_collector_area=total_collector_area, |
| 121 | + min_tracker_spacing=1, neighbor_order=1, aspect_ratio=1.2, |
| 122 | + offset=0, rotation=90) |
114 | 123 |
|
115 | | - # Test if ValueError is raised if rotation is outside valid range |
| 124 | + # Test if ValueError is raised if maximum ground cover ratio is exceeded |
116 | 125 | with pytest.raises(ValueError, match="Maximum ground cover ratio exceded"): |
117 | 126 | _ = layout.generate_field_layout( |
118 | | - gcr=0.5, total_collector_area=total_collector_area, L_min=L_min, |
119 | | - neighbor_order=1, rotation=0, offset=0, aspect_ratio=1) |
| 127 | + gcr=0.5, total_collector_area=total_collector_area, |
| 128 | + min_tracker_spacing=min_tracker_spacing, neighbor_order=1, |
| 129 | + aspect_ratio=1, offset=0, rotation=0) |
120 | 130 |
|
121 | 131 |
|
122 | | -def test_square_field_layout(rectangular_geometry, square_field_layout): |
123 | | - # Test that a square field layout is returned correctly |
124 | | - collector_geometry, total_collector_area, L_min = rectangular_geometry |
125 | | - X_exp, Y_exp, Z_exp, tracker_distance_exp, relative_azimuth_exp, relative_slope_exp = \ |
126 | | - square_field_layout |
| 132 | +def test_field_slope(): |
| 133 | + assert True |
127 | 134 |
|
| 135 | + |
| 136 | +def test_neighbor_order(rectangular_geometry): |
| 137 | + collector_geometry, total_collector_area, min_tracker_spacing = rectangular_geometry |
128 | 138 | X, Y, Z, tracker_distance, relative_azimuth, relative_slope = \ |
129 | 139 | layout.generate_field_layout( |
130 | 140 | gcr=0.125, |
131 | 141 | total_collector_area=total_collector_area, |
132 | | - L_min=L_min, |
133 | | - neighbor_order=1, |
134 | | - layout_type='square') |
| 142 | + min_tracker_spacing=min_tracker_spacing, |
| 143 | + neighbor_order=3, |
| 144 | + aspect_ratio=1, |
| 145 | + offset=0, |
| 146 | + rotation=0) |
| 147 | + assert len(X) == (7*7-1) |
135 | 148 |
|
136 | | -# Test custom layout |
137 | 149 | # Test slope |
138 | 150 | # Test neighbor order |
139 | 151 |
|
|
0 commit comments