Skip to content

Commit 771c6f0

Browse files
authored
Merge pull request #515 from PyAutoLabs/feature/sersic-core-effective-radius-zero
fix: SersicCore.intensity_prime ZeroDivisionError on effective_radius=0 (#514)
2 parents 59eef99 + 05bb532 commit 771c6f0

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

autogalaxy/profiles/light/standard/sersic_core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def intensity_prime(self, xp=np) -> float:
6464
* (2.0 ** (-self.gamma / self.alpha))
6565
* xp.exp(
6666
self.sersic_constant
67-
* (
68-
((2.0 ** (1.0 / self.alpha)) * self.radius_break)
69-
/ self.effective_radius
67+
* xp.divide(
68+
(2.0 ** (1.0 / self.alpha)) * self.radius_break,
69+
self.effective_radius,
7070
)
7171
** (1.0 / self.sersic_index)
7272
)

test_autogalaxy/profiles/light/standard/test_sersic_core.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import division, print_function
2+
import numpy as np
23
import pytest
34

45
import autogalaxy as ag
@@ -22,6 +23,28 @@ def test__image_2d_from__elliptical__ell_comps_nonzero__correct_value():
2223
assert image == pytest.approx(0.0255173, 1.0e-4)
2324

2425

26+
def test__intensity_prime__effective_radius_zero__non_finite_not_zero_division():
27+
# A degenerate `effective_radius=0` (e.g. a non-linear search proposing an
28+
# unphysical value, or a wavelength-relation instance evaluating to 0) must
29+
# yield a non-finite value the search resamples on, not a hard
30+
# ``ZeroDivisionError`` — matching every other profile's array division.
31+
lp = ag.lp.SersicCore(
32+
effective_radius=0.0,
33+
sersic_index=4.0,
34+
radius_break=0.01,
35+
intensity=0.1,
36+
gamma=1.0,
37+
alpha=1.0,
38+
)
39+
40+
value = lp.intensity_prime()
41+
42+
assert not np.isfinite(value)
43+
44+
# The full image path must not raise either.
45+
lp.image_2d_from(grid=ag.Grid2DIrregular([[0.0, 0.1]]))
46+
47+
2548
def test__image_2d_from__spherical_profile__matches_elliptical_with_zero_ellipticity():
2649
elliptical = ag.lp.SersicCore(
2750
ell_comps=(0.0, 0.0),

0 commit comments

Comments
 (0)