Skip to content

Commit 977f2ec

Browse files
Fix integration instabilities
1 parent 14b5485 commit 977f2ec

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

skyllh/core/flux_model.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,14 @@ def get_integral(
814814
integral = np.empty((len(E1),), dtype=np.float64)
815815

816816
for (i, (E1_i, E2_i)) in enumerate(zip(E1, E2)):
817-
integral[i] = quad(self, E1_i, E2_i, full_output=True)[0]
817+
818+
# integration for log(energy) for hopefully better numerical stability
819+
tmp_e = np.linspace(np.log10(E1_i), np.log10(E2_i), 5000)
820+
tmp_int = np.trapz(np.log(10) * self(10**tmp_e) * 10**tmp_e, tmp_e)
821+
822+
# make sure it is always positive (probably not an issue any more with np.trapz.
823+
# used to be an issue using the spline integrate self.function.integrate)
824+
integral[i] = max(0.0, tmp_int)
818825

819826
return integral
820827

0 commit comments

Comments
 (0)