Ejemplo n.º 1
0
def test_insert_properties():
    importer = property_importer.PropertyImporter()
    importer.parse_command_line("Mvir Rvir --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)
Ejemplo n.º 2
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]])
Ejemplo n.º 3
0
def test_import_properties_is_only_numeric_or_array():
    import tangos.core as core

    # Pick a random existing property name and halo for testing the import of properties
    halo = ts1.halos[0]
    db_name = core.dictionary.get_or_create_dictionary_item(session, "Rvir")

    # Numeric types should create a property successfully
    importer = property_importer.PropertyImporter()
    property = importer._create_property(db_name, halo, int(42))
    assert property.data == 42

    property = importer._create_property(db_name, halo, float(42.0))
    assert property.data == 42.0

    # Arrays of numerics should now create a property successfully
    property = importer._create_property(db_name, halo, np.array([42, 42, 42]))
    assert property.data_is_array() == True
    assert property.data.dtype == np.int
    npt.assert_allclose(property.data, np.array([42, 42, 42]))

    property = importer._create_property(db_name, halo,
                                         np.array([42.0, 42.0, 42.0]))
    assert property.data_is_array() == True
    assert property.data.dtype == np.floating
    npt.assert_allclose(property.data, np.array([42.0, 42.0, 42.0]))

    # Importing a string should fail
    property = importer._create_property(db_name, halo, "42.0")
    assert property is None
    # Importing an object should fail
    property = importer._create_property(db_name, halo, halo)
    assert property is None
    # Importing an array of non-numeric types should fail
    property = importer._create_property(db_name, halo,
                                         np.array(["42.0", "42.0", "42.0"]))
    assert property is None