def test_draw_creates_ellipse_with_expected_properties_with_nonzero_alpha(
            self, compute_alpha_mock):
        peak_center = (1, 2, 3)
        ellipsoid = create_test_ellipsoid()
        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.26,
                                   signal_width=2.6,
                                   signal_height=3.0,
                                   angle=90,
                                   alpha=fake_alpha,
                                   fg_color=fg_color,
                                   bkgd_width=4.8,
                                   bkgd_height=5.2,
                                   thickness=0.1,
                                   bg_color=bg_color)
    def test_draw_respects_transform(self, compute_alpha_mock):
        def slice_transform(x):
            # set slice(x)=data(z)
            return (x[2], x[0], x[1])

        peak_center = (1, 2, 3)
        ellipsoid = create_test_ellipsoid()
        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, slice_transform)

        self.assertTrue(painted is not None)
        self._assert_painter_calls(painter, (peak_center[2], peak_center[0]),
                                   cross_width=0.182,
                                   signal_width=1.82,
                                   signal_height=2.1,
                                   angle=90,
                                   alpha=fake_alpha,
                                   fg_color=fg_color,
                                   bkgd_width=4.4,
                                   bkgd_height=4.77,
                                   thickness=0.1,
                                   bg_color=bg_color)
예제 #3
0
    def test_draw_creates_circle_with_expected_properties_with_nonzero_alpha_and_no_background_in_JSON_shape(
            self, compute_alpha_mock):
        peak_center = [1, 2, 3]
        sphere = create_sphere_info(radius=0.4, specify_bkgd=False)
        painter = MagicMock()
        fg_color, bg_color = 'r', 'unused'
        fake_alpha = 0.5
        compute_alpha_mock.return_value = fake_alpha

        painted = draw_representation(EllipsoidalIntegratedPeakRepresentation,
                                      peak_center,
                                      sphere,
                                      painter,
                                      fg_color,
                                      bg_color,
                                      shape_name="spherical")

        self.assertTrue(painted is not None)
        self._assert_painter_calls(painter,
                                   peak_center[:2],
                                   cross_width=0.08,
                                   signal_width=0.8,
                                   signal_height=0.8,
                                   angle=0,
                                   alpha=fake_alpha,
                                   fg_color=fg_color)
예제 #4
0
    def test_draw_varying_background_thickness(self, compute_alpha_mock):
        def slice_transform(x):
            return x

        peak_center = [3, 1, 3]
        ellipsoid = create_ellipsoid_info(radii=(0.5, 0.5, 0.5),
                                          axes=("1 0 0", "0 1 0", "0 0 1"),
                                          bkgd_radii=((0.5, 0.6, 0.6),
                                                      (0.6, 1.0, 1.0)))
        painter = MagicMock()
        fg_color, bg_color = 'r', 'g'
        fake_alpha = 0.5
        compute_alpha_mock.return_value = fake_alpha

        painted = draw_representation(EllipsoidalIntegratedPeakRepresentation,
                                      peak_center, ellipsoid, painter,
                                      fg_color, bg_color, slice_transform)

        self.assertTrue(painted is not None)
        self._assert_painter_calls(painter, (peak_center[0], peak_center[1]),
                                   cross_width=0.1,
                                   signal_width=1.0,
                                   signal_height=1.0,
                                   angle=0,
                                   alpha=fake_alpha,
                                   fg_color=fg_color,
                                   bkgd_width=1.2,
                                   bkgd_height=2.0,
                                   thickness=((0.6 - 0.5) / 0.6,
                                              (1.0 - 0.6) / 1.0),
                                   bg_color=bg_color)
예제 #5
0
    def test_draw_with_nonzero_translation(self, compute_alpha_mock):
        def slice_transform(x):
            # set slice(x)=data(z)
            return (x[2], x[0], x[1])

        peak_center = (1, 2, 3)
        ellipsoid = create_test_ellipsoid(do_translate=True)
        painter = MagicMock()
        fg_color, bg_color = 'r', 'g'
        fake_alpha = 0.5
        compute_alpha_mock.return_value = fake_alpha

        # pass peak centre as list as modified in place
        painted = draw_representation(EllipsoidalIntegratedPeakRepresentation,
                                      list(peak_center), ellipsoid, painter,
                                      fg_color, bg_color, slice_transform)

        self.assertTrue(painted is not None)
        self._assert_painter_calls(painter,
                                   (peak_center[2], peak_center[0] + 0.1),
                                   cross_width=0.192,
                                   signal_width=1.92,
                                   signal_height=1.79,
                                   angle=90,
                                   alpha=fake_alpha,
                                   fg_color=fg_color,
                                   bkgd_width=5.54,
                                   bkgd_height=5.17,
                                   thickness=0.1,
                                   bg_color=bg_color)
예제 #6
0
    def test_draw_respects_slice_transformation(self, compute_alpha_mock):
        def slice_transform(x):
            # set slice(x)=data(y)
            return (x[1], x[0], x[2])

        peak_center = (1, 2, 3)
        sphere = create_test_sphere(background=True)
        painter = MagicMock()
        fg_color, bg_color = 'r', 'g'
        fake_alpha = 0.5
        compute_alpha_mock.return_value = fake_alpha

        painted = draw_representation(SphericallyIntergratedPeakRepresentation,
                                      peak_center, sphere, painter, fg_color,
                                      bg_color, slice_transform)

        self.assertTrue(painted is not None)
        self._assert_painter_calls(painter, (peak_center[1], peak_center[0]),
                                   cross_width=0.04,
                                   signal_slice_radius=0.4,
                                   alpha=fake_alpha,
                                   fg_color=fg_color,
                                   bkgd_slice_radius=0.9,
                                   bkgd_thickness=0.09,
                                   bg_color=bg_color)
예제 #7
0
    def test_draw_creates_nothing_when_alpha_lt_zero(self, compute_alpha_mock):
        sphere = create_test_sphere()
        painter = MagicMock()
        fake_alpha = -0.1
        compute_alpha_mock.return_value = fake_alpha

        painted = draw_representation(SphericallyIntergratedPeakRepresentation,
                                      (1, 2, 3), sphere, painter, 'r', 'g')

        self.assertTrue(painted is None)
        painter.cross.assert_not_called()
        painter.circle.assert_not_called()
    def test_draw_creates_nothing_when_alpha_lt_zero(self, compute_alpha_mock):
        ellipsoid = create_test_ellipsoid()
        painter = MagicMock()
        fake_alpha = -0.1
        compute_alpha_mock.return_value = fake_alpha

        painted = draw_representation(EllipsoidalIntergratedPeakRepresentation,
                                      (1, 2, 3), ellipsoid, painter, 'r', 'g')

        self.assertTrue(painted is None)
        painter.cross.assert_not_called()
        painter.ellipse.assert_not_called()
        painter.elliptical_shell.assert_not_called()
예제 #9
0
    def test_draw_respects_transform(self, compute_alpha_mock):
        def slice_transform(x):
            # set slice(x)=data(z)
            return (x[2], x[0], x[1])

        peak_center = [1, 2, 3]
        ellipsoid = create_test_ellipsoid()
        painter = MagicMock()
        fg_color, bg_color = 'r', 'g'
        fake_alpha = 0.5
        compute_alpha_mock.return_value = fake_alpha

        painted = draw_representation(EllipsoidalIntegratedPeakRepresentation,
                                      peak_center, ellipsoid, painter,
                                      fg_color, bg_color, slice_transform)

        slice_diff = 1  # difference between peak_center and slice_point in plane normal to slice (3 - 2)
        major_outer_radius = np.cos(
            np.arcsin(slice_diff / ellipsoid['background_outer_radius1'])
        ) * ellipsoid['background_outer_radius0']
        minor_outer_radius = np.cos(
            np.arcsin(slice_diff / ellipsoid['background_outer_radius1'])
        ) * ellipsoid['background_outer_radius2']
        major_inner_radius = np.cos(
            np.arcsin(slice_diff / ellipsoid['background_inner_radius1'])
        ) * ellipsoid['background_inner_radius0']
        minor_inner_radius = np.cos(
            np.arcsin(slice_diff / ellipsoid['background_inner_radius1'])
        ) * ellipsoid['background_inner_radius2']
        fractional_thickness = ((major_outer_radius - major_inner_radius) /
                                major_outer_radius,
                                (minor_outer_radius - minor_inner_radius) /
                                minor_outer_radius)

        self.assertTrue(painted is not None)
        self._assert_painter_calls(painter, (peak_center[2], peak_center[0]),
                                   cross_width=0.192,
                                   signal_width=1.92,
                                   signal_height=1.79,
                                   angle=90,
                                   alpha=fake_alpha,
                                   fg_color=fg_color,
                                   bkgd_width=5.54,
                                   bkgd_height=5.17,
                                   thickness=fractional_thickness,
                                   bg_color=bg_color)
예제 #10
0
    def test_draw_creates_circle_with_expected_properties_with_nonzero_alpha_and_no_background(
            self, compute_alpha_mock):
        peak_center = (1, 2, 3)
        sphere = create_test_sphere()
        painter = MagicMock()
        fg_color, bg_color = 'r', 'unused'
        fake_alpha = 0.5
        compute_alpha_mock.return_value = fake_alpha

        painted = draw_representation(SphericallyIntergratedPeakRepresentation,
                                      peak_center, sphere, painter, fg_color,
                                      bg_color)

        self.assertTrue(painted is not None)
        self._assert_painter_calls(painter,
                                   peak_center[:2],
                                   cross_width=0.04,
                                   signal_slice_radius=0.4,
                                   alpha=fake_alpha,
                                   fg_color=fg_color)
예제 #11
0
    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(EllipsoidalIntegratedPeakRepresentation,
                                      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)