@@ -11,7 +11,7 @@ def gaussian_from_Sigma_matrix(x, y, I0, mu, Sigma):
1111 """
1212 Evaluate a 2D anisotropic Gaussian defined by its covariance matrix.
1313
14- The Gaussian is given by
14+ The Gaussian is given by::
1515
1616 G(x, y) = I₀ * exp[-½ (r - μ)ᵀ Σ⁻¹ (r - μ)],
1717
@@ -59,6 +59,7 @@ def gaussian_from_Sigma_matrix(x, y, I0, mu, Sigma):
5959 >>> G = gaussian_from_Sigma_matrix(x, y, I0=1.0, mu=mu, Sigma=Sigma)
6060 >>> G.shape
6161 (101, 101)
62+
6263 """
6364 pos = np .stack ((x - mu [0 ], y - mu [1 ]), axis = 0 )
6465 invSigma = np .linalg .inv (Sigma )
@@ -77,11 +78,13 @@ def convolve_gaussians(I1, mu1, Sigma1, I2, mu2, Sigma2):
7778 """
7879 Analytically convolve two 2D anisotropic Gaussian profiles.
7980
80- The convolution of two Gaussians
81- G₁(r) = I₁ exp[-½ (r − μ₁)ᵀ Σ₁⁻¹ (r − μ₁)]
82- and
83- G₂(r) = I₂ exp[-½ (r − μ₂)ᵀ Σ₂⁻¹ (r − μ₂)]
84- yields another Gaussian with parameters:
81+ The convolution of two Gaussians::
82+
83+ G₁(r) = I₁ exp[-½ (r − μ₁)ᵀ Σ₁⁻¹ (r − μ₁)]
84+ and
85+ G₂(r) = I₂ exp[-½ (r − μ₂)ᵀ Σ₂⁻¹ (r − μ₂)]
86+
87+ yields another Gaussian with parameters::
8588
8689 Σ_H = Σ₁ + Σ₂
8790 μ_H = μ₁ + μ₂
@@ -125,8 +128,9 @@ def convolve_gaussians(I1, mu1, Sigma1, I2, mu2, Sigma2):
125128 >>> I2, mu2, Sigma2 = 1.0, np.array([0.3, -0.2]), np.diag([1.5, 0.5])
126129 >>> I_H, mu_H, Sigma_H = convolve_gaussians(I1, mu1, Sigma1, I2, mu2, Sigma2)
127130 >>> I_H, mu_H, Sigma_H
128- (0.707..., array([ 0.3, -0.2]), array([[3.5, 0. ],
129- [0. , 1.5]]))
131+ (0.707..., array([ 0.3, -0.2]), array([[3.5, 0.],
132+ [0., 1.5]]))
133+
130134 """
131135 Sigma_H = Sigma1 + Sigma2
132136 mu_H = mu1 + mu2
@@ -148,8 +152,7 @@ def convolve_gaussians(I1, mu1, Sigma1, I2, mu2, Sigma2):
148152def params_from_sigma (Sigma ):
149153 """
150154 From covariance matrix Sigma (2x2) return (sigma_maj, sigma_min,
151- theta) with
152- sigma_maj>=sigma_min>=0.
155+ theta) with sigma_maj>=sigma_min>=0.
153156
154157 Parameters
155158 ----------
@@ -158,15 +161,19 @@ def params_from_sigma(Sigma):
158161 ellipse. Must be symmetric.
159162 Covariance matrix elements: if sigma_maj is major axis stddev,
160163 sigma_min is minor axis stddev, and theta the position angle (CCW
161- from +Y), then
164+ from +Y), then::
165+
162166 S = [[sxx, sxy],
163167 [sxy, syy]] = R @ [[sigma_maj^2, 0],
164168 [0, sigma_min^2]] @ R.T
165- where R = [[-sin(theta), -cos(theta)],
166- [ cos(theta), -sin(theta)]]
167- i.e. sxx = sigma_maj^2 sin^2(theta) + sigma_min^2 cos^2(theta)
168- syy = sigma_maj^2 cos^2(theta) + sigma_min^2 sin^2(theta)
169- sxy = -(sigma_maj^2 - sigma_min^2) sin(theta) cos(theta)
169+
170+ where R = [[-sin(theta), -cos(theta)],
171+ [ cos(theta), -sin(theta)]]
172+
173+ i.e. sxx = sigma_maj^2 sin^2(theta) + sigma_min^2 cos^2(theta)
174+ syy = sigma_maj^2 cos^2(theta) + sigma_min^2 sin^2(theta)
175+ sxy = -(sigma_maj^2 - sigma_min^2) sin(theta) cos(theta)
176+
170177 Returns
171178 -------
172179 sigma_maj : float
@@ -176,6 +183,7 @@ def params_from_sigma(Sigma):
176183 theta : float
177184 Position angle of the major axis in radians, in [0, pi).
178185 Measured from the positive y-axis toward the negative-axis.
186+
179187 Notes
180188 -----
181189 - The covariance matrix Sigma is related to the ellipse parameters
@@ -184,6 +192,7 @@ def params_from_sigma(Sigma):
184192 eigenvalues of Sigma.
185193 - The position angle theta is derived from the eigenvector
186194 corresponding to the largest eigenvalue.
195+
187196 """
188197 # Symmetrize for numerical safety
189198 S = 0.5 * (Sigma + Sigma .T )
0 commit comments