예제 #1
0
def test_update_richness():
    c = ClusterEnsemble(toy_data_z)

    def _check_n_and_m(i):
        assert_equal(c.n200, toy_data_n200[i])
        assert_allclose(c.m200.value, toy_data_m200[i])

    def _check_radii(i):
        assert_allclose(c.r200.value, toy_data_r200[i])
        assert_allclose(c.rs.value, toy_data_rs[i])

    def _check_c200(i):
        assert_allclose(toy_data_c200[i], c.c200)
        if c.c200 is np.real:
            assert_allclose(toy_data_r200[i] / toy_data_rs[i], c.c200)
        else:
            assert(toy_data_r200[i] / toy_data_rs[i] is not np.real)

    def _check_delta_c(i):
        assert_allclose(toy_data_deltac[i], c.delta_c)

    for i, n200 in enumerate(toy_data_n200):
        c.n200 = n200
        yield _check_n_and_m, i
        yield _check_radii, i
        yield _check_c200, i
        yield _check_delta_c, i
예제 #2
0
def test_update_richness():
    c = ClusterEnsemble(toy_data_z)

    def _check_n_and_m(i):
        assert_equal(c.n200, toy_data_n200[i])
        assert_allclose(c.m200.value, toy_data_m200[i])

    def _check_radii(i):
        assert_allclose(c.r200.value, toy_data_r200[i])
        assert_allclose(c.rs.value, toy_data_rs[i])

    def _check_c200(i):
        assert_allclose(toy_data_c200[i], c.c200)
        if c.c200 is np.real:
            assert_allclose(toy_data_r200[i] / toy_data_rs[i], c.c200)
        else:
            assert (toy_data_r200[i] / toy_data_rs[i] is not np.real)

    def _check_delta_c(i):
        assert_allclose(toy_data_deltac[i], c.delta_c)

    for i, n200 in enumerate(toy_data_n200):
        c.n200 = n200
        yield _check_n_and_m, i
        yield _check_radii, i
        yield _check_c200, i
        yield _check_delta_c, i
예제 #3
0
def test_update_norm():
    c = ClusterEnsemble(toy_data_z)
    c.n200 = [10, 20]
    norm_before = c._massrich_norm.value
    norm_after = 2. * norm_before
    m_before = c.m200
    c.massrich_norm = norm_after
    m_after = c.m200
    assert_equal(m_before / m_after, np.array([norm_before / norm_after] * 2))
예제 #4
0
def test_update_norm():
    c = ClusterEnsemble(toy_data_z)
    c.n200 = [10, 20]
    norm_before = c._massrich_norm.value
    norm_after = 2. * norm_before
    m_before = c.m200
    c.massrich_norm = norm_after
    m_after = c.m200
    assert_equal(m_before / m_after, np.array([norm_before / norm_after] * 2))
예제 #5
0
def test_update_slope():
    c = ClusterEnsemble(toy_data_z)
    c.n200 = [10, 20]
    slope_before = c._massrich_slope
    slope_after = 2.
    m_before = c.m200
    c.massrich_slope = slope_after
    m_after = c.m200
    assert_equal(m_before[1], m_after[1])
    assert_equal(m_before[0] / m_after[0], (0.5**slope_before) /
                 (0.5**slope_after))
예제 #6
0
def test_update_slope():
    c = ClusterEnsemble(toy_data_z)
    c.n200 = [10, 20]
    slope_before = c._massrich_slope
    slope_after = 2.
    m_before = c.m200
    c.massrich_slope = slope_after
    m_after = c.m200
    assert_equal(m_before[1], m_after[1])
    assert_equal(m_before[0] / m_after[0],
                 (0.5**slope_before) / (0.5**slope_after))
예제 #7
0
def test_nfw_centered():
    c = ClusterEnsemble(toy_data_z)

    def _check_sigma(i, j):
        assert_allclose(c.sigma_nfw[j].value, toy_data_sigma[i, j],
                        rtol=1e-4)

    def _check_deltasigma(i, j):
        assert_allclose(c.deltasigma_nfw[j].value, toy_data_deltasigma[i, j],
                        rtol=1e-4)

    for i, n200 in enumerate(toy_data_n200):
        c.n200 = n200
        c.calc_nfw(toy_data_rbins)
        for j in range(c.z.shape[0]):
            yield _check_sigma, i, j
            yield _check_deltasigma, i, j
예제 #8
0
def test_nfw_centered():
    c = ClusterEnsemble(toy_data_z)

    def _check_sigma(i, j):
        assert_allclose(c.sigma_nfw[j].value, toy_data_sigma[i, j], rtol=1e-4)

    def _check_deltasigma(i, j):
        assert_allclose(c.deltasigma_nfw[j].value,
                        toy_data_deltasigma[i, j],
                        rtol=1e-4)

    for i, n200 in enumerate(toy_data_n200):
        c.n200 = n200
        c.calc_nfw(toy_data_rbins)
        for j in range(c.z.shape[0]):
            yield _check_sigma, i, j
            yield _check_deltasigma, i, j
예제 #9
0
def test_nfw_offset():
    c = ClusterEnsemble(toy_data_z)

    def _check_sigma(i, j):
        assert_allclose(c.sigma_nfw[j].value, toy_data_sigma_off[i, j],
                        rtol=10**-4)

    def _check_deltasigma(i, j):
        assert_allclose(c.deltasigma_nfw[j].value,
                        toy_data_deltasigma_off[i, j],
                        rtol=10**-4)

    for i, n200 in enumerate(toy_data_n200[:-1]):
        c.n200 = n200
        c.calc_nfw(toy_data_rbins, offsets=toy_data_offset)
        for j in range(c.z.shape[0]):
            yield _check_sigma, i, j
            yield _check_deltasigma, i, j
예제 #10
0
def test_nfw_offset():
    c = ClusterEnsemble(toy_data_z)

    def _check_sigma(i, j):
        assert_allclose(c.sigma_nfw[j].value,
                        toy_data_sigma_off[i, j],
                        rtol=10**-4)

    def _check_deltasigma(i, j):
        assert_allclose(c.deltasigma_nfw[j].value,
                        toy_data_deltasigma_off[i, j],
                        rtol=10**-4)

    for i, n200 in enumerate(toy_data_n200[:-1]):
        c.n200 = n200
        c.calc_nfw(toy_data_rbins, offsets=toy_data_offset)
        for j in range(c.z.shape[0]):
            yield _check_sigma, i, j
            yield _check_deltasigma, i, j
예제 #11
0
def test_for_infs_in_miscentered_c_calc():
    c = ClusterEnsemble(toy_data_z)

    def _check_sigma_off(arr):
        if np.isnan(arr.sum()):
            raise ValueError('sigma_off result contains NaN', arr)
        if np.isinf(arr.sum()):
            raise ValueError('sigma_off result contains Inf', arr)

    def _check_deltasigma_off(arr):
        if np.isnan(arr.sum()):
            raise ValueError('sigma_off result contains NaN', arr)
        if np.isinf(arr.sum()):
            raise ValueError('sigma_off result contains Inf', arr)

    # last element in toy_data is n200=0 -> NaN (skip for this check)
    for n200 in toy_data_n200[:-1]:
        c.n200 = n200
        c.calc_nfw(toy_data_rbins, offsets=toy_data_offset)
        for i in range(c.z.shape[0]):
            yield _check_sigma_off, c.sigma_nfw[i].value
            yield _check_deltasigma_off, c.deltasigma_nfw[i].value
예제 #12
0
def test_for_infs_in_miscentered_c_calc():
    c = ClusterEnsemble(toy_data_z)

    def _check_sigma_off(arr):
        if np.isnan(arr.sum()):
            raise ValueError('sigma_off result contains NaN', arr)
        if np.isinf(arr.sum()):
            raise ValueError('sigma_off result contains Inf', arr)

    def _check_deltasigma_off(arr):
        if np.isnan(arr.sum()):
            raise ValueError('sigma_off result contains NaN', arr)
        if np.isinf(arr.sum()):
            raise ValueError('sigma_off result contains Inf', arr)

    # last element in toy_data is n200=0 -> NaN (skip for this check)
    for n200 in toy_data_n200[:-1]:
        c.n200 = n200
        c.calc_nfw(toy_data_rbins, offsets=toy_data_offset)
        for i in range(c.z.shape[0]):
            yield _check_sigma_off, c.sigma_nfw[i].value
            yield _check_deltasigma_off, c.deltasigma_nfw[i].value