def test_two_averaged_spectra(self): """ For nspec=2, I can derive this by hand: """ power = 1.0 nspec = 2 manual_pval = 1.0 - avg_cdf_two_spectra(power) assert np.isclose(cospectra_pvalue(power, nspec), manual_pval)
def test_single_spectrum_with_positive_power(self): """ Because the Laplace distribution is always symmetric around zero, let's do a second version where I look for a different number. """ power = 0.69314718055 nspec = 1 assert np.isclose(cospectra_pvalue(power, nspec), 0.25)
def test_single_spectrum(self): # the Laplace distribution is symmetric around # 0, so a power of 0 should return p=0.5 power = 0.0 nspec = 1 assert cospectra_pvalue(power, nspec) == 0.5
def test_pval_fails_if_nspec_not_integer(self): power = 1.0 nspec = 1.5 with pytest.raises(ValueError): pval = cospectra_pvalue(power, nspec)
def test_pval_fails_if_nspec_negative(self): power = 1.0 nspec = -10 with pytest.raises(ValueError): pval = cospectra_pvalue(power, nspec)
def test_pval_fails_if_multiple_powers_inf(self): power = [1, 2.0, np.inf] nspec = 1 with pytest.raises(ValueError): pval = cospectra_pvalue(power, nspec)
def test_pval_fails_if_single_power_nan(self): power = np.nan nspec = 1 with pytest.raises(ValueError): pval = cospectra_pvalue(power, nspec)
def test_pval_returns_iterable_when_iterable_input(self): power = [0, 1, 2] nspec = 1.0 pval = cospectra_pvalue(power, nspec) assert isinstance(pval, np.ndarray) assert len(pval) == len(power)
def test_pval_returns_float_when_float_input(self): power = 1.0 nspec = 1.0 pval = cospectra_pvalue(power, nspec) assert isinstance(pval, float)
def test_sixty_spectra(self): power = 1.0 nspec = 60 gauss = scipy.stats.norm(0, np.sqrt(2 / (nspec + 1))) pval_theory = gauss.sf(power) assert np.isclose(cospectra_pvalue(power, nspec), pval_theory)