added field finding test
# You should have received a copy of the Apache-2.0 along with this
# program. If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
+# pylint: disable = protected-access
+
+import pytest
+from hypothesis import given
+from hypothesis.strategies import floats
import numpy as np
@@ -30,10 +35,41 @@ import pymedphys._mocks.profiles
import pymedphys.labs.winstonlutz.findfield
+@pytest.mark.slow
+@given(
+ floats(-20, 20),
+ floats(-20, 20),
+ floats(10, 20),
+ floats(10, 20),
+ floats(0.5, 2),
+ floats(0, 360),
+)
+def test_field_finding(x_centre, y_centre, x_edge, y_edge, penumbra, actual_rotation):
+ edge_lengths = [x_edge, y_edge]
+ actual_centre = [x_centre, y_centre]
+
+ field = pymedphys._mocks.profiles.create_rectangular_field_function(
+ actual_centre, edge_lengths, penumbra, actual_rotation
+ )
+
+ x = np.arange(-50, 50, 0.5)
+ y = np.arange(-50, 50, 0.5)
+ xx, yy = np.meshgrid(x, y)
+ zz = field(xx, yy)
+
+ initial_centre = pymedphys.labs.winstonlutz.findfield._initial_centre(x, y, zz)
+ centre, rotation = pymedphys.labs.winstonlutz.findfield.field_finding_loop(
+ field, edge_lengths, penumbra, initial_centre
+ )
+
+ np.allclose(actual_centre, centre)
+ np.allclose(actual_rotation % 180, rotation)
+
+
def test_find_initial_field_centre():
centre = [20, 5]
- field = pymedphys._mocks.profiles.create_square_field_function( # pylint: disable = protected-access
+ field = pymedphys._mocks.profiles.create_square_field_function(
centre=centre, side_length=10, penumbra_width=1, rotation=20
)
@@ -44,6 +80,6 @@ def test_find_initial_field_centre():
zz = field(xx, yy)
- initial_centre = pymedphys.labs.winstonlutz.findfield.initial_centre(x, y, zz)
+ initial_centre = pymedphys.labs.winstonlutz.findfield._initial_centre(x, y, zz)
assert np.allclose(initial_centre, centre)
