How to use the treecorr.config.read_config function in TreeCorr

To help you get started, we’ve selected a few TreeCorr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rmjarvis / TreeCorr / tests / test_nnn.py View on Github external
np.exp(-(d1**2+d2**2+d3**2)/(6.*s**2)) - 1.)

    zeta, varzeta = ddd.calculateZeta(rrr)
    print('zeta = ',zeta.flatten())
    print('true_zeta = ',true_zeta.flatten())
    print('ratio = ',(zeta / true_zeta).flatten())
    print('diff = ',(zeta - true_zeta).flatten())
    print('max rel diff = ',np.max(np.abs((zeta - true_zeta)/true_zeta)))
    np.testing.assert_allclose(zeta, true_zeta, rtol=0.1*tol_factor)
    np.testing.assert_allclose(np.log(np.abs(zeta)), np.log(np.abs(true_zeta)),
                                  atol=0.1*tol_factor)

    # Check that we get the same result using the corr3 functin:
    cat.write(os.path.join('data','nnn_3d_data.dat'))
    rand.write(os.path.join('data','nnn_3d_rand.dat'))
    config = treecorr.config.read_config('configs/nnn_3d.yaml')
    config['verbose'] = 0
    treecorr.corr3(config)
    corr3_output = np.genfromtxt(os.path.join('output','nnn_3d.out'), names=True, skip_header=1)
    print('zeta = ',zeta.flatten())
    print('from corr3 output = ',corr3_output['zeta'])
    print('ratio = ',corr3_output['zeta']/zeta.flatten())
    print('diff = ',corr3_output['zeta']-zeta.flatten())
    np.testing.assert_allclose(corr3_output['zeta'], zeta.flatten(), rtol=1.e-3)

    # Check that we get the same thing when using x,y,z rather than ra,dec,r
    cat = treecorr.Catalog(x=x, y=y, z=z)
    rand = treecorr.Catalog(x=rx, y=ry, z=rz)
    ddd.process(cat)
    rrr.process(rand)
    zeta, varzeta = ddd.calculateZeta(rrr)
    np.testing.assert_allclose(zeta, true_zeta, rtol=0.1*tol_factor)
github rmjarvis / TreeCorr / tests / test_rperp.py View on Github external
print('Results with bin_slop = 0.1')
    print('gg.npairs = ',gg.npairs)
    print('gg.xim = ',gg.xim)
    print('theory_gammat = ',theory_gQ)
    print('ratio = ',gg.xim / theory_gQ)
    print('diff = ',gg.xim - theory_gQ)
    print('max diff = ',max(abs(gg.xim - theory_gQ)))
    assert max(abs(gg.xim - theory_gQ)) < 1.e-4
    print('gg.xim_im = ',gg.xim_im)
    assert max(abs(gg.xim_im)) < 1.e-4

    # Check that we get the same result using the corr2 function:
    lens_cat.write(os.path.join('data','gg_oldrperp_local_lens.dat'))
    source_cat.write(os.path.join('data','gg_oldrperp_local_source.dat'))
    config = treecorr.config.read_config('configs/gg_oldrperp_local.yaml')
    logger = treecorr.config.setup_logger(0)
    treecorr.corr2(config, logger)
    corr2_output = np.genfromtxt(os.path.join('output','gg_oldrperp_local.out'),names=True,
                                    skip_header=1)
    print('gg.xim = ',gg.xim)
    print('from corr2 output = ',corr2_output['xim'])
    print('ratio = ',corr2_output['xim']/gg.xim)
    print('diff = ',corr2_output['xim']-gg.xim)
    np.testing.assert_allclose(corr2_output['xim'], gg.xim, rtol=1.e-3)
    np.testing.assert_allclose(corr2_output['xim_im'], gg.xim_im, rtol=1.e-3)
    np.testing.assert_allclose(corr2_output['xip'], gg.xip, rtol=1.e-3)
    np.testing.assert_allclose(corr2_output['xip_im'], gg.xip_im, rtol=1.e-3)
github rmjarvis / TreeCorr / tests / test_config.py View on Github external
'file_name': ['data/nn_list_data0.dat', 'data/nn_list_data1.dat', 'data/nn_list_data2.dat'],
        'rand_file_name': ['data/nn_list_rand0.dat', 'data/nn_list_rand1.dat', 'data/nn_list_rand2.dat'],
        'file_list2': 'data/nn_list_data_files.txt',
        'rand_file_list2': 'data/nn_list_rand_files.txt',
        'x_col': '1',
        'y_col': '2',
        'verbose': '1',
        'min_sep': '1.',
        'max_sep': '25.',
        'bin_size': '0.10',
        'nn_file_name': 'nn_list6.out',
        'nn_statistic': 'simple',
    }

    with assert_raises(ValueError):
        treecorr.config.read_config('configs/nn_list6.config', file_type='simple')
    with assert_raises(ValueError):
        treecorr.config.read_config('configs/nn_list6.config')
github rmjarvis / TreeCorr / tests / test_config.py View on Github external
config2 = treecorr.config.read_config('configs/nn_list2.json')
    assert config2 == {
        'file_list': 'data/nn_list_data_files.txt',
        'rand_file_name': 'data/nn_list_randx.dat',
        'x_col': 1,
        'y_col': 2,
        'verbose': 1,
        'min_sep': 1.,
        'max_sep': 25.,
        'bin_size': 0.10,
        'nn_file_name': 'output/nn_list2.out',
        'nn_statistic': 'simple',
    }

    config3 = treecorr.config.read_config('configs/nn_list3.params')
    assert config3 == {
        'file_name': 'data/nn_list_datax.dat',
        'rand_file_name': ['data/nn_list_rand0.dat', 'data/nn_list_rand1.dat',
                           'data/nn_list_rand2.dat'],
        'x_col': '1',
        'y_col': '2',
        'verbose': '1',
        'min_sep': '1.',
        'max_sep': '25.',
        'bin_size': '0.10',
        'nn_file_name': 'output/nn_list3.out',
        'nn_statistic': 'simple',
    }

    config4 = treecorr.config.read_config('configs/nn_list4.config', file_type='yaml')
    assert config4 == {
github rmjarvis / TreeCorr / tests / test_nnn.py View on Github external
rand_file_namex = os.path.join('data','nnn_list_randx.dat')
    rand_catx.write(rand_file_namex)

    config = treecorr.config.read_config('configs/nnn_list1.yaml')
    config['verbose'] = 0
    config['bin_slop'] = 0.1
    treecorr.corr3(config)
    corr3_output = np.genfromtxt(os.path.join('output','nnn_list1.out'), names=True, skip_header=1)
    print('zeta = ',zeta)
    print('from corr3 output = ',corr3_output['zeta'])
    print('ratio = ',corr3_output['zeta']/zeta.flatten())
    print('diff = ',corr3_output['zeta']-zeta.flatten())
    np.testing.assert_allclose(corr3_output['zeta'], zeta.flatten(), rtol=1.e-3)

    config = treecorr.config.read_config('configs/nnn_list2.json')
    config['verbose'] = 0
    config['bin_slop'] = 0.1
    treecorr.corr3(config)
    corr3_output = np.genfromtxt(os.path.join('output','nnn_list2.out'), names=True, skip_header=1)
    print('zeta = ',zeta)
    print('from corr3 output = ',corr3_output['zeta'])
    print('ratio = ',corr3_output['zeta']/zeta.flatten())
    print('diff = ',corr3_output['zeta']-zeta.flatten())
    np.testing.assert_allclose(corr3_output['zeta'], zeta.flatten(), rtol=0.05)

    config = treecorr.config.read_config('configs/nnn_list3.params')
    config['verbose'] = 0
    config['bin_slop'] = 0.1
    treecorr.corr3(config)
    corr3_output = np.genfromtxt(os.path.join('output','nnn_list3.out'), names=True, skip_header=1)
    print('zeta = ',zeta)
github rmjarvis / TreeCorr / tests / test_kk.py View on Github external
print('true_weight = ',true_weight)
    print('diff = ',kk.weight - true_weight)
    np.testing.assert_allclose(kk.weight, true_weight, rtol=1.e-5, atol=1.e-8)

    print('true_xi = ',true_xi)
    print('kk.xi = ',kk.xi)
    np.testing.assert_allclose(kk.xi, true_xi, rtol=1.e-4, atol=1.e-8)

    try:
        import fitsio
    except ImportError:
        print('Skipping FITS tests, since fitsio is not installed')
        return

    # Check that running via the corr2 script works correctly.
    config = treecorr.config.read_config('configs/kk_direct_spherical.yaml')
    cat1.write(config['file_name'])
    cat2.write(config['file_name2'])
    treecorr.corr2(config)
    data = fitsio.read(config['kk_file_name'])
    np.testing.assert_allclose(data['r_nom'], kk.rnom)
    np.testing.assert_allclose(data['npairs'], kk.npairs)
    np.testing.assert_allclose(data['weight'], kk.weight)
    np.testing.assert_allclose(data['xi'], kk.xi, rtol=1.e-3)

    # Repeat with binslop = 0
    # And don't do any top-level recursion so we actually test not going to the leaves.
    kk = treecorr.KKCorrelation(min_sep=min_sep, max_sep=max_sep, nbins=nbins,
                                sep_units='deg', bin_slop=0, max_top=0)
    kk.process(cat1, cat2)
    np.testing.assert_array_equal(kk.npairs, true_npairs)
    np.testing.assert_allclose(kk.weight, true_weight, rtol=1.e-5, atol=1.e-8)
github rmjarvis / TreeCorr / tests / test_nnn.py View on Github external
true_zeta = (1./(12.*np.pi**2)) * (L/s)**4 * np.exp(-(d1**2+d2**2+d3**2)/(6.*s**2)) - 1.

    zeta, varzeta = ddd.calculateZeta(rrr)
    print('zeta = ',zeta)
    print('true_zeta = ',true_zeta)
    print('ratio = ',zeta / true_zeta)
    print('diff = ',zeta - true_zeta)
    print('max rel diff = ',np.max(np.abs((zeta - true_zeta)/true_zeta)))
    np.testing.assert_allclose(zeta, true_zeta, rtol=0.1*tol_factor)
    np.testing.assert_allclose(np.log(np.abs(zeta)), np.log(np.abs(true_zeta)),
                                  atol=0.1*tol_factor)

    # Check that we get the same result using the corr3 function
    cat.write(os.path.join('data','nnn_data.dat'))
    rand.write(os.path.join('data','nnn_rand.dat'))
    config = treecorr.config.read_config('configs/nnn.yaml')
    config['verbose'] = 0
    treecorr.corr3(config)
    corr3_output = np.genfromtxt(os.path.join('output','nnn.out'), names=True, skip_header=1)
    print('zeta = ',zeta)
    print('from corr3 output = ',corr3_output['zeta'])
    print('ratio = ',corr3_output['zeta']/zeta.flatten())
    print('diff = ',corr3_output['zeta']-zeta.flatten())
    np.testing.assert_allclose(corr3_output['zeta'], zeta.flatten(), rtol=1.e-3)

    try:
        import fitsio
    except ImportError:
        print('Skipping FITS tests, since fitsio is not installed')
        return

    # Check the fits write option
github rmjarvis / TreeCorr / tests / test_nn.py View on Github external
fid.write('%s\n'%file_name)

    file_namex = os.path.join('data','nn_list_datax.dat')
    with open(file_namex, 'w') as fid:
        for k in range(ncats):
            for i in range(nobj):
                fid.write(('%.8f %.8f\n')%(x[i,k],y[i,k]))

    rand_file_namex = os.path.join('data','nn_list_randx.dat')
    with open(rand_file_namex, 'w') as fid:
        for k in range(ncats):
            for i in range(nobj):
                fid.write(('%.8f %.8f\n')%(rx[i,k],ry[i,k]))

    # First do this via the corr2 function.
    config = treecorr.config.read_config('configs/nn_list1.yaml')
    logger = treecorr.config.setup_logger(0)
    treecorr.corr2(config, logger)
    corr2_output = np.genfromtxt(os.path.join('output','nn_list1.out'),names=True,skip_header=1)
    print('xi = ',xi)
    print('from corr2 output = ',corr2_output['xi'])
    print('ratio = ',corr2_output['xi']/xi)
    print('diff = ',corr2_output['xi']-xi)
    np.testing.assert_allclose(corr2_output['xi'], xi, rtol=1.e-3)

    # Now calling out to the external corr2 executable to test it with extra command-line params
    import subprocess
    corr2_exe = get_script_name('corr2')
    p = subprocess.Popen( [corr2_exe,"configs/nn_list1.yaml","verbose=0"] )
    p.communicate()
    corr2_output = np.genfromtxt(os.path.join('output','nn_list1.out'),names=True,skip_header=1)
    print('xi = ',xi)
github rmjarvis / TreeCorr / tests / test_ng.py View on Github external
np.testing.assert_allclose(ng.weight, true_weight, rtol=1.e-5, atol=1.e-8)

    print('true_xi = ',true_xi)
    print('ng.xi = ',ng.xi)
    print('ng.xi_im = ',ng.xi_im)
    np.testing.assert_allclose(ng.xi, true_xi.real, rtol=1.e-4, atol=1.e-8)
    np.testing.assert_allclose(ng.xi_im, true_xi.imag, rtol=1.e-4, atol=1.e-8)

    try:
        import fitsio
    except ImportError:
        print('Skipping FITS tests, since fitsio is not installed')
        return

    # Check that running via the corr2 script works correctly.
    config = treecorr.config.read_config('configs/ng_direct.yaml')
    cat1.write(config['file_name'])
    cat2.write(config['file_name2'])
    treecorr.corr2(config)
    data = fitsio.read(config['ng_file_name'])
    np.testing.assert_allclose(data['r_nom'], ng.rnom)
    np.testing.assert_allclose(data['npairs'], ng.npairs)
    np.testing.assert_allclose(data['weight'], ng.weight)
    np.testing.assert_allclose(data['gamT'], ng.xi, rtol=1.e-3)
    np.testing.assert_allclose(data['gamX'], ng.xi_im, rtol=1.e-3)

    # Invalid with only one file_name
    del config['file_name2']
    with assert_raises(TypeError):
        treecorr.corr2(config)
    config['file_name2'] = 'data/ng_direct_cat2.fits'
    # Invalid to request compoensated if no rand_file