File tree Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change 77
88@u .quantity_input (t_obs = u .hour , t_ref = u .hour ) 
99def  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
8092relative_sensitivity  =  np .vectorize (
Original file line number Diff line number Diff line change 33
44setup (
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' ,
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments