Skip to content

Commit 0304a68

Browse files
authored
Merge pull request #346 from ComputationalCryoEM/real_sph_harm
Reimplement real spherical harmonic function
2 parents 645fe24 + 4ddf3fb commit 0304a68

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

src/aspire/basis/basis_utils.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99
from numpy import diff, exp, log, pi
1010
from numpy.polynomial.legendre import leggauss
11-
from scipy.special import jn, jv, lpmv
11+
from scipy.special import jn, jv, lpmv, sph_harm
1212

1313
from aspire.utils import ensure
1414
from aspire.utils.coor_trans import grid_2d, grid_3d
@@ -126,26 +126,14 @@ def real_sph_harmonic(j, m, theta, phi):
126126
:return: The real spherical harmonics evaluated at the points (theta, phi).
127127
"""
128128
abs_m = abs(m)
129-
y = lpmv(abs_m, j, np.cos(theta))
130-
131-
# Beware of using just np.prod in the denominator here
132-
# Unless we use float64, values in the denominator > 13! will be incorrect
133-
try:
134-
y = (
135-
np.sqrt(
136-
(2 * j + 1)
137-
/ (4 * pi)
138-
/ np.prod(range(j - abs_m + 1, j + abs_m + 1), dtype=np.float64)
139-
)
140-
* y
141-
)
142-
except RuntimeWarning:
143-
logger.error("debug")
144129

130+
y = sph_harm(abs_m, j, phi, theta)
145131
if m < 0:
146-
y = np.sqrt(2) * np.sin(abs_m * phi) * y
132+
y = np.sqrt(2) * np.imag(y)
147133
elif m > 0:
148-
y = np.sqrt(2) * np.cos(abs_m * phi) * y
134+
y = np.sqrt(2) * np.real(y)
135+
else:
136+
y = np.real(y)
149137

150138
return y
151139

tutorials/examples/cov3d_simulation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
# Create a simulation object with specified filters
3030
sim = Simulation(
31+
L=img_size,
3132
n=num_imgs,
3233
C=num_vols,
3334
unique_filters=[RadialCTFFilter(defocus=d) for d in np.linspace(1.5e4, 2.5e4, 7)],

0 commit comments

Comments
 (0)