2020"""Utility Module."""
2121
2222import numpy as np
23- from scipy .special import sph_harm
23+ from scipy .special import sph_harm_y
2424
2525_bragg = np .array (
2626 [
@@ -560,21 +560,23 @@ def generate_real_spherical_harmonics_scipy(l_max: int, theta: np.ndarray, phi:
560560 l_list = np .arange (l_max + 1 )
561561 for l_val in l_list :
562562 # generate m=0 real spherical harmonic
563- zero_real_sph = sph_harm ( 0 , l_val , theta , phi ).real
563+ zero_real_sph = sph_harm_y ( l_val , 0 , phi , theta ).real
564564
565- # generate order m=positive real spherical harmonic
566- m_list_p = np .arange (1 , l_val + 1 , dtype = float )
565+ # generate order m=positive real spherical harmonic: sqrt(2) * (-1)^m * Re(Y_l^m)
566+ m_list_p = np .arange (1 , l_val + 1 , dtype = int )
567567 pos_real_sph = (
568- sph_harm (m_list_p [:, None ], l_val , theta , phi ).real
569- * np .sqrt (2 )
570- * (- 1 ) ** m_list_p [:, None ] # Remove Conway phase from SciPy
568+ np .sqrt (2 )
569+ * (- 1 ) ** m_list_p [:, None ]
570+ * sph_harm_y (l_val , m_list_p [:, None ], phi , theta ).real
571+ # Remove Conway phase from SciPy
571572 )
572- # generate order m=negative real spherical harmonic
573- m_list_n = np .arange (- 1 , - l_val - 1 , - 1 , dtype = float )
573+ # generate order m=negative real spherical harmonic: sqrt(2) * (-1)^m * Im(Y_l^m)
574574 neg_real_sph = (
575- sph_harm (m_list_p [:, None ], l_val , theta , phi ).imag
576- * np .sqrt (2 )
577- * (- 1 ) ** m_list_n [:, None ] # Remove Conway phase from SciPy
575+ np .sqrt (2 )
576+ * (- 1 ) ** m_list_p [:, None ]
577+ * sph_harm_y (
578+ l_val , m_list_p [:, None ], phi , theta
579+ ).imag # Remove Conway phase from SciPy
578580 )
579581
580582 # Convert to horton 2 order
@@ -753,7 +755,8 @@ def generate_derivative_real_spherical_harmonics(l_max: int, theta: np.ndarray,
753755 sph_harm_vals = generate_real_spherical_harmonics (l_max , theta , phi )
754756 i_output = 0
755757 for l_val in l_list :
756- for m in [0 , * sum ([[x , - x ] for x in range (1 , l_val + 1 )], [])]:
758+ m_values = [0 ] + [m for x in range (1 , l_val + 1 ) for m in (x , - x )]
759+ for m in m_values :
757760 # Take all spherical harmonics at degree l_val
758761 sph_harm_degree = sph_harm_vals [(l_val ) ** 2 : (l_val + 1 ) ** 2 , :]
759762
@@ -777,7 +780,7 @@ def index_m(m):
777780 # Compute it using SciPy, removing conway phase (-1)^m and multiply by 2^0.5.
778781 sph_harm_m = (
779782 fac
780- * sph_harm ( np .abs (float (m )) + 1 , l_val , theta , phi )
783+ * sph_harm_y ( l_val , np .abs (int (m )) + 1 , phi , theta )
781784 * np .sqrt (2 )
782785 * (- 1.0 ) ** float (m )
783786 )
0 commit comments