Skip to content

Commit 1f798b9

Browse files
authored
Add Lebedev quadrature (#14)
1 parent bb91667 commit 1f798b9

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

micarray/modal/angular.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import numpy as np
33
from scipy import special
44
from .. import util
5+
from warnings import warn
6+
try:
7+
import quadpy # only for grid_lebedev()
8+
except ImportError:
9+
pass
510

611

712
def sht_matrix(N, azi, elev, weights=None):
@@ -226,3 +231,47 @@ def grid_equal_polar_angle(n):
226231
pol = np.linspace(0, 2*np.pi, num=num_mic, endpoint=False)
227232
weights = 1/num_mic * np.ones(num_mic)
228233
return pol, weights
234+
235+
236+
def grid_lebedev(n):
237+
"""Lebedev sampling points on sphere.
238+
239+
(Maximum n is 65. We use what is available in quadpy, some n may not be
240+
tight, others produce negative weights.
241+
242+
Parameters
243+
----------
244+
n : int
245+
Maximum order.
246+
247+
Returns
248+
-------
249+
azi : array_like
250+
Azimuth.
251+
elev : array_like
252+
Elevation.
253+
weights : array_like
254+
Quadrature weights.
255+
256+
"""
257+
def available_quadrature(d):
258+
"""Get smallest availabe quadrature of of degree d.
259+
260+
see:
261+
https://people.sc.fsu.edu/~jburkardt/datasets/sphere_lebedev_rule/sphere_lebedev_rule.html
262+
"""
263+
l = list(range(1, 32, 2)) + list(range(35, 132, 6))
264+
matches = [x for x in l if x >= d]
265+
return matches[0]
266+
267+
if n > 65:
268+
raise ValueError("Maximum available Lebedev grid order is 65. "
269+
"(requested: {})".format(n))
270+
271+
# this needs https://pypi.python.org/pypi/quadpy
272+
q = quadpy.sphere.Lebedev(degree=available_quadrature(2*n))
273+
if np.any(q.weights < 0):
274+
warn("Lebedev grid of order {} has negative weights.".format(n))
275+
azi = q.azimuthal_polar[:, 0]
276+
elev = q.azimuthal_polar[:, 1]
277+
return azi, elev, q.weights

0 commit comments

Comments
 (0)