Skip to content

Commit 7bf25e7

Browse files
authored
Merge pull request #130 from fact-project/fix_unit
Fix unit conversion in power_law_integral
2 parents 1f4756e + e7a24c1 commit 7bf25e7

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

fact/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.25.0
1+
0.25.1

fact/analysis/statistics.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ def power_law_integral(
407407
res = flux_normalization * e_ref / int_index * e_term
408408

409409
if flux_normalization.unit.is_equivalent(FLUX_UNIT):
410-
return res.to(FLUX_UNIT)
411-
return res.to(POINT_SOURCE_FLUX_UNIT)
410+
return res.to(FLUX_UNIT * u.GeV)
411+
return res.to(POINT_SOURCE_FLUX_UNIT * u.GeV)
412412

413413

414414
@u.quantity_input

tests/test_analysis.py

+17
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,20 @@ def test_power():
2626

2727
with raises(ValueError):
2828
random_power(2.7, 5 * u.GeV, 10 * u.GeV, e_ref=1 * u.GeV, size=1)
29+
30+
31+
def test_power_law_integral():
32+
from fact.analysis.statistics import power_law_integral, FLUX_UNIT
33+
import astropy.units as u
34+
import numpy as np
35+
36+
# wolfram alpha result https://www.wolframalpha.com/input/?i=int_100%5E1000+x%5E-2
37+
result = power_law_integral(
38+
flux_normalization=1 * FLUX_UNIT,
39+
spectral_index=-2,
40+
e_min=100 * u.GeV,
41+
e_max=1000 * u.GeV,
42+
e_ref=1 * u.GeV,
43+
)
44+
assert np.isclose(result.value, 0.009)
45+
assert result.unit == (FLUX_UNIT * u.GeV)

0 commit comments

Comments
 (0)