File tree 2 files changed +24
-12
lines changed
2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change 7
7
8
8
@u .quantity_input (t_obs = u .hour , t_ref = u .hour )
9
9
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
+ ):
18
19
'''
19
20
Calculate the relative sensitivity defined as the flux
20
21
relative to the reference source that is detectable with
@@ -52,6 +53,8 @@ def relative_sensitivity(
52
53
"Analysis methods for results in gamma-ray astronomy."
53
54
The Astrophysical Journal 272 (1983): 317-324.
54
55
Formula (17)
56
+ initial_guess: float
57
+ Initial guess for the root finder
55
58
'''
56
59
57
60
ratio = (t_ref / t_obs ).si
@@ -64,17 +67,26 @@ def relative_sensitivity(
64
67
if np .isnan (n_on ) or np .isnan (n_off ):
65
68
return np .nan
66
69
70
+ if n_on == 0 or n_off == 0 :
71
+ return np .nan
72
+
73
+ if n_signal <= 0 :
74
+ return np .nan
75
+
67
76
def equation (relative_flux ):
68
77
n_on = n_signal * relative_flux + n_background
69
78
return significance_function (n_on , n_off , alpha ) - target_significance
70
79
71
80
try :
72
- phi_rel = newton (equation , x0 = 1.0 )
81
+ result = newton (
82
+ equation ,
83
+ x0 = initial_guess ,
84
+ )
73
85
except RuntimeError :
74
86
warnings .warn ('Could not calculate relative significance, returning nan' )
75
- phi_rel = np .nan
87
+ return np .nan
76
88
77
- return phi_rel
89
+ return result
78
90
79
91
80
92
relative_sensitivity = np .vectorize (
Original file line number Diff line number Diff line change 3
3
4
4
setup (
5
5
name = 'irf' ,
6
- version = '0.2.1 ' ,
6
+ version = '0.3.0 ' ,
7
7
description = 'Functions to do instrument response functions for FACT' ,
8
8
url = 'http://github.com/fact-project/irf' ,
9
9
author = 'Kai Brügge, Maximilian Nöthe' ,
You can’t perform that action at this time.
0 commit comments