Exemplo n.º 1
0
def test_integrity_of_lensfuncs():
    ra_source, dec_source = [120.1, 119.9, 119.9], [41.9, 42.2, 42.2]
    id_source, z_sources = [1, 2, 3], [1, 1, 1]
    galcat = GCData([ra_source, dec_source, z_sources, id_source],
                    names=('ra', 'dec', 'z', 'id'))
    galcatNoZ = GCData([ra_source, dec_source, id_source],
                       names=('ra', 'dec', 'id'))
    cosmo = clmm.Cosmology(H0=70.0, Omega_dm0=0.275, Omega_b0=0.025)
    # Missing cosmo
    cl = clmm.GalaxyCluster(unique_id='1',
                            ra=161.3,
                            dec=34.,
                            z=0.3,
                            galcat=galcat)
    assert_raises(TypeError, cl.add_critical_surface_density, None)
    # Missing cl redshift
    cl = clmm.GalaxyCluster(unique_id='1',
                            ra=161.3,
                            dec=34.,
                            z=0.3,
                            galcat=galcat)
    cl.z = None
    assert_raises(TypeError, cl.add_critical_surface_density, cosmo)
    # Missing galaxy redshift
    cl = clmm.GalaxyCluster(unique_id='1',
                            ra=161.3,
                            dec=34.,
                            z=0.3,
                            galcat=galcatNoZ)
    assert_raises(TypeError, cl.add_critical_surface_density, cosmo)
Exemplo n.º 2
0
def test_compute_tangential_and_cross_components(modeling_data):
    # Input values
    reltol = modeling_data['dataops_reltol']
    ra_lens, dec_lens, z_lens = 120., 42., 0.5
    gals = GCData({
        'ra': np.array([120.1, 119.9]),
        'dec': np.array([41.9, 42.2]),
        'id': np.array([1, 2]),
        'e1': np.array([0.2, 0.4]),
        'e2': np.array([0.3, 0.5]),
        'z': np.array([1.,2.]),
        })
    # Correct values
    expected_flat = {
        'angsep': np.array([0.0021745039090962414, 0.0037238407383072053]),
        'cross_shear': np.array([0.2780316984090899, 0.6398792901134982]),
        'tangential_shear': np.array([-0.22956126563459447, -0.02354769805831558]),
        # DeltaSigma expected values for clmm.Cosmology(H0=67.66, Omega_dm0=0.262, Omega_b0=0.049)
        'cross_DS': np.array([8.58093068e+14, 1.33131522e+15]), #[1224.3326297393244, 1899.6061989365176])*0.7*1.0e12*1.0002565513832675
        'tangential_DS': np.array([-7.08498103e+14, -4.89926917e+13]), #[-1010.889584349285, -69.9059242788237])*0.7*1.0e12*1.0002565513832675
    }
    expected_curve = {# <<TO BE ADDED IN THE FUTURE>>
        'angsep': np.array([]),
        'cross_shear': np.array([]),
        'tangential_shear': np.array([]),
        'cross_DS': np.array([]),
        'tangential_DS': np.array([]),
    }
    # Geometries to test
    geo_tests = [('flat', expected_flat), ('curve', expected_curve)]
    geo_tests = geo_tests[:1] # <<DELETE THIS LINE WHEN CURVE VALUES ADDED>>
    # test incosnsitent data
    testing.assert_raises(TypeError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=gals['ra'][0], dec_source=gals['dec'],
        shear1=gals['e1'], shear2=gals['e2'])
    testing.assert_raises(TypeError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=gals['ra'][:1], dec_source=gals['dec'],
        shear1=gals['e1'], shear2=gals['e2'])
    # test not implemented geometry
    testing.assert_raises(NotImplementedError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=gals['ra'], dec_source=gals['dec'],
        shear1=gals['e1'], shear2=gals['e2'], geometry='something crazy')
    for geometry, expected in geo_tests:
        # Pass arrays directly into function
        angsep, tshear, xshear = da.compute_tangential_and_cross_components(ra_lens=ra_lens, dec_lens=dec_lens,
                                              ra_source=gals['ra'], dec_source=gals['dec'],
                                              shear1=gals['e1'], shear2=gals['e2'], geometry=geometry)
        testing.assert_allclose(angsep, expected['angsep'], **TOLERANCE,
                            err_msg="Angular Separation not correct when passing lists")
        testing.assert_allclose(tshear, expected['tangential_shear'], **TOLERANCE,
                            err_msg="Tangential Shear not correct when passing lists")
        testing.assert_allclose(xshear, expected['cross_shear'], **TOLERANCE,
                            err_msg="Cross Shear not correct when passing lists")
        # Pass LISTS into function
        angsep, tshear, xshear = da.compute_tangential_and_cross_components(ra_lens=ra_lens, dec_lens=dec_lens,
                                    ra_source=list(gals['ra']), dec_source=list(gals['dec']),
                                    shear1=list(gals['e1']), shear2=list(gals['e2']), geometry=geometry)
        testing.assert_allclose(angsep, expected['angsep'], **TOLERANCE,
                                err_msg="Angular Separation not correct when passing lists")
        testing.assert_allclose(tshear, expected['tangential_shear'], **TOLERANCE,
                                err_msg="Tangential Shear not correct when passing lists")
        testing.assert_allclose(xshear, expected['cross_shear'], **TOLERANCE,
                                err_msg="Cross Shear not correct when passing lists")
    # Use the cluster method
    cluster = clmm.GalaxyCluster(unique_id='blah', ra=ra_lens, dec=dec_lens, z=z_lens,
                                 galcat=gals['ra', 'dec', 'e1', 'e2'])
    # Test error with bad name/missing column
    testing.assert_raises(TypeError, cluster.compute_tangential_and_cross_components,
                          shape_component1='crazy name')
    # Test output
    for geometry, expected in geo_tests:
        angsep3, tshear3, xshear3 = cluster.compute_tangential_and_cross_components(geometry=geometry)
        testing.assert_allclose(angsep3, expected['angsep'], **TOLERANCE,
                                err_msg="Angular Separation not correct when using cluster method")
        testing.assert_allclose(tshear3, expected['tangential_shear'], **TOLERANCE,
                                err_msg="Tangential Shear not correct when using cluster method")
        testing.assert_allclose(xshear3, expected['cross_shear'], **TOLERANCE,
                                err_msg="Cross Shear not correct when using cluster method")
    # Check behaviour for the deltasigma option.
    cosmo = clmm.Cosmology(H0=70.0, Omega_dm0=0.275, Omega_b0=0.025)
    # test missing info for is_deltasigma=True
    testing.assert_raises(TypeError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=gals['ra'], dec_source=gals['dec'],
        shear1=gals['e1'], shear2=gals['e2'], is_deltasigma=True, cosmo=None, z_lens=z_lens, z_source=gals['z'])
    testing.assert_raises(TypeError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=gals['ra'], dec_source=gals['dec'],
        shear1=gals['e1'], shear2=gals['e2'], is_deltasigma=True, cosmo=cosmo, z_lens=None, z_source=gals['z'])
    testing.assert_raises(TypeError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=gals['ra'], dec_source=gals['dec'],
        shear1=gals['e1'], shear2=gals['e2'], is_deltasigma=True, cosmo=cosmo, z_lens=z_lens, z_source=None)
    # check values for DeltaSigma
    for geometry, expected in geo_tests:
        angsep_DS, tDS, xDS = da.compute_tangential_and_cross_components(
            ra_lens=ra_lens, dec_lens=dec_lens,
            ra_source=gals['ra'], dec_source=gals['dec'],
            shear1=gals['e1'], shear2=gals['e2'], is_deltasigma=True,
            cosmo=cosmo, z_lens=z_lens, z_source=gals['z'], geometry=geometry)
        testing.assert_allclose(angsep_DS, expected['angsep'], reltol,
                                err_msg="Angular Separation not correct")
        testing.assert_allclose(tDS, expected['tangential_DS'], reltol,
                                err_msg="Tangential Shear not correct")
        testing.assert_allclose(xDS, expected['cross_DS'], reltol,
                                err_msg="Cross Shear not correct")
    # Tests with the cluster object
    # cluster object missing source redshift, and function call missing cosmology
    cluster = clmm.GalaxyCluster(unique_id='blah', ra=ra_lens, dec=dec_lens, z=z_lens,
                                 galcat=gals['ra', 'dec', 'e1', 'e2'])
    testing.assert_raises(TypeError, cluster.compute_tangential_and_cross_components, is_deltasigma=True)
    # cluster object OK but function call missing cosmology
    cluster = clmm.GalaxyCluster(unique_id='blah', ra=ra_lens, dec=dec_lens, z=z_lens,
                                 galcat=gals['ra', 'dec', 'e1', 'e2','z'])
    testing.assert_raises(TypeError, cluster.compute_tangential_and_cross_components, is_deltasigma=True)
    # check values for DeltaSigma
    for geometry, expected in geo_tests:
        angsep_DS, tDS, xDS = cluster.compute_tangential_and_cross_components(cosmo=cosmo, is_deltasigma=True, geometry=geometry)
        testing.assert_allclose(angsep_DS, expected['angsep'], reltol,
                                err_msg="Angular Separation not correct when using cluster method")
        testing.assert_allclose(tDS, expected['tangential_DS'], reltol,
                                err_msg="Tangential Shear not correct when using cluster method")
        testing.assert_allclose(xDS, expected['cross_DS'], reltol,
                                err_msg="Cross Shear not correct when using cluster method")
Exemplo n.º 3
0
###plot style
plt.rcParams['figure.figsize'] = [9.5, 6]
plt.rcParams.update({'font.size': 18})
#plt.rcParams['figure.figsize'] = [10, 8] for big figures

outpath = "/sps/lsst/users/tguillem/DESC/desc_may_2021/desc-data-portal/notebooks/dc2/plots/debug/"
if os.path.exists(outpath):
    shutil.rmtree(outpath)
os.mkdir(outpath)

extragalactic_cat = GCRCatalogs.load_catalog('cosmoDC2_v1.1.4_small')

# Make a CLMM cosmology object from the DC2 cosmology
dc2_cosmo = extragalactic_cat.cosmology
cosmo = clmm.Cosmology(H0=dc2_cosmo.H0.value,
                       Omega_dm0=dc2_cosmo.Om0 - dc2_cosmo.Ob0,
                       Omega_b0=dc2_cosmo.Ob0)

# get list of massive halos in a given redshift and mass range
mmin = 1.e14  # Msun
zmin = 0.3
zmax = 0.4

massive_halos = extragalactic_cat.get_quantities(
    ['halo_mass', 'hostHaloMass', 'redshift', 'ra', 'dec', 'halo_id'],
    filters=[
        f'halo_mass > {mmin}', 'is_central==True', f'redshift>{zmin}',
        f'redshift<{zmax}'
    ])
N_cl = len(massive_halos['halo_mass'])
print(f'There are {N_cl} clusters in this mass and redshift range')
Exemplo n.º 4
0
def test_compute_tangential_and_cross_components(modeling_data):
    # Input values
    ra_lens, dec_lens, z_lens = 120., 42., 0.5
    ra_source = np.array([120.1, 119.9])
    dec_source = np.array([41.9, 42.2])
    z_source = np.array([1.,2.])
    shear1 = np.array([0.2, 0.4])
    shear2 = np.array([0.3, 0.5])
    # Correct values
    expected_angsep = np.array([0.0021745039090962414, 0.0037238407383072053])
    expected_cross_shear = np.array([0.2780316984090899, 0.6398792901134982])
    expected_tangential_shear = np.array([-0.22956126563459447, -0.02354769805831558])
    # DeltaSigma expected values for clmm.Cosmology(H0=70.0, Omega_dm0=0.275, Omega_b0=0.025)
    expected_cross_DS = np.array([1224.3326297393244, 1899.6061989365176])*0.7*1.0e12*1.0002565513832675
    expected_tangential_DS = np.array([-1010.889584349285, -69.9059242788237])*0.7*1.0e12*1.0002565513832675
    # test incosnsitent data
    testing.assert_raises(TypeError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=ra_source[0], dec_source=dec_source,
        shear1=shear1, shear2=shear2)
    testing.assert_raises(TypeError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=ra_source[:1], dec_source=dec_source,
        shear1=shear1, shear2=shear2)
    # test not implemented geometry
    testing.assert_raises(NotImplementedError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=ra_source, dec_source=dec_source,
        shear1=shear1, shear2=shear2, geometry='something crazy')
    # Pass arrays directly into function
    angsep, tshear, xshear = da.compute_tangential_and_cross_components(ra_lens=ra_lens, dec_lens=dec_lens,
                                              ra_source=ra_source, dec_source=dec_source,
                                              shear1=shear1, shear2=shear2)
    testing.assert_allclose(angsep, expected_angsep, **TOLERANCE,
                            err_msg="Angular Separation not correct when passing lists")
    testing.assert_allclose(tshear, expected_tangential_shear, **TOLERANCE,
                            err_msg="Tangential Shear not correct when passing lists")
    testing.assert_allclose(xshear, expected_cross_shear, **TOLERANCE,
                            err_msg="Cross Shear not correct when passing lists")
    # Pass LISTS into function
    angsep, tshear, xshear = da.compute_tangential_and_cross_components(ra_lens=ra_lens, dec_lens=dec_lens,
                                ra_source=list(ra_source), dec_source=list(dec_source),
                                shear1=list(shear1), shear2=list(shear2))
    testing.assert_allclose(angsep, expected_angsep, **TOLERANCE,
                            err_msg="Angular Separation not correct when passing lists")
    testing.assert_allclose(tshear, expected_tangential_shear, **TOLERANCE,
                            err_msg="Tangential Shear not correct when passing lists")
    testing.assert_allclose(xshear, expected_cross_shear, **TOLERANCE,
                            err_msg="Cross Shear not correct when passing lists")
    # Use the cluster method
    cluster = clmm.GalaxyCluster(unique_id='blah', ra=ra_lens, dec=dec_lens, z=z_lens,
                                 galcat=GCData([ra_source, dec_source, shear1, shear2],
                                              names=('ra', 'dec', 'e1', 'e2')))
    # Test error with bad name/missing column
    testing.assert_raises(TypeError, cluster.compute_tangential_and_cross_components,
                          shape_component1='crazy name')
    # Test output
    angsep3, tshear3, xshear3 = cluster.compute_tangential_and_cross_components()
    testing.assert_allclose(angsep3, expected_angsep, **TOLERANCE,
                            err_msg="Angular Separation not correct when using cluster method")
    testing.assert_allclose(tshear3, expected_tangential_shear, **TOLERANCE,
                            err_msg="Tangential Shear not correct when using cluster method")
    testing.assert_allclose(xshear3, expected_cross_shear, **TOLERANCE,
                            err_msg="Cross Shear not correct when using cluster method")
    # Check behaviour for the deltasigma option.
    cosmo = clmm.Cosmology(H0=70.0, Omega_dm0=0.275, Omega_b0=0.025)
    # test missing info for is_deltasigma=True
    testing.assert_raises(TypeError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=ra_source, dec_source=dec_source,
        shear1=shear1, shear2=shear2, is_deltasigma=True, cosmo=None, z_lens=z_lens, z_source=z_source)
    testing.assert_raises(TypeError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=ra_source, dec_source=dec_source,
        shear1=shear1, shear2=shear2, is_deltasigma=True, cosmo=cosmo, z_lens=None, z_source=z_source)
    testing.assert_raises(TypeError, da.compute_tangential_and_cross_components,
        ra_lens=ra_lens, dec_lens=dec_lens, ra_source=ra_source, dec_source=dec_source,
        shear1=shear1, shear2=shear2, is_deltasigma=True, cosmo=cosmo, z_lens=z_lens, z_source=None)
    # check values for DeltaSigma
    angsep_DS, tDS, xDS = da.compute_tangential_and_cross_components(
        ra_lens=ra_lens, dec_lens=dec_lens,
        ra_source=ra_source, dec_source=dec_source,
        shear1=shear1, shear2=shear2, is_deltasigma=True,
        cosmo=cosmo, z_lens=z_lens, z_source=z_source)
    testing.assert_allclose(angsep_DS, expected_angsep, **TOLERANCE,
                            err_msg="Angular Separation not correct")
    testing.assert_allclose(tDS, expected_tangential_DS, **TOLERANCE,
                            err_msg="Tangential Shear not correct")
    testing.assert_allclose(xDS, expected_cross_DS, **TOLERANCE,
                            err_msg="Cross Shear not correct")
    # Tests with the cluster object
    # cluster object missing source redshift, and function call missing cosmology
    cluster = clmm.GalaxyCluster(unique_id='blah', ra=ra_lens, dec=dec_lens, z=z_lens,
                                 galcat=GCData([ra_source, dec_source, shear1, shear2],
                                              names=('ra', 'dec', 'e1', 'e2')))
    testing.assert_raises(TypeError, cluster.compute_tangential_and_cross_components, is_deltasigma=True)
    # cluster object OK but function call missing cosmology
    cluster = clmm.GalaxyCluster(unique_id='blah', ra=ra_lens, dec=dec_lens, z=z_lens,
                                 galcat=GCData([ra_source, dec_source, shear1, shear2, z_source],
                                               names=('ra', 'dec', 'e1', 'e2','z')))
    testing.assert_raises(TypeError, cluster.compute_tangential_and_cross_components, is_deltasigma=True)
    # check values for DeltaSigma
    angsep_DS, tDS, xDS = cluster.compute_tangential_and_cross_components(cosmo=cosmo, is_deltasigma=True)
    testing.assert_allclose(angsep_DS, expected_angsep, **TOLERANCE,
                            err_msg="Angular Separation not correct when using cluster method")
    testing.assert_allclose(tDS, expected_tangential_DS, **TOLERANCE,
                            err_msg="Tangential Shear not correct when using cluster method")
    testing.assert_allclose(xDS, expected_cross_DS, **TOLERANCE,
                            err_msg="Cross Shear not correct when using cluster method")