Skip to content

Commit 8af3dd0

Browse files
committed
Raise error early on unrecognised method + add tests
1 parent 8dbcc97 commit 8af3dd0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

s2fft/precompute_transforms/spherical.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def inverse(
6262
np.ndarray: Pixel-space coefficients with shape.
6363
6464
"""
65+
if method not in _inverse_functions:
66+
raise ValueError(f"Method {method} not recognised.")
6567
if reality and spin != 0:
6668
reality = False
6769
warn(
@@ -81,8 +83,6 @@ def inverse(
8183
if kernel is None
8284
else kernel
8385
)
84-
if method not in _inverse_functions:
85-
raise ValueError(f"Method {method} not recognised.")
8686
return _inverse_functions[method](flm, kernel, **common_kwargs)
8787

8888

@@ -351,6 +351,8 @@ def forward(
351351
np.ndarray: Spherical harmonic coefficients.
352352
353353
"""
354+
if method not in _forward_functions:
355+
raise ValueError(f"Method {method} not recognised.")
354356
if reality and spin != 0:
355357
reality = False
356358
warn(
@@ -370,8 +372,6 @@ def forward(
370372
if kernel is None
371373
else kernel
372374
)
373-
if method not in _forward_functions:
374-
raise ValueError(f"Method {method} not recognised.")
375375
if iter == 0:
376376
return _forward_functions[method](f, kernel, **common_kwargs)
377377
else:

tests/test_spherical_precompute.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,19 @@ def test_transform_forward_high_spin(
324324
flm_recov = forward(f, L, spin, kernel, sampling, reality, "numpy")
325325
tol = 1e-8 if sampling.lower() in ["dh", "gl"] else 1e-12
326326
np.testing.assert_allclose(flm_recov, flm, atol=tol, rtol=tol)
327+
328+
329+
def test_forward_transform_unrecognised_method_raises():
330+
method = "invalid_method"
331+
L = 32
332+
f = np.zeros(samples.f_shape(L))
333+
with pytest.raises(ValueError, match=f"{method} not recognised"):
334+
forward(f, L, method=method)
335+
336+
337+
def test_inverse_transform_unrecognised_method_raises():
338+
method = "invalid_method"
339+
L = 32
340+
flm = np.zeros(samples.flm_shape(L))
341+
with pytest.raises(ValueError, match=f"{method} not recognised"):
342+
inverse(flm, L, method=method)

0 commit comments

Comments
 (0)