def make_residual_map(self, h, hm, smooth, mc=False, resid_type='fractional'): if mc: h = copy.deepcopy(h) h._counts = np.array(np.random.poisson(hm.counts), dtype='float') if smooth: hm = hm.smooth(self._rsmooth, compute_var=True, summed=True) h = h.smooth(self._rsmooth, compute_var=True, summed=True) ts = 2.0 * (poisson_lnl(h.counts, h.counts) - poisson_lnl(h.counts, hm.counts)) s = h.counts - hm.counts if resid_type == 'fractional': h._counts = s / hm.counts h._var = np.zeros(s.shape) else: sigma = np.sqrt(ts) sigma[s < 0] *= -1 h._counts = sigma h._var = np.zeros(sigma.shape) # h._counts -= hm._counts # h._counts /= np.sqrt(hm._var) return h
def make_residual_map(self,h,hm,smooth,mc=False,resid_type='fractional'): if mc: h = copy.deepcopy(h) h._counts = np.array(np.random.poisson(hm.counts), dtype='float') if smooth: hm = hm.smooth(self._rsmooth,compute_var=True,summed=True) h = h.smooth(self._rsmooth,compute_var=True,summed=True) ts = 2.0*(poisson_lnl(h.counts,h.counts) - poisson_lnl(h.counts,hm.counts)) s = h.counts - hm.counts if resid_type == 'fractional': h._counts = s/hm.counts h._var = np.zeros(s.shape) else: sigma = np.sqrt(ts) sigma[s<0] *= -1 h._counts = sigma h._var = np.zeros(sigma.shape) # h._counts -= hm._counts # h._counts /= np.sqrt(hm._var) return h
def poisson_ts(sig,bkg): return 2*(poisson_lnl(sig+bkg,sig+bkg) - poisson_lnl(sig+bkg,bkg))
def poisson_ts(sig, bkg): return 2 * (poisson_lnl(sig + bkg, sig + bkg) - poisson_lnl(sig + bkg, bkg))