diff --git a/deerlab/utils.py b/deerlab/utils.py index b52a6cb1..8e121908 100644 --- a/deerlab/utils.py +++ b/deerlab/utils.py @@ -885,15 +885,15 @@ def sophegrid(octants,maxphi,size,closed_phi=False): elif octants==0: # Dinfh symmetry (quarter of meridian in xz plane) - phi = np.zeros(1,size) + phi = np.zeros(size) theta = np.linspace(0,np.pi/2,size) weights = -2*(2*np.pi)*np.diff(np.cos(np.concatenate([[0], np.arange(dtheta/2,np.pi/2,dtheta), [np.pi/2]]))); # sum = 4*pi elif octants==-1: # O3 symmetry (z orientation only) - phi = 0 - theta = 0 - weights = 4*np.pi + phi = np.array([0]) + theta = np.array([0]) + weights = np.array([4*np.pi]) else: raise ValueError('Unsupported value #d for octants.',octants) diff --git a/test/test_utils.py b/test/test_utils.py index aee4960a..f111e009 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -16,8 +16,22 @@ def test_sophegrid(): assert np.allclose(weights*4*np.pi, np.array([0.956558005801449,1.70021769237074,1.70021769237074,1.70021769237074,1.70021769237074,0.601117729884346,0.601117729884346,0.601117729884346,0.601117729884346,0.601117729884346,0.601117729884346,0.601117729884346,0.601117729884346])) phi, theta, weights = sophegrid(1,np.pi/2,5,closed_phi=True) - + assert np.allclose(weights.sum(),1) assert np.allclose(phi, np.array([0, 0, 1.5708, 0, 0.7854, 1.5708, 0, 0.5236, 1.0472, 1.5708, 0, 0.3927, 0.7854, 1.1781, 1.5708]),rtol=1e-4) assert np.allclose(theta, np.array([0, 0.3927, 0.3927, 0.7854, 0.7854, 0.7854, 1.1781, 1.1781, 1.1781, 1.1781, 1.5708, 1.5708, 1.5708, 1.5708, 1.5708]),rtol=1e-4) assert np.allclose(weights*4*np.pi, np.array([0.24146, 0.93818, 0.93818, 0.86676, 1.7335, 0.86676, 0.75499, 1.51, 1.51, 0.75499, 0.30645, 0.61289, 0.61289, 0.61289, 0.30645]),rtol=1e-4) + + + phi, theta, weights = sophegrid(0,0,6) + assert np.allclose(weights.sum(),1) + assert np.allclose(phi, np.array([0, 0, 0, 0, 0, 0]),rtol=1e-3) + assert np.allclose(theta, np.array([0, 0.3142, 0.6283, 0.9425, 1.2566, 1.5708]),rtol=1e-3) + assert np.allclose(weights*4*np.pi, np.array([0.1547, 1.2149, 2.3110, 3.1808, 3.7392, 1.9658]),rtol=1e-3) + + phi, theta, weights = sophegrid(-1,0,6) + + assert np.allclose(weights.sum(),1) + assert np.allclose(phi, np.array([0]),rtol=1e-4) + assert np.allclose(theta, np.array([0]),rtol=1e-4) + assert np.allclose(weights*4*np.pi, np.array([12.5664]),rtol=1e-4)