Exemple #1
0
def test_fits():
    get_aardvark()

    file_name = os.path.join('data','Aardvark.fit')
    config = treecorr.read_config('Aardvark.params')

    # Just test a few random particular values
    cat1 = treecorr.Catalog(file_name, config)
    numpy.testing.assert_equal(len(cat1.ra), 390935)
    numpy.testing.assert_equal(cat1.nobj, 390935)
    numpy.testing.assert_almost_equal(cat1.ra[0], 56.4195 * (pi/180.))
    numpy.testing.assert_almost_equal(cat1.ra[390934], 78.4782 * (pi/180.))
    numpy.testing.assert_almost_equal(cat1.dec[290333], 83.1579 * (pi/180.))
    numpy.testing.assert_almost_equal(cat1.g1[46392], 0.0005066675)
    numpy.testing.assert_almost_equal(cat1.g2[46392], -0.0001006742)
    numpy.testing.assert_almost_equal(cat1.k[46392], -0.0008628797)

    # The catalog doesn't have x, y, or w, but test that functionality as well.
    del config['ra_col']
    del config['dec_col']
    config['x_col'] = 'RA'
    config['y_col'] = 'DEC'
    config['w_col'] = 'MU'
    config['flag_col'] = 'INDEX'
    config['ignore_flag'] = 64
    cat2 = treecorr.Catalog(file_name, config)
    numpy.testing.assert_almost_equal(cat2.x[390934], 78.4782, decimal=4)
    numpy.testing.assert_almost_equal(cat2.y[290333], 83.1579, decimal=4)
    numpy.testing.assert_almost_equal(cat2.w[46392], 0.)        # index = 1200379
    numpy.testing.assert_almost_equal(cat2.w[46393], 0.9995946) # index = 1200386

    # Test using a limited set of rows
    config['first_row'] = 101
    config['last_row'] = 50000
    cat3 = treecorr.Catalog(file_name, config)
    numpy.testing.assert_equal(len(cat3.x), 49900)
    numpy.testing.assert_equal(cat3.nobj, sum(cat3.w != 0))
    numpy.testing.assert_almost_equal(cat3.g1[46292], 0.0005066675)
    numpy.testing.assert_almost_equal(cat3.g2[46292], -0.0001006742)
    numpy.testing.assert_almost_equal(cat3.k[46292], -0.0008628797)
Exemple #2
0
def test_aardvark():

    # Eric Suchyta did a brute force calculation of the Aardvark catalog, so it is useful to
    # compare the output from my code with that.

    get_aardvark()
    file_name = os.path.join('data','Aardvark.fit')
    config = treecorr.read_config('Aardvark.params')
    cat1 = treecorr.Catalog(file_name, config)
    gg = treecorr.GGCorrelation(config)
    gg.process(cat1)

    direct_file_name = os.path.join('data','Aardvark.direct')
    direct_data = numpy.genfromtxt(direct_file_name)
    direct_xip = direct_data[:,3]
    direct_xim = direct_data[:,4]

    #print 'gg.xip = ',gg.xip
    #print 'direct.xip = ',direct_xip

    xip_err = gg.xip - direct_xip
    print 'xip_err = ',xip_err
    print 'max = ',max(abs(xip_err))
    assert max(abs(xip_err)) < 2.e-7
    print 'xip_im = ',gg.xip_im
    print 'max = ',max(abs(gg.xip_im))
    assert max(abs(gg.xip_im)) < 3.e-7

    xim_err = gg.xim - direct_xim
    print 'xim_err = ',xim_err
    print 'max = ',max(abs(xim_err))
    assert max(abs(xim_err)) < 1.e-7
    print 'xim_im = ',gg.xim_im
    print 'max = ',max(abs(gg.xim_im))
    assert max(abs(gg.xim_im)) < 1.e-7

    # However, after some back and forth about the calculation, we concluded that Eric hadn't
    # done the spherical trig correctly to get the shears relative to the great circle joining
    # the two positions.  So let's compare with my own brute force calculation (i.e. using
    # bin_slop = 0):
    # This also has the advantage that the radial bins are done the same way -- uniformly 
    # spaced in log of the chord distance, rather than the great circle distance.

    bs0_file_name = os.path.join('data','Aardvark.bs0')
    bs0_data = numpy.genfromtxt(bs0_file_name)
    bs0_xip = bs0_data[:,2]
    bs0_xim = bs0_data[:,3]

    #print 'gg.xip = ',gg.xip
    #print 'bs0.xip = ',bs0_xip

    xip_err = gg.xip - bs0_xip
    print 'xip_err = ',xip_err
    print 'max = ',max(abs(xip_err))
    assert max(abs(xip_err)) < 1.e-7

    xim_err = gg.xim - bs0_xim
    print 'xim_err = ',xim_err
    print 'max = ',max(abs(xim_err))
    assert max(abs(xim_err)) < 5.e-8

    # Check that we get the same result using the corr2 executable:
    # Note: This is the only test of the corr2 executable that we do with nosetests.
    # The other similar tests are blocked out with: if __name__ == '__main__':
    import subprocess
    p = subprocess.Popen( ["corr2","Aardvark.params"] )
    p.communicate()
    corr2_output = numpy.genfromtxt(os.path.join('output','Aardvark.out'), names=True)
    print 'gg.xip = ',gg.xip
    print 'from corr2 output = ',corr2_output['xip']
    print 'ratio = ',corr2_output['xip']/gg.xip
    print 'diff = ',corr2_output['xip']-gg.xip
    numpy.testing.assert_almost_equal(corr2_output['xip']/gg.xip, 1., decimal=3)

    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
    numpy.testing.assert_almost_equal(corr2_output['xim']/gg.xim, 1., decimal=3)

    print 'xip_im from corr2 output = ',corr2_output['xip_im']
    print 'max err = ',max(abs(corr2_output['xip_im']))
    assert max(abs(corr2_output['xip_im'])) < 3.e-7
    print 'xim_im from corr2 output = ',corr2_output['xim_im']
    print 'max err = ',max(abs(corr2_output['xim_im']))
    assert max(abs(corr2_output['xim_im'])) < 1.e-7

    # As bin_slop decreases, the agreement should get even better.
    # This test is slow, so only do it if running test_gg.py directly.
    if __name__ == '__main__':
        config['bin_slop'] = 0.2
        gg = treecorr.GGCorrelation(config)
        gg.process(cat1)

        #print 'gg.xip = ',gg.xip
        #print 'bs0.xip = ',bs0_xip

        xip_err = gg.xip - bs0_xip
        print 'xip_err = ',xip_err
        print 'max = ',max(abs(xip_err))
        assert max(abs(xip_err)) < 1.e-8

        xim_err = gg.xim - bs0_xim
        print 'xim_err = ',xim_err
        print 'max = ',max(abs(xim_err))
        assert max(abs(xim_err)) < 1.e-8