Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer importing newer scipy.sph_harm_y #448

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions meshmode/mesh/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,15 @@ def refine_mesh_and_get_urchin_warper(

.. versionadded: 2018.1
"""
try:
from scipy.special import sph_harm_y
except ImportError:
# NOTE: this was deprecated in v1.15 and (will be) removed in v1.17
from scipy.special import sph_harm as _sph_harm_y

def sph_harm_y(n: int, m: int, p: np.ndarray, t: np.ndarray) -> np.ndarray:
# NOTE: this swaps both (n, m) and (theta, phi)
return _sph_harm_y(m, n, t, p)

def sph_harm(m: int, n: int, pts: np.ndarray) -> np.ndarray:
assert abs(m) <= n
Expand All @@ -976,16 +985,9 @@ def sph_harm(m: int, n: int, pts: np.ndarray) -> np.ndarray:
theta = np.arccos(z/r)
phi = np.arctan2(y, x)

import scipy.special as sps

# Note: This matches the spherical harmonic
# convention in the QBX3D paper:
# NOTE: This matches the spherical harmonic convention in the QBX3D paper:
# https://arxiv.org/abs/1805.06106
#
# Numpy takes arguments in the order (theta, phi)
# *and* swaps their meanings, so passing the
# arguments swapped maintains the intended meaning.
return sps.sph_harm(m, n, phi, theta) # pylint: disable=no-member
return sph_harm_y(n, m, theta, phi)

def map_coords(pts: np.ndarray) -> np.ndarray:
r = np.sqrt(np.sum(pts**2, axis=0))
Expand Down
Loading