Commit 1f07327b authored by Richard Waite's avatar Richard Waite
Browse files

Added test for ellipsoid with no bg

Changed way fake ellipsoid shape made such that bg and peak have same covar matrix and makes test values more transparent.
parent 8c1ae127
...@@ -14,9 +14,6 @@ import numpy.linalg as linalg ...@@ -14,9 +14,6 @@ import numpy.linalg as linalg
from .alpha import compute_alpha from .alpha import compute_alpha
from .painter import Painted from .painter import Painted
import pydevd_pycharm
pydevd_pycharm.settrace('debug_host', port=44444, stdoutToServer=True, stderrToServer=True, suspend=False)
class EllipsoidalIntergratedPeakRepresentation(): class EllipsoidalIntergratedPeakRepresentation():
"""Provide methods to display a representation of a slice through an """Provide methods to display a representation of a slice through an
...@@ -196,7 +193,7 @@ def calculate_ellipsoid_matrix(axis_a, axis_b, axis_c, a, b, c, transform): ...@@ -196,7 +193,7 @@ def calculate_ellipsoid_matrix(axis_a, axis_b, axis_c, a, b, c, transform):
# transformation matrix (inverse gives transform from MD to view basis) # transformation matrix (inverse gives transform from MD to view basis)
R = np.vstack((transform((1, 0, 0)), transform((0, 1, 0)), transform((0, 0, 1)))) R = np.vstack((transform((1, 0, 0)), transform((0, 1, 0)), transform((0, 0, 1))))
# matrix with eigenvectors (in view basis) in columns # matrix with eigenvectors (in view basis) in columns
axes_dir = linalg.inv(R) @ np.hstack((axis_a[:,None], axis_b[:,None], axis_c[:,None])) axes_dir = linalg.inv(R) @ np.hstack((axis_a[:, None], axis_b[:, None], axis_c[:, None]))
return axes_dir @ axes_lengths @ np.transpose(axes_dir) return axes_dir @ axes_lengths @ np.transpose(axes_dir)
......
...@@ -19,11 +19,19 @@ from mantidqt.widgets.sliceviewer.peaksviewer.representation.test.shapetesthelpe ...@@ -19,11 +19,19 @@ from mantidqt.widgets.sliceviewer.peaksviewer.representation.test.shapetesthelpe
import FuzzyMatch, create_ellipsoid_info, draw_representation import FuzzyMatch, create_ellipsoid_info, draw_representation
def create_test_ellipsoid(): def create_test_ellipsoid(bg_shell=True):
radii = [1.5, 1.3, 1.4]
if bg_shell:
frac_thick = 0.1 # fractional thickness of major axis
bg_outer = [2 * r for r in radii]
bg_inner = [(1 - frac_thick) * r for r in bg_outer]
else:
bg_outer = 3 * [0]
bg_inner = radii
return create_ellipsoid_info( return create_ellipsoid_info(
radii=(1.5, 1.3, 1.4), radii=radii,
axes=("1 0 0", "0 1 0", "0 0 1"), axes=("1 0 0", "0 1 0", "0 0 1"),
bkgd_radii=(((2.5, 2.3, 2.4)), ((2.6, 2.4, 2.5)))) bkgd_radii=((bg_inner), (bg_outer)))
@patch("mantidqt.widgets.sliceviewer.peaksviewer.representation.ellipsoid.compute_alpha") @patch("mantidqt.widgets.sliceviewer.peaksviewer.representation.ellipsoid.compute_alpha")
...@@ -42,7 +50,7 @@ class EllipsoidalIntergratedPeakRepresentationTest(unittest.TestCase): ...@@ -42,7 +50,7 @@ class EllipsoidalIntergratedPeakRepresentationTest(unittest.TestCase):
painter.ellipse.assert_not_called() painter.ellipse.assert_not_called()
painter.elliptical_shell.assert_not_called() painter.elliptical_shell.assert_not_called()
def test_draw_creates_ellipse_with_expected_properties_with_nonzero_alpha( def test_draw_creates_ellipse_with_expected_properties_with_nonzero_alpha_and_background(
self, compute_alpha_mock): self, compute_alpha_mock):
peak_center = (1, 2, 3) peak_center = (1, 2, 3)
ellipsoid = create_test_ellipsoid() ellipsoid = create_test_ellipsoid()
...@@ -59,16 +67,38 @@ class EllipsoidalIntergratedPeakRepresentationTest(unittest.TestCase): ...@@ -59,16 +67,38 @@ class EllipsoidalIntergratedPeakRepresentationTest(unittest.TestCase):
painter, painter,
peak_center[:2], peak_center[:2],
cross_width=0.3, cross_width=0.3,
signal_width=2.6, signal_width=3.0,
signal_height=3.0, signal_height=2.6,
angle=90, angle=0,
alpha=fake_alpha, alpha=fake_alpha,
fg_color=fg_color, fg_color=fg_color,
bkgd_width=4.8, bkgd_width=6.0,
bkgd_height=5.2, bkgd_height=5.2,
thickness=0.1 / 2.6, thickness=0.1,
bg_color=bg_color) bg_color=bg_color)
def test_draw_creates_ellipse_with_expected_properties_with_nonzero_alpha_no_background(self, compute_alpha_mock):
peak_center = (1, 2, 3)
ellipsoid = create_test_ellipsoid(bg_shell=False)
painter = MagicMock()
fg_color, bg_color = 'r', 'g'
fake_alpha = 0.5
compute_alpha_mock.return_value = fake_alpha
painted = draw_representation(EllipsoidalIntergratedPeakRepresentation, peak_center,
ellipsoid, painter, fg_color, bg_color)
self.assertTrue(painted is not None)
self._assert_painter_calls(
painter,
peak_center[:2],
cross_width=0.3,
signal_width=3.0,
signal_height=2.6,
angle=0,
alpha=fake_alpha,
fg_color=fg_color)
def test_draw_respects_transform(self, compute_alpha_mock): def test_draw_respects_transform(self, compute_alpha_mock):
def slice_transform(x): def slice_transform(x):
# set slice(x)=data(z) # set slice(x)=data(z)
...@@ -93,9 +123,9 @@ class EllipsoidalIntergratedPeakRepresentationTest(unittest.TestCase): ...@@ -93,9 +123,9 @@ class EllipsoidalIntergratedPeakRepresentationTest(unittest.TestCase):
angle=90, angle=90,
alpha=fake_alpha, alpha=fake_alpha,
fg_color=fg_color, fg_color=fg_color,
bkgd_width=4.73, bkgd_width=5.54,
bkgd_height=4.55, bkgd_height=5.17,
thickness=0.1 / 2.6, thickness=0.1,
bg_color=bg_color) bg_color=bg_color)
# private # private
...@@ -147,15 +177,15 @@ class EllipsoidalIntergratedPeakRepresentationTest(unittest.TestCase): ...@@ -147,15 +177,15 @@ class EllipsoidalIntergratedPeakRepresentationTest(unittest.TestCase):
class EllipsoidalIntergratedPeakRepresentationSliceEllipsoidTest(unittest.TestCase): class EllipsoidalIntergratedPeakRepresentationSliceEllipsoidTest(unittest.TestCase):
def test_slice_ellipsoid_zp(self): def test_slice_ellipsoid_zp(self):
origin = (0, 0, 0) origin = (0, 0, 0)
axis_a = (1, 0, 0) axis_a = np.array([1, 0, 0])
axis_b = (0, 1, 0) axis_b = np.array([0, 1, 0])
axis_c = (0, 0, 1) axis_c = np.array([0, 0, 1])
a = 1 a = 1
b = 2 b = 2
c = 1 c = 1
zp = 0 zp = 0
slice_transform = lambda x: (x[1], x[0], x[2]) # Y out of plane slice_transform = lambda x: (x[1], x[0], x[2])
expected_slice_origin = (0, 0, 0) expected_slice_origin = (0, 0, 0)
expected_major_radius = 2 expected_major_radius = 2
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment