LSST Applications g1653933729+34a971ddd9,g1a997c3884+34a971ddd9,g2160c40384+da0d0eec6b,g28da252d5a+1236b942f7,g2bbee38e9b+e5a1bc5b38,g2bc492864f+e5a1bc5b38,g2ca4be77d2+192fe503f0,g2cdde0e794+704103fe75,g3156d2b45e+6e87dc994a,g347aa1857d+e5a1bc5b38,g35bb328faa+34a971ddd9,g3a166c0a6a+e5a1bc5b38,g3e281a1b8c+8ec26ec694,g4005a62e65+ba0306790b,g414038480c+9f5be647b3,g41af890bb2+c3a10c924f,g5065538af8+e7237db731,g5a0bb5165c+eae055db26,g717e5f8c0f+b65b5c3ae4,g80478fca09+4ce5a07937,g82479be7b0+08790af60f,g858d7b2824+b65b5c3ae4,g9125e01d80+34a971ddd9,ga5288a1d22+5df949a35e,gae0086650b+34a971ddd9,gb58c049af0+ace264a4f2,gbd397ab92a+2141afb137,gc28159a63d+e5a1bc5b38,gc805d3fbd4+b65b5c3ae4,gcf0d15dbbd+97632ccc20,gd6b7c0dfd1+de826e8718,gda6a2b7d83+97632ccc20,gdaeeff99f8+7774323b41,ge2409df99d+e6cadbf968,ge33fd446bb+b65b5c3ae4,ge79ae78c31+e5a1bc5b38,gf0baf85859+890af219f9,gf5289d68f6+a27069ed62,w.2024.37
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