Ejemplo n.º 1
0
def test_consistent_groups():
    """ Shuffling gives consistent groups """
    # Note we dont actually need to check for renumbering between hfof and
    # itself because even if you shuffle the points they end up in the same
    # cells, which are treated in order, so the group numbers (at each
    # position) are guaranteed to be the same. Only if you check against
    # another FOF do you need to check the numbering.

    pos = example_data.get_pos()
    N = pos.shape[0]
    rs = RandomState(seed=123)
    idx = np.arange(N)
    rs.shuffle(idx)
    rcut = 0.01

    # Non=periodic
    doms1 = fof(pos, rcut)
    doms2 = fof(pos[idx], rcut)

    assert (np.all(np.equal(doms1[idx], doms2)))
    # Periodic
    doms1 = fof(pos, rcut, boxsize=0.8)
    doms2 = fof(pos[idx], rcut, boxsize=0.8)

    assert (np.all(np.equal(doms1[idx], doms2)))
Ejemplo n.º 2
0
def test_cosmo_isol():
    """ Cosmological (non-periodic) """
    pos = example_data.get_pos()

    for rcut, n in ndom_isol.items():
        domains = fof(pos, rcut)
        n_doms = len(np.unique(domains))
        assert (n == n_doms)
        print(rcut, n_doms, n)
Ejemplo n.º 3
0
def test_cosmo_periodic():
    """ Cosmological (periodic) """
    pos = example_data.get_pos()

    for rcut, n in ndom_prd.items():
        domains = fof(pos, rcut, boxsize=1.0)
        n_doms = len(np.unique(domains))
        assert (n == n_doms)
        print(rcut, n_doms, n)
Ejemplo n.º 4
0
def test_shift_scale():
    """ Cube scaled and shifted """
    shift, scale = (8.82334, 4.234, -15.234), 4.8271

    pos = example_data.get_pos() * scale + shift

    # scaled the box => scale the linking length

    # Isolated
    for rcut, n in ndom_isol.items():
        domains = fof(pos, rcut * scale)
        n_doms = len(np.unique(domains))
        assert (n == n_doms)
        print(rcut, n_doms, n)

    #Periodic (scale boxsize too)
    for rcut, n in ndom_prd.items():
        domains = fof(pos, rcut * scale, boxsize=scale)
        n_doms = len(np.unique(domains))
        assert (n == n_doms)
        print(rcut, n_doms, n)
Ejemplo n.º 5
0
def test_fof():
    """ Test friends-of-friends """

    pos = example_data.get_pos()  # (32768,3) positions in [0,1]
    pos[:, 2] *= 0.0  # project (squash) z-dimension
    r_cut = 0.004  # linking length

    fof_labels = fof(pos, r_cut, boxsize=1.0)  # integer labels from 0...
    print 'Number of labels', len(np.unique(fof_labels)), 'minimum', min(
        fof_labels), 'maximum', max(fof_labels)

    # color by number of particles in group
    clrs = np.bincount(fof_labels)[fof_labels]
    import pylab as pl
    pl.scatter(pos[:, 0],
               pos[:, 1],
               c=np.power(clrs, 0.3),
               s=1.0,
               edgecolors='none')
    #    pl.xlim(0,1)
    #    pl.ylim(0,1)
    #    pl.axis('off')
    #    pl.savefig('figs/fof.png', dpi=50, bbox_inches='tight')
    pl.show()