def equispaced_s2_grid(theta_range, phi_range, resolution=2.5, no_center=False):
"""Creates rotations approximately equispaced on a sphere.
Parameters
----------
theta_range : tuple of float
(theta_min, theta_max)
The range of allowable polar angles, in degrees.
phi_range : tuple of float
(phi_min, phi_max)
The range of allowable azimuthal angles, in degrees.
resolution : float
The angular resolution of the grid in degrees.
no_center : bool
If true, `theta` values will not start at zero.
Returns
-------
s2_grid : array-like
Each row contains `(theta, phi)`, the azimthal and polar angle
respectively.
"""
theta_min, theta_max = [radians(t) for t in theta_range]
phi_min, phi_max = [radians(r) for r in phi_range]
resolution = radians(resolution)
resolution = 2 * theta_max / int(Decimal(2 * theta_max / resolution).quantize(0, ROUND_HALF_UP))
n_theta = int(Decimal((2 * theta_max / resolution + no_center)).quantize(0, ROUND_HALF_UP) / 2)
if no_center:
theta_grid = np.arange(0.5, n_theta + 0.5) * resolution
else:
theta_grid = np.arange(n_theta + 1) * resolution
phi_grid = []
for j, theta in enumerate(theta_grid):
steps = max(round(sin(theta) * phi_max / theta_max * n_theta), 1)
phi = phi_min\
+ np.arange(steps) * (phi_max - phi_min) / steps \
+ ((j+1) % 2) * (phi_max - phi_min) / steps / 2
phi_grid.append(phi)
s2_grid = np.array(
[(theta, phi) for phis, theta in zip(phi_grid, theta_grid) for phi in
phis])
return s2_grid
评论列表
文章目录