Beispiel #1
0
def test_integer_overflow_error():
    """
    Check that integer input is not treated differently from float inputs

    Background:

    * In version 1.1.2 utility functions did not explicitely convert integer
      input to float-valued arrays. Numpy arrays on Windows resulted in
      completly wrong results (Linux not affected). E.g. on Windows we got:

      h = Atmosphere.geop2geom_height([0, 1000, 10000])
      atmosphere.h
      array([   0.        ,  324.39814556, -135.00567691]
    """

    # --- geop2geom_height ---
    h_inputs = [
        [0, 1000, 10000],
        np.array([0, 1000, 10000], dtype=int),
        np.asarray([0, 1000, 10000], dtype=int),
        np.asarray([0, 1000, 10000], dtype=np.int16),
        np.asarray([0, 1000, 10000], dtype=np.int32),
        np.asarray([0, 1000, 10000], dtype=np.int64),
    ]
    for h_input in h_inputs:
        h = Atmosphere.geop2geom_height(h_input)
        atmos = Atmosphere(h)
        assert atmos.h[0] == approx(0., 1e-4)
        assert atmos.h[1] == approx(1000.157337, 1e-4)
        assert atmos.h[2] == approx(10015.756056, 1e-4)

    h = Atmosphere.geop2geom_height(1000)
    atmos = Atmosphere(h)
    assert atmos.h[0] == approx(1000.1573374476027, 1e-4)

    # --- geom2geop_height ---
    H = Atmosphere.geom2geop_height(int(1000))
    assert Atmosphere.geop2geom_height(H) == approx(1000, 1e-4)
    assert Atmosphere.geop2geom_height(float(H)) == approx(1000, 1e-4)
Beispiel #2
0
def test_geom_geop_height_conversion():
    """Test conversion between geometric and geopotential height"""

    # Test different inputs
    inputs = [
        np.arange(-5e3, 80e3, 1e3),
        (-5e3, 80e3, 1e3),
        [-5e3, 80e3, 1e3],
        -5000,
    ]

    for in_data in inputs:
        geom_height_in = np.arange(-5e3, 80e3, 1e3)

        geop_height_out = Atmosphere.geom2geop_height(geom_height_in)
        geom_height_out = Atmosphere.geop2geom_height(geop_height_out)

        assert np.testing.assert_allclose(geom_height_out, geom_height_in) is None