Exemplo n.º 1
0
def setup():
    global ts1, ts2, sim
    testing.init_blank_db_for_testing()
    db.config.base = os.path.dirname(os.path.abspath(__file__)) + "/"

    session = db.core.get_default_session()

    sim = tangos.core.simulation.Simulation("test_stat_files")
    session.add(sim)

    ts1 = tangos.core.timestep.TimeStep(sim,
                                        "pioneer50h128.1536gst1.bwK1.000832")
    ts1.time_gyr = 6  # unimportant
    ts1.redshift = 2.323  # matters for AHF filename

    ts2 = tangos.core.timestep.TimeStep(
        sim, "h242.cosmo50PLK.1536g1bwK1C52.004096")
    ts2.time_gyr = 10
    ts2.redshift = 0

    session.add_all([ts1, ts2])

    session.commit()

    parallel_tasks.use('null')
Exemplo n.º 2
0
def setup():
    testing.init_blank_db_for_testing()

    creator = tangos.testing.simulation_generator.TestSimulationGenerator()

    halo_offset = 0
    for ts in range(1, 4):
        creator.add_timestep()
        creator.add_objects_to_timestep(4)
        creator.link_last_halos()

    tangos.get_default_session().commit()
    tangos.get_item("sim/ts1/halo_1")['test_image'] = np.zeros((500, 500, 3))
    for ts in tangos.get_simulation(1).timesteps:
        for h in ts.halos:
            h['test_value'] = 1.0

    tangos.get_default_session().commit()

    creator = tangos.testing.simulation_generator.TestSimulationGenerator(
        "simname/has/slashes")
    creator.add_timestep()
    creator.add_objects_to_timestep(1)
    creator.add_timestep()
    creator.add_objects_to_timestep(1)
    creator.link_last_halos()
    tangos.get_simulation(2).timesteps[0].halos[0]['test_value'] = 2.0
    tangos.get_default_session().commit()

    global app
    app = TestApp(tangos.web.main({}))
Exemplo n.º 3
0
def setup():
    testing.init_blank_db_for_testing()

    generator = tangos.testing.simulation_generator.TestSimulationGenerator()
    generator.add_timestep() # ts1
    generator.add_objects_to_timestep(7)

    generator.add_timestep() # ts2
    generator.add_objects_to_timestep(7)
    generator.link_last_halos()

    generator.add_timestep() # ts3
    generator.add_objects_to_timestep(6)
    generator.link_last_halos_using_mapping({1:1, 2:1, 3:2, 4:3, 5:4, 6:5, 7:6}) # ts2->ts3: merger of halos 1 & 2

    generator.add_timestep() # ts4
    generator.add_objects_to_timestep(6)
    generator.link_last_halos()

    generator.add_timestep() # ts5
    generator.add_objects_to_timestep(5)
    generator.link_last_halos_using_mapping({1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 1})  # ts4->ts5: merger of halos 1 & 6

    generator.add_timestep() # ts6
    generator.add_objects_to_timestep(5)
    generator.link_last_halos()

    # setup the default options, so that these can change in the config without changing the tests
    tree.mergertree_min_fractional_weight = 0.02
    tree.mergertree_min_fractional_NDM = 0.0
    tree.mergertree_max_nhalos = 30
    tree.mergertree_timeout = 15.0
    tree.mergertree_max_hops = 500
Exemplo n.º 4
0
def setup():
    testing.init_blank_db_for_testing()

    generator = tangos.testing.simulation_generator.TestSimulationGenerator()

    ts1 = generator.add_timestep()
    ts1_h1, ts2_h2 = generator.add_objects_to_timestep(2)

    ts1_h1['dummy_property_1'] = np.arange(0, 100.0)

    angmom = np.empty((100, 3))
    angmom[:, :] = np.arange(0, 100.0).reshape((100, 1))
    ts1_h1['dummy_property_2'] = angmom

    ts1_h1['dummy_property_3'] = -2.5

    ts1_h1_bh1 = tangos.core.halo.BH(ts1, 1)
    ts1_h1_bh1["BH_mass"] = 1000.0

    ts1_h1_bh2 = tangos.core.halo.BH(ts1, 2)
    ts1_h1_bh2["BH_mass"] = 900.0
    ts1_h1["BH"] = ts1_h1_bh1, ts1_h1_bh2

    generator.add_timestep()
    generator.add_objects_to_timestep(1)
    generator.link_last_halos()

    generator.add_timestep()  # intentionally empty final timestep
def setup():
    testing.init_blank_db_for_testing()

    generator = tangos.testing.simulation_generator.TestSimulationGenerator()
    generator.add_timestep()  # ts1
    generator.add_objects_to_timestep(2, NDM=[1000, 600])

    generator.add_timestep()  # ts2
    generator.add_objects_to_timestep(2)
    generator.link_last_halos(adjust_masses=True)

    generator.add_timestep()  # ts3, in which halo 1 and 2 collide
    generator.add_objects_to_timestep(2)
    generator.link_last_halos_using_mapping(
        {
            1: 2,
            2: 1
        }, adjust_masses=True
    )  # halo 1 becomes 2, 2 becomes 1 due to mass ordering
    generator.add_mass_transfer(
        1, 1, 0.3, adjust_masses=True
    )  # halo 1 in previous step loses 30% of its mass to halo 1 in this step... but survives

    generator.add_timestep()  # ts4
    generator.add_objects_to_timestep(2)
    generator.link_last_halos(adjust_masses=True)
    generator.add_mass_transfer(
        2, 1, 0.05, adjust_masses=True)  # continued minor stripping of halo 2

    generator.add_timestep(
    )  #ts5, in which halo 1 and 2 finally merge completely
    generator.add_objects_to_timestep(1)
    generator.link_last_halos_using_mapping({1: 1, 2: 1}, adjust_masses=True)
Exemplo n.º 6
0
def test_NDM_cut():
    testing.init_blank_db_for_testing()
    manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandlerReverseHaloNDM("dummy_sim_2"))
    manager.min_halo_particles = 2005
    manager.scan_simulation_and_add_all_descendants()
    ndm, = db.get_timestep("dummy_sim_2/step.1").calculate_all("NDM()")
    assert ndm.min()==2005
def setup_module():
    testing.init_blank_db_for_testing()

    creator = tangos.testing.simulation_generator.SimulationGeneratorForTests()

    halo_offset = 0
    for ts in range(1,4):
        num_halos = 4 if ts<3 else 3
        creator.add_timestep()
        creator.add_objects_to_timestep(num_halos)
        creator.add_properties_to_halos(Mvir=lambda i: i+halo_offset)
        creator.add_properties_to_halos(Rvir=lambda i: (i+halo_offset)*0.1)
        halo_offset+=num_halos

        creator.add_bhs_to_timestep(4)
        creator.add_properties_to_bhs(hole_mass = lambda i: float(i*100))
        creator.add_properties_to_bhs(hole_spin = lambda i: 1000-float(i)*100)
        creator.add_properties_to_bhs(test_array = lambda i: np.array([1.0,2.0,3.0]))
        creator.assign_bhs_to_halos({1:1, 2:2, 3:3, 4:3})


        if ts>1:
            creator.link_last_halos()
            creator.link_last_bhs_using_mapping({1:1})

    # special timestep 5->6 where there is an exact equal weight link
    creator.add_timestep()
    creator.add_objects_to_timestep(2, NDM=[5,5])
    creator.add_timestep()
    creator.add_objects_to_timestep(1, NDM=[10])
    creator.link_last_halos_using_mapping({1:1, 2:1})
Exemplo n.º 8
0
def setup_module():
    testing.init_blank_db_for_testing()

    generator = tangos.testing.simulation_generator.SimulationGeneratorForTests(
    )
    # A second simulation to test linking across
    generator_2 = tangos.testing.simulation_generator.SimulationGeneratorForTests(
        "sim2")

    generator.add_timestep()
    generator_2.add_timestep()
    generator.add_objects_to_timestep(7)
    generator.add_bhs_to_timestep(2)
    generator.assign_bhs_to_halos({1: 1, 2: 2})

    generator.add_timestep()
    generator_2.add_timestep()
    generator.add_objects_to_timestep(5)
    generator.add_bhs_to_timestep(2)
    generator.assign_bhs_to_halos({1: 1, 2: 2})
    generator_2.add_objects_to_timestep(2)

    generator_2.link_last_halos_across_using_mapping(generator, {1: 2, 2: 1})

    # ts1_h1 becomes ts2_h2 but loses 10% of its mass to ts2_h1
    # ts1_h2 becomes ts2_h1
    # ts1_h3 becomes ts2_h3
    # ts1_h4 becomes ts2_h4 but loses 1% of its mass to ts2_h3
    # ts1_h6 and ts1_h7 merge into ts2_h5
    # ts1_h5 is ORPHANED, i.e has no counterpart in ts2
    #
    # We do not adjust the masses here because, despite the halos crossing
    # over in ordering, the tests were constructed with an earlier version
    # of the code which did not ensure this consistency
    generator.link_last_halos_using_mapping(
        {
            1: 2,
            2: 1,
            3: 3,
            4: 4,
            6: 5,
            7: 5
        }, adjust_masses=False)

    generator.add_mass_transfer(1, 1, 0.1)
    generator.add_mass_transfer(4, 3, 0.01)

    generator.add_timestep()
    generator.add_objects_to_timestep(5)
    generator.add_bhs_to_timestep(2)
    generator.assign_bhs_to_halos({1: 1, 2: 2})

    # ts2_h1 and ts2_h2 merge to ts3_h1
    # ts2_h3 becomes ts3_h2
    # ts2_h4 becomes ts3_h3 but loses 5% of its mass to ts3_h2
    # ts2_h5 becomes ts3_h4
    # ts3_h5 has no counterpart
    generator.link_last_halos_using_mapping({1: 1, 2: 1, 3: 2, 4: 3, 5: 4})
    generator.add_mass_transfer(4, 2, 0.05)
Exemplo n.º 9
0
def test_import():
    existing_session = tangos.get_default_session()
    testing.init_blank_db_for_testing(testing_db_name='imported_db_test')
    new_session = tangos.get_default_session()
    manager._db_import_export(new_session, existing_session)
    differ = diff.TangosDbDiff(existing_session, new_session)
    differ.compare()
    assert not differ.failed, "Copied database differs; see log for details"
Exemplo n.º 10
0
def setup_func():
    parallel_tasks.use('null')

    testing.init_blank_db_for_testing()
    db.config.base = os.path.join(os.path.dirname(__file__), "test_simulations")
    manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandler("dummy_sim_1"))
    with log.LogCapturer():
        manager.scan_simulation_and_add_all_descendants()
Exemplo n.º 11
0
def setup_module():
    global output_manager
    testing.init_blank_db_for_testing()
    db.config.base = os.path.join(os.path.dirname(__file__),
                                  "test_simulations")
    output_manager = yt_outputs.YtChangaAHFInputHandler("test_tipsy_yt")
    add.SimulationAdderUpdater(
        output_manager).scan_simulation_and_add_all_descendants()
Exemplo n.º 12
0
def init_blank_simulation():
    testing.init_blank_db_for_testing(timeout=0.0)
    db.config.base = os.path.join(os.path.dirname(__file__),
                                  "test_simulations")
    manager = add_simulation.SimulationAdderUpdater(
        output_testing.TestInputHandler("dummy_sim_1"))
    with log.LogCapturer():
        manager.scan_simulation_and_add_all_descendants()
Exemplo n.º 13
0
def setup():
    pt.use("multiprocessing")
    testing.init_blank_db_for_testing(timeout=5.0, verbose=False)

    generator = tangos.testing.simulation_generator.TestSimulationGenerator()
    generator.add_timestep()
    generator.add_objects_to_timestep(9)

    tangos.core.get_default_session().commit()
Exemplo n.º 14
0
def setup():

    testing.init_blank_db_for_testing()
    tangos.config.base = os.path.join(os.path.dirname(__file__),
                                      "test_simulations")

    manager = tools.add_simulation.SimulationAdderUpdater(
        input_handlers.pynbody.ChangaInputHandler("test_ahf_merger_tree"))
    with log.LogCapturer():
        manager.scan_simulation_and_add_all_descendants()
Exemplo n.º 15
0
def test_renumbering():
    testing.init_blank_db_for_testing()
    manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandlerReverseHaloNDM("dummy_sim_2"))
    assert not manager.simulation_exists()
    with log.LogCapturer():
        manager.scan_simulation_and_add_all_descendants()

    assert db.get_halo("dummy_sim_2/step.1/halo_2").halo_number==2
    assert db.get_halo("dummy_sim_2/step.1/halo_2").finder_id == 7
    assert db.get_halo("dummy_sim_2/step.1/halo_2").NDM==2006
Exemplo n.º 16
0
def setup():
    testing.init_blank_db_for_testing()

    generator = tangos.testing.simulation_generator.TestSimulationGenerator()
    generator.add_timestep()
    ts1_h1, ts1_h2, ts1_h3, ts1_h4, ts1_h5 = generator.add_objects_to_timestep(
        5)

    ts1_h1['testlink'] = ts1_h2, ts1_h3, ts1_h4, ts1_h5
    ts1_h1['testlink_univalued'] = ts1_h2

    ts1_h5['nonexistent_link'] = 0  # This is just to generate the results

    ts1_h2['testval'] = 1.0
    ts1_h2['testvalpartial'] = 1.0
    ts1_h3['testval'] = 2.0
    ts1_h3['testvalpartial'] = 2.0
    ts1_h4['testval'] = 3.0
    ts1_h5['testval'] = 0.0

    ts1_h2['testval2'] = 10.0
    ts1_h3['testval2'] = 20.0
    ts1_h4['testval2'] = 30.0
    ts1_h5['testval2'] = 40.0

    generator.add_timestep()
    ts2_h1, ts2_h2 = generator.add_objects_to_timestep(2)
    ts2_h1['testval'] = 2.0
    ts2_h2['testval'] = 100.0
    generator.link_last_halos_using_mapping({2: 1, 3: 2})

    generator_sim2 = tangos.testing.simulation_generator.TestSimulationGenerator(
        "sim2")
    # this is added to offer red herring links that should be ignored
    # We add a timestep and links that create an illusory past, but actually it's in another simulation
    # so should be ignored. It triggers a problem with the original implementation of find_progenitor.

    generator_sim2.add_timestep()
    s2_h1, s2_h2 = generator_sim2.add_objects_to_timestep(2)
    generator_sim2.link_last_halos_across_using_mapping(
        generator, {
            1: 1,
            2: 2
        })
    s2_h2['testval'] = 1e6

    # end of red herring

    generator.add_timestep()
    ts3_h1, ts3_h2 = generator.add_objects_to_timestep(2)
    generator.link_last_halos()
    ts3_h1['testval'] = -1.0
    ts3_h2['testval'] = 1000.0

    db.core.get_default_session().commit()
Exemplo n.º 17
0
def setup():
    _ensure_dummy_gadgetsnaps_exist()

    testing.init_blank_db_for_testing()
    tangos.config.base = os.path.join(os.path.dirname(__file__),
                                      "test_simulations")

    manager = tools.add_simulation.SimulationAdderUpdater(
        input_handlers.pynbody.GadgetRockstarInputHandler(
            "test_gadget_rockstar"))
    with log.LogCapturer():
        manager.scan_simulation_and_add_all_descendants()
Exemplo n.º 18
0
def setup():
    testing.init_blank_db_for_testing()

    generator = tangos.testing.simulation_generator.TestSimulationGenerator()

    ts1 = generator.add_timestep()
    generator.add_objects_to_timestep(2)
    ts2 = generator.add_timestep()
    generator.add_objects_to_timestep(1)
    generator.link_last_halos_using_mapping({1:1, 2:1})

    _setup_dummy_histogram_data(ts1, ts2)
Exemplo n.º 19
0
def setup_func():
    parallel_tasks.use('null')
    testing.init_blank_db_for_testing()
    db.config.base = os.path.join(os.path.dirname(__file__),
                                  "test_simulations")
    manager = add_simulation.SimulationAdderUpdater(
        output_testing.TestInputHandler("dummy_sim_1"))
    manager2 = add_simulation.SimulationAdderUpdater(
        output_testing.TestInputHandler("dummy_sim_2"))
    with log.LogCapturer():
        manager.scan_simulation_and_add_all_descendants()
        manager2.scan_simulation_and_add_all_descendants()
        writer = property_writer.PropertyWriter()
        writer.parse_command_line(['dummy_property'])
        writer.run_calculation_loop()
Exemplo n.º 20
0
def setup():
    pt.use("multiprocessing")
    testing.init_blank_db_for_testing(timeout=0.1, verbose=False)

    session = db.core.get_default_session()

    sim = tangos.core.simulation.Simulation("sim")
    session.add(sim)

    ts1 = tangos.core.timestep.TimeStep(sim, "ts1")
    session.add(ts1)

    halo_1 = tangos.core.halo.Halo(ts1, 1, 0, 0, 0, 0)
    session.add_all([halo_1])

    session.commit()
Exemplo n.º 21
0
def setup_module():
    testing.init_blank_db_for_testing()
    generator = SimulationGeneratorForTests()

    generator.add_timestep()
    generator.add_objects_to_timestep(10)

    generator.add_properties_to_halos(Mvir=lambda i: 1. * i)

    halo = tangos.get_halo(1)

    session = core.get_default_session()
    px = create_property(halo, "Mvir", -1., session)
    session.add(px, session)
    px = create_property(halo, "Mvir", -2., session)
    session.add(px, session)
    session.commit()

    # Also create links between halos, including duplicates
    halo2 = tangos.get_halo(2)
    halo3 = tangos.get_halo(3)
    halo9 = tangos.get_halo(9)

    # two links between halo 1 to halo 2 with the same weight and name (maximal duplicate)
    d_test = tangos.core.get_or_create_dictionary_item(session, "test")
    l_obj = link.HaloLink(halo, halo2, d_test, 1.0)
    session.add(l_obj)
    l_obj = link.HaloLink(halo, halo2, d_test, 1.0)
    session.add(l_obj)
    # and another time but with same weight but different name (not a duplicate)
    diff_name = tangos.core.get_or_create_dictionary_item(
        session, "other_test")
    l_obj = link.HaloLink(halo, halo2, diff_name, 1.0)
    session.add(l_obj)
    # and another time, with same name but different weight
    # (this is a non-maximal duplicate, oldest addition gets deleted and we keep the most recent link)
    l_obj = link.HaloLink(halo, halo2, d_test, 0.5)
    session.add(l_obj)
    # and another time, with same weight and name as previous but linking to a different halo (not a duplicate)
    l_obj = link.HaloLink(halo, halo3, d_test, 1.0)
    session.add(l_obj)

    # and now a completely independent link between halo 2 to halo 9
    l_obj = link.HaloLink(halo2, halo9, d_test, 1.0)
    session.add(l_obj)
Exemplo n.º 22
0
def setup():
    testing.init_blank_db_for_testing()

    creator = tangos.testing.simulation_generator.TestSimulationGenerator()

    halo_offset = 0
    for ts in range(1,4):
        creator.add_timestep()
        creator.add_objects_to_timestep(4)
        creator.link_last_halos()

    tangos.get_default_session().commit()
    tangos.get_item("sim/ts1/halo_1")['test_image'] = np.zeros((500,500,3))
    for ts in tangos.get_simulation(1).timesteps:
        for h in ts.halos:
            h['test_value'] = 1.0

    tangos.get_default_session().commit()

    creator.add_timestep()  # add ts 4
    creator.add_objects_to_timestep(3)
    tangos.get_default_session().commit()
    # now make the object have halo numbers which have a different ordering to the database IDs
    tangos.get_item("sim/ts4/1")['test_value'] = 1.0
    tangos.get_item("sim/ts4/2")['test_value'] = 2.0
    tangos.get_item("sim/ts4/3")['test_value'] = 3.0
    tangos.get_item("sim/ts4/1").halo_number = 10
    tangos.get_default_session().commit()


    creator = tangos.testing.simulation_generator.TestSimulationGenerator("simname/has/slashes")
    creator.add_timestep()
    creator.add_objects_to_timestep(1)
    creator.add_timestep()
    creator.add_objects_to_timestep(1)
    creator.link_last_halos()
    tangos.get_simulation(2).timesteps[0].halos[0]['test_value'] = 2.0
    tangos.get_default_session().commit()



    global app
    app = TestApp(tangos.web.main({}))
Exemplo n.º 23
0
def setup_module():
    if testing_db_backend != "sqlite":
        skip("This test is only relevant for sqlite databases")

    pt.use("multiprocessing")
    testing.init_blank_db_for_testing(timeout=0.1, verbose=False)

    session = db.core.get_default_session()

    sim = tangos.core.simulation.Simulation("sim")
    session.add(sim)

    ts1 = tangos.core.timestep.TimeStep(sim, "ts1")
    session.add(ts1)

    halo_1 = tangos.core.halo.Halo(ts1, 1, 1, 1, 0, 0, 0, 0)
    session.add_all([halo_1])

    session.commit()
Exemplo n.º 24
0
def setup():
    global output_manager, iord_expected_s960, iord_expected_s832
    testing.init_blank_db_for_testing()
    db.config.base = os.path.join(os.path.dirname(__file__),
                                  "test_simulations")
    output_manager = pynbody_outputs.ChangaInputHandler("test_tipsy")
    with log.LogCapturer():
        add.SimulationAdderUpdater(
            output_manager).scan_simulation_and_add_all_descendants()

    h1 = db.get_halo("test_tipsy/%640/1").load()
    h1_sub = h1[::5]

    tracking.new("test_tipsy", h1_sub)
    iord_expected_s960 = copy.deepcopy(h1_sub['iord'])

    # because the tiny test files are downsampled, only a small number of particles are actually
    # in common between the two steps
    iord_expected_s832 = np.intersect1d(
        iord_expected_s960,
        db.get_timestep("test_tipsy/%832").load()['iord'])
Exemplo n.º 25
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.º 26
0
def setup():
    testing.init_blank_db_for_testing()

    creator = tangos.testing.simulation_generator.TestSimulationGenerator()

    halo_offset = 0
    for ts in range(1, 4):
        num_halos = 4 if ts < 3 else 3
        creator.add_timestep()
        creator.add_objects_to_timestep(num_halos)
        creator.add_properties_to_halos(Mvir=lambda i: i + halo_offset)
        creator.add_properties_to_halos(Rvir=lambda i: (i + halo_offset) * 0.1)
        halo_offset += num_halos

        creator.add_bhs_to_timestep(4)
        creator.add_properties_to_bhs(hole_mass=lambda i: float(i * 100))
        creator.add_properties_to_bhs(
            hole_spin=lambda i: 1000 - float(i) * 100)

        creator.assign_bhs_to_halos({1: 1, 2: 2, 3: 3, 4: 3})

        if ts > 1:
            creator.link_last_halos()
            creator.link_last_bhs_using_mapping({1: 1})
Exemplo n.º 27
0
def setup():
    testing.init_blank_db_for_testing()
Exemplo n.º 28
0
def setup_module():
    testing.init_blank_db_for_testing()
    creator = testing.simulation_generator.SimulationGeneratorForTests()
    creator.add_timestep()
Exemplo n.º 29
0
def setup():
    global output_manager
    testing.init_blank_db_for_testing()
    db.config.base = os.path.join(os.path.dirname(__file__),
                                  "test_simulations")
    output_manager = pynbody_outputs.ChangaInputHandler("test_tipsy")
Exemplo n.º 30
0
def setup_module():
    testing.init_blank_db_for_testing()