def test_upper_hybrid_frequency():
    r"""Test the upper_hybrid_frequency function in parameters.py."""

    omega_uh = upper_hybrid_frequency(B, n_e=n_e)
    omega_ce = gyrofrequency(B)
    omega_pe = plasma_frequency(n=n_e)
    assert omega_ce.unit.is_equivalent(u.rad / u.s)
    assert omega_pe.unit.is_equivalent(u.rad / u.s)
    assert omega_uh.unit.is_equivalent(u.rad / u.s)
    left_hand_side = omega_uh**2
    right_hand_side = omega_ce**2 + omega_pe**2
    assert np.isclose(left_hand_side.value, right_hand_side.value)

    with pytest.raises(ValueError):
        upper_hybrid_frequency(5 * u.T, n_e=-1 * u.m**-3)

    with pytest.warns(u.UnitsWarning):
        assert upper_hybrid_frequency(1.2, 1.3) == upper_hybrid_frequency(
            1.2 * u.T, 1.3 * u.m**-3)

    with pytest.warns(u.UnitsWarning):
        assert upper_hybrid_frequency(1.4 * u.T,
                                      1.3) == upper_hybrid_frequency(
                                          1.4, 1.3 * u.m**-3)

    assert_can_handle_nparray(upper_hybrid_frequency)
Esempio n. 2
0
 def time_upper_hybrid_frequency(self):
     upper_hybrid_frequency(0.2*u.T,
                            n_e=5e19*u.m**-3,
                            to_hz = True)