Skip to content

Commit 1f12fe9

Browse files
committed
Fix sensitivity for negative signla
1 parent 3a5fd5a commit 1f12fe9

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

irf/sensitivity.py

+23-11
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
@u.quantity_input(t_obs=u.hour, t_ref=u.hour)
99
def relative_sensitivity(
10-
n_on,
11-
n_off,
12-
alpha,
13-
t_obs,
14-
t_ref=50*u.hour,
15-
target_significance=5,
16-
significance_function=li_ma_significance,
17-
):
10+
n_on,
11+
n_off,
12+
alpha,
13+
t_obs,
14+
t_ref=50*u.hour,
15+
target_significance=5,
16+
significance_function=li_ma_significance,
17+
initial_guess=0.5,
18+
):
1819
'''
1920
Calculate the relative sensitivity defined as the flux
2021
relative to the reference source that is detectable with
@@ -52,6 +53,8 @@ def relative_sensitivity(
5253
"Analysis methods for results in gamma-ray astronomy."
5354
The Astrophysical Journal 272 (1983): 317-324.
5455
Formula (17)
56+
initial_guess: float
57+
Initial guess for the root finder
5558
'''
5659

5760
ratio = (t_ref / t_obs).si
@@ -64,17 +67,26 @@ def relative_sensitivity(
6467
if np.isnan(n_on) or np.isnan(n_off):
6568
return np.nan
6669

70+
if n_on == 0 or n_off == 0:
71+
return np.nan
72+
73+
if n_signal <= 0:
74+
return np.nan
75+
6776
def equation(relative_flux):
6877
n_on = n_signal * relative_flux + n_background
6978
return significance_function(n_on, n_off, alpha) - target_significance
7079

7180
try:
72-
phi_rel = newton(equation, x0=1.0)
81+
result = newton(
82+
equation,
83+
x0=initial_guess,
84+
)
7385
except RuntimeError:
7486
warnings.warn('Could not calculate relative significance, returning nan')
75-
phi_rel = np.nan
87+
return np.nan
7688

77-
return phi_rel
89+
return result
7890

7991

8092
relative_sensitivity = np.vectorize(

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='irf',
6-
version='0.2.1',
6+
version='0.3.0',
77
description='Functions to do instrument response functions for FACT',
88
url='http://github.com/fact-project/irf',
99
author='Kai Brügge, Maximilian Nöthe',

0 commit comments

Comments
 (0)