Skip to content

Commit 58efd99

Browse files
committed
fix: raise for invalid beta
1 parent 58196ca commit 58efd99

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

jax_galsim/moffat.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from functools import partial
22

3+
import equinox
34
import galsim as _galsim
45
import jax
56
import jax.numpy as jnp
@@ -31,7 +32,7 @@ def _Knu(nu, x):
3132
lax_description="""\
3233
The JAX-GalSim version of the Moffat profile
3334
34-
- does not support truncation or beta < 1.1
35+
- does not support truncation or beta <= 1.1
3536
- does not support gsparams.maxk_thresholds > 0.1
3637
- does not support autodiff with respect to the `beta` parameter
3738
for Fourier-space evaluations
@@ -67,6 +68,18 @@ def __init__(
6768
f"(got trunc={repr(trunc)}, always pass the constant 0.0)!"
6869
)
6970

71+
if isinstance(beta, (float, int)):
72+
if beta <= self._beta_thr:
73+
raise ValueError(
74+
f"JAX-GalSim does not support Moffat beta values <= {self._beta_thr}."
75+
)
76+
else:
77+
beta = equinox.error_if(
78+
jnp.array(beta),
79+
beta <= self._beta_thr,
80+
f"JAX-GalSim does not support Moffat beta values <= {self._beta_thr}.",
81+
)
82+
7083
# Parse the radius options
7184
if half_light_radius is not None:
7285
if scale_radius is not None or fwhm is not None:

tests/jax/test_moffat_jax.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import jax
2+
import jax.numpy as jnp
3+
import pytest
4+
5+
import jax_galsim
6+
7+
8+
def test_moffat_jax_beta_raises():
9+
10+
@jax.jit
11+
def make_moffat(beta):
12+
return jax_galsim.Moffat(beta, fwhm=1.0)
13+
14+
with pytest.raises(Exception):
15+
make_moffat(jnp.array(1.1))
16+
17+
with pytest.raises(Exception):
18+
make_moffat(0.9)

0 commit comments

Comments
 (0)