Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ workflows:
matrix:
parameters:
version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
Expand Down Expand Up @@ -211,7 +210,6 @@ workflows:
matrix:
parameters:
version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.6.2"
description = "Project for data formats in acoustics."
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.10"
requires-python = ">=3.11"
authors = [
{ name = "The pyfar developers", email = "info@pyfar.org" },
]
Expand All @@ -18,15 +18,14 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",

]
dependencies = [
'numpy>=1.22',
'scipy>=1.15',
'scipy>=1.17',
'urllib3',
'matplotlib>=3.10.3',
'pyfar>=0.7.3,<0.8.0',
Expand Down
19 changes: 9 additions & 10 deletions spharpy/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,15 @@ def legendre_function(n, m, z, cs_phase=True):
"""
z = np.atleast_1d(z)

if np.abs(m) > n:
legendre = np.zeros(z.shape)
else:
legendre = np.zeros(z.shape)
for idx, arg in zip(count(), z):
leg, _ = _spspecial.lpmn(m, n, arg)
if np.mod(m, 2) != 0 and not cs_phase:
legendre[idx] = -leg[-1, -1]
else:
legendre[idx] = leg[-1, -1]
# squeeze required because the legendre function introduced in scipy 1.15
# returns a 2D array, whereas the previous function `lpmn` returned a 1D
# array
legendre = np.squeeze(_spspecial.assoc_legendre_p(n, m, z))

# remove Condon-Shortley phase
if not cs_phase and m % 2:
legendre *= -1

return legendre


Expand Down
49 changes: 49 additions & 0 deletions tests/test_special.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,52 @@ def test_spherical_harmonic_gradient_phi_real():
desired = desired_all[:, acn]

npt.assert_allclose(actual, desired, rtol=1e-10, atol=1e-10)


@pytest.mark.parametrize('condon_shortley', [(True, ), (False, )])
@pytest.mark.parametrize(('n', 'm'), [
(1, -1), (1, 0), (1, 1), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)])
def test_legendre(condon_shortley, n, m):
"""
Test values of the Legendre functions for first order and all degrees.
"""
z = np.linspace(-1, 1, 11)

# Manually computed desired values according to
# Rafaely (2019), Fundamentals of Spherical Array Processing, Table 1.3
if n == 1:
if m == -1:
desired = .5 * np.sqrt(1 - z**2)
if m == 0:
desired = z.copy()
if m == 1:
desired = -np.sqrt(1 - z**2)
if n == 2:
if m == -2:
desired = .125 * (1 - z**2)
if m == -1:
desired = .5 * z * np.sqrt(1 - z**2)
if m == 0:
desired = .5 * (3 * z**2 - 1)
if m == 1:
desired = -3 * z * np.sqrt(1 - z**2)
if m == 2:
desired = 3 * (1 - z**2)

# remove Condon-Shortley phase
if not condon_shortley and m % 2:
desired *= -1

# compute and compare actual values
actual = special.legendre_function(n, m, z, condon_shortley)
npt.assert_almost_equal(actual, desired, 10)
Comment thread
mberz marked this conversation as resolved.


@pytest.mark.parametrize('m', [(-2, ), (2, )])
def test_legendre_degree_out_of_range(m):
"""Test if zero is returned if the degree m is larger than the order n."""
n = 1
z = np.linspace(-1, 1, 11)

npt.assert_equal(special.legendre_function(n, m, z),
np.zeros_like(z))