def test_zn_poisson(self): phases = self.phases prof512, bins = self.prof512, self.bins ks, ze = z_n_events_all(phases, nmax=10) ksp, zp = z_n_binned_events_all(prof512, nmax=10) assert np.allclose(ze, zp, rtol=0.01) m, h = htest(prof512, datatype="binned", nmax=10) assert np.isclose(h + 4 * m - 4, z_n(prof512, n=m, datatype="binned")) assert np.isclose(h + 4 * m - 4, zp[m - 1])
def test_zn_gauss(self): nbin = 512 dph = 1 / nbin err = 0.1 ph = np.arange(-0.5 + dph / 2, 0.5, dph) prof = np.random.normal(np.exp(-ph**2 / 2 / 0.1**2), err) prof_poiss = poissonize_gaussian_profile(prof, err) ksp, zp = z_n_binned_events_all(prof_poiss, nmax=10) ksg, zg = z_n_gauss_all(prof, err, nmax=10) assert np.allclose(zg, zp, rtol=0.01) mg, hg = htest(prof, err=err, datatype="gauss", nmax=10) mp, hp = htest(prof_poiss, datatype="binned", nmax=10) assert np.isclose(hg, hp) assert np.isclose(mg, mp) assert np.isclose(hg + 4 * mg - 4, z_n(prof, n=mg, err=err, datatype="gauss"))
def test_wrong_args_H_gauss_noerr(self): with pytest.raises(ValueError) as excinfo: htest([1], 2, datatype="gauss") assert "If datatype='gauss', you need to " in str(excinfo.value)
def test_wrong_args_H_datatype(self): with pytest.raises(ValueError) as excinfo: htest([1], 2, datatype="gibberish") assert "Unknown datatype requested for htest (gibberish)" in str( excinfo.value)
def test_zn_events(self): phases = self.phases ks, ze = z_n_events_all(phases, nmax=10) m, h = htest(phases, nmax=10, datatype="events") assert np.isclose(h + 4 * m - 4, z_n(phases, n=m, datatype="events")) assert np.isclose(h + 4 * m - 4, ze[m - 1])