def calculate_inertial_length(form):
    n = form['n']
    p = form['particle']

    n_quantity = u.Quantity(n, u.Unit(form['unitsN']))
    sum = pfp.inertial_length(n_quantity, p)
    return sum
Esempio n. 2
0
def calculate_inertial_length(form):
    r''' Returns 
        --------
        Quantity 
            Inertial length in meters (m)

        Parameters
        ---------- 
        `form`: The calculator form from the HTML page where the user enters data for calculation.
    '''
    n = form['n']  # Particle number density
    p = form['particle']  # Particle
    u1 = form['unitsN']

    if n == "" or u1 == 'select':
        return -1

    n_quantity = u.Quantity(n, u.Unit(u1))
    sum = pfp.inertial_length(n_quantity, p)
    return sum
Esempio n. 3
0
def test_inertial_length():
    r"""Test the inertial_length function in parameters.py."""

    assert inertial_length(n_i, particle="p").unit.is_equivalent(u.m)

    assert np.isclose(inertial_length(mu * u.cm**-3, particle="p").cgs.value,
                      2.28e7,
                      rtol=0.01)

    inertial_length_electron_plus = inertial_length(5.351 * u.m**-3,
                                                    particle="e+")
    assert inertial_length_electron_plus == inertial_length(5.351 * u.m**-3,
                                                            particle="e")

    assert inertial_length(n_i, particle="p") == inertial_length(n_i,
                                                                 particle="p")

    with pytest.warns(u.UnitsWarning):
        inertial_length(4, particle="p")

    with pytest.raises(u.UnitTypeError):
        inertial_length(4 * u.m**-2, particle="p")

    with pytest.raises(ValueError):
        inertial_length(-5 * u.m**-3, particle="p")

    with pytest.raises(InvalidParticleError):
        inertial_length(n_i, particle=-135)

    with pytest.warns(u.UnitsWarning):
        inertial_length_no_units = inertial_length(1e19, particle="p")
        assert inertial_length_no_units == inertial_length(1e19 * u.m**-3,
                                                           particle="p")

    assert inertial_length(n_e, "e-").unit.is_equivalent(u.m)

    assert np.isclose(inertial_length(1 * u.cm**-3, "e-").cgs.value,
                      5.31e5,
                      rtol=1e-3)

    with pytest.warns(u.UnitsWarning):
        inertial_length(5, "e-")

    with pytest.raises(u.UnitTypeError):
        inertial_length(5 * u.m, "e-")

    with pytest.raises(ValueError):
        inertial_length(-5 * u.m**-3, "e-")

    with pytest.warns(u.UnitsWarning):
        assert inertial_length(1e19,
                               "e-") == inertial_length(1e19 * u.m**-3, "e-")

    assert_can_handle_nparray(inertial_length)
Esempio n. 4
0
 def time_inertial_length(self):
     inertial_length(5 * u.m**-3, 'He+')