Exemplo n.º 1
0
def match(source_halos, target):
    timestep = consistent_collection.ConsistentCollection(
        source_halos).timestep
    if target is None:
        results = [None] * len(source_halos)
    else:
        from ... import relation_finding
        if not isinstance(target, core.Base):
            target = tangos.get_item(target,
                                     core.Session.object_session(timestep))
        results = relation_finding.MultiSourceMultiHopStrategy(
            source_halos, target).all()
    # if following assert fails, it might be duplicate links in the database which the
    # current MultiSourceMultiHop implementation cannot de-duplicate:
    assert len(results) == len(source_halos)
    return np.array(results, dtype=object)
Exemplo n.º 2
0
def setup():
    global sim1, sim2, collection, h1, h2
    testing.init_blank_db_for_testing()

    session = db.core.get_default_session()

    sim1 = tangos.core.simulation.Simulation("sim1")
    sim2 = tangos.core.simulation.Simulation("sim2")
    ts1 = tangos.core.timestep.TimeStep(sim1, "ts")
    h1 = tangos.core.halo.Halo(ts1, 1, 1, 1, 1000, 0, 0, 0)
    ts2 = tangos.core.timestep.TimeStep(sim2, "ts")
    h2 = tangos.core.halo.Halo(ts2, 1, 1, 1, 1000, 0, 0, 0)

    session.add_all([sim1, sim2, ts1, ts2, h1, h2])

    sim1['consistent_property'] = 1.0
    sim2['consistent_property'] = 1.0

    sim1['inconsistent_property'] = 0.5
    sim2['inconsistent_property'] = 1.0
    collection = cc.ConsistentCollection([sim1, sim2])
Exemplo n.º 3
0
def test_empty_collection():
    with assert_raises(ValueError):
        col = cc.ConsistentCollection([])
Exemplo n.º 4
0
def test_set_pruning():
    col2 = cc.ConsistentCollection([sim1, sim1, sim2])
    assert len(col2._objects) == 2
Exemplo n.º 5
0
def earliest(source_halos):
    timestep = consistent_collection.ConsistentCollection(
        source_halos).timestep.get_final(-1)
    return match(source_halos, timestep)
Exemplo n.º 6
0
def later(source_halos, num_steps):
    timestep = consistent_collection.ConsistentCollection(
        source_halos).timestep.get_next(num_steps)
    return match(source_halos, timestep)