def _Pressure(field, data):
    gamma = 5. / 3.
    m_p = YTQuantity(1.6726219e-24, 'g')  # mass of proton in grams
    mu = 1.2
    kb = YTQuantity(1.38e-16, 'erg/K')  #boltzmann constant cgs
    u = data[('Gas', 'Temperature')] * kb / (mu * m_p * (gamma - 1.))
    return u * data[('Gas', 'density')] * (gamma - 1.)
Esempio n. 2
0
def _assert_normalisations_equal(ds):
    assert_allclose_units(ds.length_unit, YTQuantity(*length_unit))
    assert_allclose_units(ds.numberdensity_unit, YTQuantity(*numberdensity_unit))
    assert_allclose_units(ds.temperature_unit, YTQuantity(*temperature_unit))
    assert_allclose_units(ds.density_unit, YTQuantity(*density_unit))
    assert_allclose_units(ds.mass_unit, YTQuantity(*mass_unit))
    assert_allclose_units(ds.velocity_unit, YTQuantity(*velocity_unit))
    assert_allclose_units(ds.pressure_unit, YTQuantity(*pressure_unit))
    assert_allclose_units(ds.time_unit, YTQuantity(*time_unit))
    assert_allclose_units(ds.magnetic_unit, YTQuantity(*magnetic_unit))
Esempio n. 3
0
def test_normalisations_default():
    # test default normalisations, without overrides
    ds = data_dir_load(khi_cartesian_2D)
    assert_allclose_units(ds.length_unit, YTQuantity(1, 'cm'))
    assert_allclose_units(ds.numberdensity_unit, YTQuantity(1, 'cm**-3'))
    assert_allclose_units(ds.temperature_unit, YTQuantity(1, 'K'))
    assert_allclose_units(ds.density_unit, YTQuantity(2.341670657200000e-24, 'g*cm**-3'))
    assert_allclose_units(ds.mass_unit, YTQuantity(2.341670657200000e-24, 'g'))
    assert_allclose_units(ds.velocity_unit, YTQuantity(1.164508387441102e+04, 'cm*s**-1'))
    assert_allclose_units(ds.pressure_unit, YTQuantity(3.175492240000000e-16, 'dyn*cm**-2'))
    assert_allclose_units(ds.time_unit, YTQuantity(8.587314705370271e-05, 's'))
    assert_allclose_units(ds.magnetic_unit, YTQuantity(6.316993934686148e-08, 'gauss'))
Esempio n. 4
0
def test_schema_validation():

    valid_schemas = [
        {
            "length_unit": 1.0
        },
        {
            "length_unit": [1.0]
        },
        {
            "length_unit": (1.0, )
        },
        {
            "length_unit": int(1.0)
        },
        {
            "length_unit": (1.0, "m")
        },
        {
            "length_unit": [1.0, "m"]
        },
        {
            "length_unit": YTQuantity(1.0, "m")
        },
    ]

    for schema in valid_schemas:
        uo = Dataset._sanitize_units_override(schema)
        for v in uo.values():
            q = mock_quan(v)  # check that no error (TypeError) is raised
            q.to("pc")  # check that q is a length
Esempio n. 5
0
def test_default_to_cartesian():
    data = {"density": np.random.random(128)}
    ds_attrs = {"current_time": YTQuantity(10, "Myr")}
    with TemporaryDirectory() as tmpdir:
        tmpf = os.path.join(tmpdir, "savefile.h5")
        fn = save_as_dataset(ds_attrs, tmpf, data)
        ds2 = load(fn)
    assert ds2.geometry == "cartesian"
Esempio n. 6
0
def just_one(obj):
    # If we have an iterable, sometimes we only want one item
    if hasattr(obj, "flat"):
        if isinstance(obj, YTArray):
            return YTQuantity(obj.flat[0], obj.units, registry=obj.units.registry)
        return obj.flat[0]
    elif iterable(obj):
        return obj[0]
    return obj
Esempio n. 7
0
def test_just_one():
    # Check that behaviour of this function is consistent before and after refactor
    # PR 2893
    for unit in ["mm", "cm", "km", "pc", "g", "kg", "M_sun"]:
        obj = YTArray([0.0, 1.0], unit)
        expected = YTQuantity(obj.flat[0],
                              obj.units,
                              registry=obj.units.registry)
        jo = just_one(obj)
        assert jo == expected
Esempio n. 8
0
def test_validate_center():
    validate_center("max")
    validate_center("MIN_")

    with assert_raises(TypeError) as ex:
        validate_center("avg")
    desired = ("Expected 'center' to be in ['c', 'center', 'm', 'max', 'min'] "
               "or the prefix to be 'max_'/'min_', received 'avg'.")
    assert_equal(str(ex.exception), desired)

    validate_center(YTQuantity(0.25, "cm"))
    validate_center([0.25, 0.25, 0.25])

    class CustomCenter:
        def __init__(self, center):
            self.center = center

    with assert_raises(TypeError) as ex:
        validate_center(CustomCenter(10))
    desired = ("Expected 'center' to be a numeric object of type "
               "list/tuple/np.ndarray/YTArray/YTQuantity, received "
               "'yt.tests.test_funcs.test_validate_center.<locals>."
               "CustomCenter'.")
    assert_equal(str(ex.exception)[:50], desired[:50])
Esempio n. 9
0
 def get_mass(field, data):
     species_mass = data.ds.index.parameters[ptype + "_mass"]
     return data["particle_weight"] * YTQuantity(species_mass, "kg")
Esempio n. 10
0
 def get_charge(field, data):
     species_charge = data.ds.index.parameters[ptype + "_charge"]
     return data["particle_weight"] * YTQuantity(species_charge, "C")
Esempio n. 11
0
def test_dimensionality_error_detection():
    invalid_schema = {"length_unit": YTQuantity(1.0, "s")}
    assert_raises(ValueError, Dataset._sanitize_units_override, invalid_schema)