LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
test_ellipse.py
Go to the documentation of this file.
1# This file is part of gauss2d.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
21
22import lsst.gauss2d as g2d
23
24import math
25import pytest
26
27rho_min = math.nextafter(-1, -2)
28rho_max = math.nextafter(1, 2)
29pos_min = math.nextafter(0, 1)
30prefix_namespace = "lsst.gauss2d."
31
32
34 with pytest.raises(ValueError):
36 with pytest.raises(ValueError):
37 g2d.Covariance(0, -1)
38 for rho_bad in (rho_min, rho_max):
39 with pytest.raises(ValueError):
40 g2d.Covariance(0, 0, rho_bad)
41
42 covar_0 = g2d.Covariance()
43 assert (covar_0.sigma_x_sq, covar_0.sigma_y_sq, covar_0.cov_xy) == (0, 0, 0)
44 assert covar_0.xyc == [0, 0, 0]
45 assert covar_0 != g2d.Covariance(pos_min, 0, 0)
46 assert covar_0 != g2d.Covariance(0, pos_min, 0)
47 assert g2d.Covariance(1, 1, 0) != g2d.Covariance(1, 1, pos_min)
48
49 covar_conv = g2d.Covariance(9., 9., 0).make_convolution(g2d.Covariance(16., 16., 0))
50 assert covar_conv == g2d.Covariance(25., 25., 0)
51
52 str_covar_conv = "Covariance(sigma_x_sq=2.500000e+01, sigma_y_sq=2.500000e+01, cov_xy=0.000000e+00)"
53 assert str(str_covar_conv) == str_covar_conv
54 assert repr(covar_conv) == f"{prefix_namespace}{str_covar_conv}"
55
56
58 with pytest.raises(ValueError):
59 g2d.Ellipse(-1)
60 with pytest.raises(ValueError):
61 g2d.Ellipse(0, -1)
62 for rho_bad in (rho_min, rho_max):
63 with pytest.raises(ValueError):
64 g2d.Ellipse(0, 0, rho_bad)
65
66 ell_0 = g2d.Ellipse()
67 assert ell_0.xyr == [0, 0, 0]
68 assert ell_0 != g2d.Ellipse(pos_min, 0, 0)
69 assert ell_0 != g2d.Ellipse(0, pos_min, 0)
70 ell_1 = g2d.Ellipse(sigma_x=1, sigma_y=1, rho=-0.1)
71 assert (ell_1.sigma_x, ell_1.sigma_y, ell_1.rho) == (1, 1, -0.1)
72 assert [ell_1.hwhm_x, ell_1.hwhm_y, ell_1.rho] == ell_1.hxyr
73 ell_1.set_h(hwhm_x=1, hwhm_y=1, rho=0.1)
74 assert (ell_1.hwhm_x, ell_1.hwhm_y, ell_1.rho) == (1, 1, 0.1)
75 assert ell_1 != g2d.Ellipse(1, 1, pos_min)
76
77 ell_conv = g2d.Ellipse(3., 3., 0).make_convolution(g2d.Ellipse(4., 4., 0))
78 assert ell_conv == g2d.Ellipse(5., 5., 0)
79 assert ell_conv.get_radius_trace() == pytest.approx(5*math.sqrt(2.), rel=1e-10, abs=1e-10)
80
81 str_data = "EllipseValues(sigma_x=5.000000e+00, sigma_y=5.000000e+00, rho=0.000000e+00)"
82 assert str(ell_conv) == f"Ellipse(data={str_data})"
83 assert repr(ell_conv) == f"{prefix_namespace}Ellipse(data={prefix_namespace}{str_data})"
84
85 ell_conv.set(g2d.Covariance(ell_0))
86 print(g2d.Covariance(ell_0))
87 assert ell_conv == ell_0
88 ell_1_maj = g2d.EllipseMajor(ell_1)
89 ell_conv.set(ell_1_maj)
90 assert ell_conv == g2d.Ellipse(ell_1_maj)
91
92
94 covar = g2d.Covariance(0.08333332098858685, 0.08333332098858683, 1.337355953645e-13)
95 ellipse_maj = g2d.EllipseMajor(covar)
96 assert ellipse_maj.r_major > 0
A representation of a 2D Gaussian with x and y standard deviations and a covariance value.
Definition ellipse.h:57
An Ellipse with sigma_x, sigma_y, and rho values.
Definition ellipse.h:283
An Ellipse with r_major, axrat and angle values.
Definition ellipse.h:337