|
| 1 | +import numpy as np |
| 2 | +import astropy.units as u |
| 3 | +import uncertainties as unc |
| 4 | +import uncertainties.unumpy as unp |
| 5 | + |
| 6 | + |
| 7 | +@u.quantity_input(t_obs=u.hour, t_ref=u.hour) |
| 8 | +def relative_sensitivity( |
| 9 | + n_on, |
| 10 | + n_off, |
| 11 | + alpha, |
| 12 | + t_obs, |
| 13 | + t_ref=50*u.hour, |
| 14 | + significance=5, |
| 15 | + ): |
| 16 | + ''' |
| 17 | + Calculate the relative sensitivity defined as the flux |
| 18 | + relative to the reference source that is detectable with |
| 19 | + significance in t_ref. |
| 20 | +
|
| 21 | + Parameters |
| 22 | + ---------- |
| 23 | + n_on: int or array-like |
| 24 | + Number of signal-like events for the on observations |
| 25 | + n_off: int or array-like |
| 26 | + Number of signal-like events for the off observations |
| 27 | + alpha: float |
| 28 | + Scaling factor between on and off observations. |
| 29 | + 1 / number of off regions for wobble observations. |
| 30 | + t_obs: astropy.units.Quantity of type time |
| 31 | + Total observation time |
| 32 | + t_ref: astropy.units.Quantity of type time |
| 33 | + Reference time for the detection |
| 34 | + significance: float |
| 35 | + Significance necessary for a detection |
| 36 | + ''' |
| 37 | + ratio = (t_obs / t_ref).decompose().value |
| 38 | + |
| 39 | + n_on = unp.uarray(n_on, np.sqrt(n_on)) |
| 40 | + n_off = unp.uarray(n_off, np.sqrt(n_off)) |
| 41 | + |
| 42 | + t_off = n_off * unp.log(n_off * (1 + alpha) / (n_on + n_off)) |
| 43 | + t_on = n_on * unp.log(n_on * (1 + alpha) / alpha / (n_on + n_off)) |
| 44 | + |
| 45 | + sensitivity = significance**2 / 2 * ratio / (t_on + t_off) |
| 46 | + |
| 47 | + return unp.nominal_values(sensitivity), unp.std_devs(sensitivity) |
0 commit comments