Beispiel #1
0
def test_from_pressure():
    """Test instantiation of Atmosphere with 'from_pressure()' method"""

    with pytest.raises(ValueError):
        Atmosphere.from_pressure(-15.6)

    with pytest.raises(ValueError):
        Atmosphere.from_pressure([1e5, 0])

    # --- Scalar input ---
    for h_exp in np.arange(CONST.h_min+1000, CONST.h_max, 171.3):
        p = Atmosphere(h_exp).pressure
        h_comp = Atmosphere.from_pressure(p).h
        assert h_exp == approx(h_comp)

    # --- Vector input ---
    h_exp = [0, -2000, 1e3, 30e3, -50, 71938]
    p = Atmosphere(h_exp).pressure
    h_comp = Atmosphere.from_pressure(p).h
    assert np.testing.assert_allclose(h_exp, h_comp) is None

    # --- Matrix input ---
    h_exp = np.array([
        [0, -2000, 1e3],
        [30e3, -50, 71938],
        [888, 444, 9999.33],
    ])
    p = Atmosphere(h_exp).pressure
    h_comp = Atmosphere.from_pressure(p).h
    assert np.testing.assert_allclose(h_exp, h_comp) is None
Beispiel #2
0
def test_from_pressure():
    """Test instantiation of Atmosphere with 'from_pressure()' method"""

    value_errors = [
        -15.6,
        (),
        [[]],
        [1, [2, 3]],
        [1e5, 0],
        CONST.p_min * 0.9,
        CONST.p_max * 1.1,
    ]

    for value_error in value_errors:
        with pytest.raises(ValueError):
            Atmosphere.from_pressure(value_error)

    # --- Scalar input ---
    for h_exp in np.arange(CONST.h_min, CONST.h_max, 30.):
        p = Atmosphere(h_exp).pressure
        h_comp = Atmosphere.from_pressure(p).h
        assert h_exp == approx(h_comp)

    # Test boundaries
    for h_exp in [CONST.h_min, CONST.h_max]:
        p = Atmosphere(h_exp).pressure
        h_comp = Atmosphere.from_pressure(p).h
        assert h_exp == approx(h_comp)

    # --- Vector input ---
    h_exp = [0, -2000, 1e3, 30e3, -50, 71938]
    p = Atmosphere(h_exp).pressure
    h_comp = Atmosphere.from_pressure(p).h
    assert np.testing.assert_allclose(h_exp, h_comp, atol=1e-9) is None

    # Whole pressure range can be passed in
    p = np.linspace(CONST.p_min, CONST.p_max, 1000)
    atmos = Atmosphere.from_pressure(p)
    assert np.testing.assert_allclose(p, atmos.pressure) is None

    # --- Matrix input ---
    h_exp = np.array([
        [0, -2000, 1e3],
        [30e3, -50, 71938],
        [888, 444, 9999.33],
    ])
    p = Atmosphere(h_exp).pressure
    h_comp = Atmosphere.from_pressure(p).h
    assert np.testing.assert_allclose(h_exp, h_comp, atol=1e-9) is None