Beispiel #1
0
def test_get_critical_surface_density(modeling_data):
    """ Validation test for critical surface density """
    cfg = load_validation_config()
    assert_allclose(
        md.get_critical_surface_density(
            cfg['cosmo'],
            z_cluster=cfg['TEST_CASE']['z_cluster'],
            z_source=cfg['TEST_CASE']['z_source']),
        cfg['TEST_CASE']['nc_Sigmac'], 1.2e-8)
    # Check behaviour when sources are in front of the lens
    z_cluster = 0.3
    z_source = 0.2
    assert_allclose(
        md.get_critical_surface_density(cfg['cosmo'],
                                        z_cluster=z_cluster,
                                        z_source=z_source), np.inf, 1.0e-10)
    z_source = [0.2, 0.12, 0.25]
    assert_allclose(
        md.get_critical_surface_density(cfg['cosmo'],
                                        z_cluster=z_cluster,
                                        z_source=z_source),
        [np.inf, np.inf, np.inf], 1.0e-10)
    # Check usage with cluster object function
    z_src = np.array([cfg['TEST_CASE']['z_source']])
    cluster = GalaxyCluster(unique_id='blah',
                            ra=0,
                            dec=0,
                            z=cfg['TEST_CASE']['z_cluster'],
                            galcat=GCData([0 * z_src, 0 * z_src, z_src],
                                          names=('ra', 'dec', 'z')))
    cluster.add_critical_surface_density(cfg['cosmo'])
    assert_allclose(cluster.galcat['sigma_c'], cfg['TEST_CASE']['nc_Sigmac'],
                    1.2e-8)
Beispiel #2
0
def test_shear_convergence_unittests():
    """ Unit and validation tests for the shear and convergence calculations """
    helper_physics_functions(md.predict_tangential_shear)
    helper_physics_functions(md.predict_convergence)
    helper_physics_functions(md.predict_reduced_tangential_shear)

    # Validation Tests =========================
    # NumCosmo makes different choices for constants (Msun). We make this conversion
    # by passing the ratio of SOLAR_MASS in kg from numcosmo and CLMM
    cfg = load_validation_config()
    constants_conversion = clc.SOLAR_MASS.value / cfg['TEST_CASE']['Msun[kg]']

    # First compute SigmaCrit to correct cosmology changes
    cosmo = cfg['cosmo']
    sigma_c = md.get_critical_surface_density(cosmo,
                                              cfg['GAMMA_PARAMS']['z_cluster'],
                                              cfg['z_source'])

    # Patch a conversion for cluster_toolkit computations
    cosmo['Omega_c'] = cosmo['Omega_c'] * constants_conversion
    cosmo['Omega_b'] = cosmo['Omega_b'] * constants_conversion

    # Compute sigma_c in the new cosmology and get a correction factor
    sigcrit_corr = cfg['SIGMAC_PHYSCONST_CORRECTION']
    sigma_c_undo = md.get_critical_surface_density(
        cosmo, cfg['GAMMA_PARAMS']['z_cluster'], +cfg['z_source'])
    sigmac_corr = sigma_c_undo / sigma_c / sigcrit_corr

    # Chech error is raised if too small radius
    assert_raises(ValueError, md.predict_tangential_shear, 1.e-12, 1.e15, 4,
                  0.2, 0.45, cosmo)

    # Validate tangential shear
    gammat = md.predict_tangential_shear(cosmo=cosmo, **cfg['GAMMA_PARAMS'])
    assert_allclose(gammat * sigmac_corr, cfg['numcosmo_profiles']['gammat'],
                    1.0e-8)

    # Validate convergence
    kappa = md.predict_convergence(cosmo=cosmo, **cfg['GAMMA_PARAMS'])
    assert_allclose(kappa * sigmac_corr, cfg['numcosmo_profiles']['kappa'],
                    1.0e-8)

    # Validate reduced tangential shear
    assert_allclose(
        md.predict_reduced_tangential_shear(cosmo=cosmo,
                                            **cfg['GAMMA_PARAMS']),
        gammat / (1.0 - kappa), 1.0e-10)
    assert_allclose(gammat / (1. / sigmac_corr - kappa),
                    cfg['numcosmo_profiles']['gt'], 1.0e-6)
Beispiel #3
0
def test_get_critical_surface_density():
    """ Validation test for critical surface density """
    cfg = load_validation_config()
    assert_allclose(cfg['SIGMAC_PHYSCONST_CORRECTION']*\
                    md.get_critical_surface_density(cfg['cosmo'],
                                                    z_cluster=cfg['TEST_CASE']['z_cluster'],
                                                    z_source=cfg['TEST_CASE']['z_source']),
                    cfg['TEST_CASE']['nc_Sigmac'], 1.0e-8)
Beispiel #4
0
def test_shear_convergence_unittests(modeling_data):
    """ Unit and validation tests for the shear and convergence calculations """
    helper_physics_functions(md.predict_tangential_shear)
    helper_physics_functions(md.predict_convergence)
    helper_physics_functions(md.predict_reduced_tangential_shear)
    helper_physics_functions(md.predict_magnification)

    # Validation Tests -------------------------
    # NumCosmo makes different choices for constants (Msun). We make this conversion
    # by passing the ratio of SOLAR_MASS in kg from numcosmo and CLMM
    cfg = load_validation_config()
    constants_conversion = clc.SOLAR_MASS.value / cfg['TEST_CASE']['Msun[kg]']

    # First compute SigmaCrit to correct cosmology changes
    cosmo = cfg['cosmo']
    sigma_c = md.get_critical_surface_density(cosmo,
                                              cfg['GAMMA_PARAMS']['z_cluster'],
                                              cfg['z_source'])

    # Compute sigma_c in the new cosmology and get a correction factor
    sigma_c_undo = md.get_critical_surface_density(
        cosmo, cfg['GAMMA_PARAMS']['z_cluster'], cfg['z_source'])
    sigmac_corr = (sigma_c_undo / sigma_c)

    # Chech error is raised if too small radius
    assert_raises(ValueError, md.predict_tangential_shear, 1.e-12, 1.e15, 4,
                  0.2, 0.45, cosmo)

    # Validate tangential shear
    gammat = md.predict_tangential_shear(cosmo=cosmo, **cfg['GAMMA_PARAMS'])
    assert_allclose(gammat * sigmac_corr, cfg['numcosmo_profiles']['gammat'],
                    1.0e-8)

    # Validate convergence
    kappa = md.predict_convergence(cosmo=cosmo, **cfg['GAMMA_PARAMS'])
    assert_allclose(kappa * sigmac_corr, cfg['numcosmo_profiles']['kappa'],
                    1.0e-8)

    # Validate reduced tangential shear
    assert_allclose(
        md.predict_reduced_tangential_shear(cosmo=cosmo,
                                            **cfg['GAMMA_PARAMS']),
        gammat / (1.0 - kappa), 1.0e-10)
    assert_allclose(gammat * sigmac_corr / (1. - (kappa * sigmac_corr)),
                    cfg['numcosmo_profiles']['gt'], 1.0e-6)

    # Validate magnification
    assert_allclose(
        md.predict_magnification(cosmo=cosmo, **cfg['GAMMA_PARAMS']),
        1. / ((1 - kappa)**2 - abs(gammat)**2), 1.0e-10)
    assert_allclose(1. / ((1 - kappa)**2 - abs(gammat)**2),
                    cfg['numcosmo_profiles']['mu'], 4.0e-7)

    # Check that shear, reduced shear and convergence return zero and magnification returns one if source is in front of the cluster
    # First, check for a array of radius and single source z
    r = np.logspace(-2, 2, 10)
    z_cluster = 0.3
    z_source = 0.2

    assert_allclose(
        md.predict_convergence(r,
                               mdelta=1.e15,
                               cdelta=4.,
                               z_cluster=z_cluster,
                               z_source=z_source,
                               cosmo=cosmo), np.zeros(len(r)), 1.0e-10)
    assert_allclose(
        md.predict_tangential_shear(r,
                                    mdelta=1.e15,
                                    cdelta=4.,
                                    z_cluster=z_cluster,
                                    z_source=z_source,
                                    cosmo=cosmo), np.zeros(len(r)), 1.0e-10)
    assert_allclose(
        md.predict_reduced_tangential_shear(r,
                                            mdelta=1.e15,
                                            cdelta=4.,
                                            z_cluster=z_cluster,
                                            z_source=z_source,
                                            cosmo=cosmo), np.zeros(len(r)),
        1.0e-10)
    assert_allclose(
        md.predict_magnification(r,
                                 mdelta=1.e15,
                                 cdelta=4.,
                                 z_cluster=z_cluster,
                                 z_source=z_source,
                                 cosmo=cosmo), np.ones(len(r)), 1.0e-10)

    # Second, check a single radius and array of source z
    r = 1.
    z_source = [0.25, 0.1, 0.14, 0.02]
    assert_allclose(
        md.predict_convergence(r,
                               mdelta=1.e15,
                               cdelta=4.,
                               z_cluster=z_cluster,
                               z_source=z_source,
                               cosmo=cosmo), np.zeros(len(z_source)), 1.0e-10)
    assert_allclose(
        md.predict_tangential_shear(r,
                                    mdelta=1.e15,
                                    cdelta=4.,
                                    z_cluster=z_cluster,
                                    z_source=z_source,
                                    cosmo=cosmo), np.zeros(len(z_source)),
        1.0e-10)
    assert_allclose(
        md.predict_reduced_tangential_shear(r,
                                            mdelta=1.e15,
                                            cdelta=4.,
                                            z_cluster=z_cluster,
                                            z_source=z_source,
                                            cosmo=cosmo),
        np.zeros(len(z_source)), 1.0e-10)
    assert_allclose(
        md.predict_magnification(r,
                                 mdelta=1.e15,
                                 cdelta=4.,
                                 z_cluster=z_cluster,
                                 z_source=z_source,
                                 cosmo=cosmo), np.ones(len(z_source)), 1.0e-10)