Skip to content

Commit 85a0e1f

Browse files
authored
Merge branch 'master' into remove_mongo
2 parents 7a9cfcf + 1a9e3b3 commit 85a0e1f

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

Diff for: fact/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.26.0
1+
0.26.0

Diff for: 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

Diff for: fact/io.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,26 @@ def read_simulated_spectrum(corsika_headers_path):
546546
runs = read_h5py(corsika_headers_path, key='corsika_runs')
547547

548548
summary = {}
549-
try:
550-
summary['n_showers'] = runs['n_showers'].sum()
551-
except KeyError:
552-
summary['n_showers'] = runs['n_events'].sum()
549+
if 'n_showers' in runs.columns:
550+
n_showers = runs['n_showers']
551+
else:
552+
n_showers = runs['n_events']
553+
554+
summary['n_showers'] = n_showers.sum()
555+
556+
with h5py.File(corsika_headers_path, 'r') as f:
557+
summary['n_reuse'] = f['corsika_runs'].attrs.get('n_reuse', 1)
558+
559+
if 'n_reuse' in runs.columns:
560+
# if reuse is not the same for all runs, multply n_showers
561+
# and set reuse to 1
562+
unique = runs['reuse'].unique()
563+
if len(unique) > 1:
564+
summary['n_showers'] = (n_showers * runs['n_reuse']).sum()
565+
summary['n_reuse'] = 1
566+
567+
else:
568+
summary['n_reuse'] = runs['n_reuse'].iloc[0]
553569

554570
keys = {'energy_min': u.GeV, 'energy_max': u.GeV, 'energy_spectrum_slope': None}
555571
if 'x_scatter' in runs.columns:

Diff for: 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)