Esempio n. 1
0
def test_simulation_exists(fresh_database):
    manager = add_simulation.SimulationAdderUpdater(
        output_testing.TestInputHandler("dummy_sim_2"))
    assert not manager.simulation_exists()

    manager = add_simulation.SimulationAdderUpdater(
        output_testing.TestInputHandler("dummy_sim_1"))
    assert manager.simulation_exists()
Esempio n. 2
0
def setup():
    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()
Esempio n. 3
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()
Esempio n. 4
0
def test_NDM_cut(fresh_database_no_contents):
    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
Esempio n. 5
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()
Esempio n. 6
0
def test_insert_halos():
    #stat.HaloStatFile(ts1.filename).add_halos(min_NDM=200000)
    adder = add_simulation.SimulationAdderUpdater(sim.get_output_handler())
    adder.min_halo_particles = 200000
    adder.add_objects_to_timestep(ts1)
    assert ts1.halos.count() == 3
    assert ts1.halos[0].NDM == 4348608
    assert ts1.halos[1].NDM == 402567
Esempio n. 7
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()
Esempio n. 8
0
def test_readd_simulation():
    manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandler("dummy_sim_1"))
    with log.LogCapturer():
        manager.scan_simulation_and_add_all_descendants()

    assert db.core.get_default_session().query(db.core.Simulation).count()==1
    assert len(db.get_simulation("dummy_sim_1").timesteps)==2
    assert db.get_simulation("dummy_sim_1").properties.count()==3
Esempio n. 9
0
def _perform_simulation_update():
    try:
        old_base = db.config.base
        db.config.base = os.path.join(os.path.dirname(__file__), "test_simulations_mock_update")
        manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandler("dummy_sim_1"))
        with log.LogCapturer():
            manager.scan_simulation_and_add_all_descendants()
    finally:
        db.config.base = old_base
Esempio n. 10
0
def test_renumbering(fresh_database_no_contents):
    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
Esempio n. 11
0
def test_renumbering_disabled():
    testing.init_blank_db_for_testing()
    manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandlerReverseHaloNDM("dummy_sim_2"),
                                                    renumber=False)
    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 == 2
    assert db.get_halo("dummy_sim_2/step.1/halo_2").NDM==2001
Esempio n. 12
0
def add_test_simulation_to_db():
    global _added_to_db

    if not _added_to_db:
        with log.LogCapturer():
            add.SimulationAdderUpdater(
                output_manager).scan_simulation_and_add_all_descendants()
        tx = db.core.tracking.TrackData(db.get_simulation("test_tipsy"))
        tx.particles = tracked_particles
        tx.use_iord = False
        tx = db.core.get_default_session().merge(tx)
        tx.create_objects()

        tx = db.core.tracking.TrackData(db.get_simulation("test_tipsy"))
        tx.particles = tracked_iord
        tx.use_iord = True
        tx = db.core.get_default_session().merge(tx)
        tx.create_objects()
        _added_to_db = True
Esempio n. 13
0
def test_insert_properties():
    for h in ts1.halos:
        db.get_default_session().delete(
            h)  # remove previous objects so that we can add them afresh
    adder = add_simulation.SimulationAdderUpdater(sim.get_output_handler())
    adder.add_objects_to_timestep(ts1)
    importer = property_importer.PropertyImporter()
    importer.parse_command_line(
        "Mvir Rvir hostHalo childHalo --for test_stat_files".split())
    print(importer.options)
    importer.run_calculation_loop()
    npt.assert_almost_equal(ts1.halos[0]["Rvir"], 195.87)
    npt.assert_almost_equal(ts1.halos[0]["Mvir"], 5.02432e+11)
    with npt.assert_raises(KeyError):
        ts1.halos[0]['hostHalo']
    with npt.assert_raises(KeyError):
        ts1.halos[1]['childHalo']
    assert ts1.halos[2]['hostHalo'] == ts1.halos[0]
    assert ts1.halos[3]['hostHalo'] == ts1.halos[0]
    testing.assert_halolists_equal(ts1.halos[0]['childHalo'],
                                   [ts1.halos[2], ts1.halos[3]])
Esempio n. 14
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'])
Esempio n. 15
0
def test_limited_numbers(fresh_database_no_contents):
    manager = add_simulation.SimulationAdderUpdater(
        output_testing.TestInputHandlerReverseHaloNDM("dummy_sim_2"))
    manager.max_num_objects = 3
    manager.scan_simulation_and_add_all_descendants()
    assert db.get_timestep("dummy_sim_2/step.1").halos.count() == 3
Esempio n. 16
0
def test_limited_numbers():
    testing.init_blank_db_for_testing()
    manager = add_simulation.SimulationAdderUpdater(output_testing.TestInputHandlerReverseHaloNDM("dummy_sim_2"))
    manager.max_num_objects = 3
    manager.scan_simulation_and_add_all_descendants()
    assert db.get_timestep("dummy_sim_2/step.1").halos.count()==3