Exemple #1
0
def test_repopulate(comm):

    # initialize the halos
    halos = DemoHaloCatalog('bolshoi', 'rockstar', 0.5, comm=comm)

    # populate the mock first
    hod = halos.populate(Zheng07Model, seed=42)
    size = hod.csize

    # repopulate (with same seed --> same catalog)
    hod.repopulate(seed=42)
    assert hod.csize == size

    # repopulate with random seed
    # make sure root sets a random seed and it's saved
    hod.repopulate(seed=None)
    assert hod.attrs['seed'] is not None

    # new params, same seed
    hod.repopulate(seed=42, alpha=1.0)
    assert hod.csize != size

    # bad param name
    with pytest.raises(ValueError):
        hod.repopulate(seed=42, bad_param_name=1.0)
Exemple #2
0
def test_no_seed(comm):

    halos = DemoHaloCatalog('bolshoi', 'rockstar', 0.5, comm=comm)
    hod = halos.populate(Zheng07Model)

    # seed is set randomly
    assert hod.attrs['seed'] is not None
Exemple #3
0
def test_bad_model(comm):

    CurrentMPIComm.set(comm)

    halos = DemoHaloCatalog('bolshoi', 'rockstar', 0.5)
    with pytest.raises(TypeError):
        hod = halos.populate('Zheng07Model')
Exemple #4
0
def test_no_galaxies(comm):

    halos = DemoHaloCatalog('bolshoi', 'rockstar', 0.5, comm=comm)

    # no galaxies populated into halos
    # NOTE: logMmin is unrealistically large here
    with pytest.raises(ValueError):
        hod = halos.populate(Zheng07Model, seed=42, logMmin=17)
Exemple #5
0
def test_failed_populate(comm):

    # the demo halos
    halos = DemoHaloCatalog('bolshoi', 'rockstar', 0.5, comm=comm)

    # initialize model with bad MASS column
    model = Zheng07Model.to_halotools(halos.cosmo, halos.attrs['redshift'], '200c')

    with pytest.raises(Exception):
        hod = halos.populate(model)
Exemple #6
0
def test_download(comm):

    from halotools.sim_manager import UserSuppliedHaloCatalog

    # download and load the cached catalog
    cat = DemoHaloCatalog('bolshoi', 'rockstar', 0.5, comm=comm)
    assert all(col in cat for col in ['Position', 'Velocity'])

    # convert to halotools catalog
    halotools_cat = cat.to_halotools()
    assert isinstance(halotools_cat, UserSuppliedHaloCatalog)

    # bad simulation name
    with pytest.raises(Exception):
        cat = DemoHaloCatalog('BAD', 'rockstar', 0.5)
Exemple #7
0
def test_download_failure(comm):
    CurrentMPIComm.set(comm)

    # initialize with bad redshift
    BAD_REDSHIFT = 100.0
    with pytest.raises(Exception):
        cat = DemoHaloCatalog('bolshoi', 'rockstar', BAD_REDSHIFT)
Exemple #8
0
def test_bad_model(comm):

    halos = DemoHaloCatalog('bolshoi', 'rockstar', 0.5, comm=comm)
    with pytest.raises(TypeError):
        hod = halos.populate('Zheng07Model')