def test_wind_mover():
    '''
        Use a wind_mover, about as simple as it comes
        - We are moving to a design where the environment objects contain the
          extrapolate flag instead of the movers.  This flag is off by default.
    '''

    # fake data arrays:
    num = 2

    pos_dt = np.dtype([('lon', np.float),
                       ('lat', np.float),
                       ('depth', np.float)])

    sc = SC({'positions': np.zeros((num,), dtype=pos_dt),
             'status_codes': np.zeros((num,), dtype=np.int16),
             'windages': np.zeros((num,)),
             })

    wind = wind_from_values([(datetime(2016, 5, 10, 12, 0), 5, 45),
                             (datetime(2016, 5, 10, 12, 20), 6, 50),
                             (datetime(2016, 5, 10, 12, 40), 7, 55),
                             ])
    wm = WindMover(wind)

    # within the model's time span, this should work:
    wm.prepare_for_model_step(sc, 600, datetime(2016, 5, 10, 12, 20))

    # before time span -- this should fail
    with pytest.raises(RuntimeError):
        wm.prepare_for_model_step(sc, 600, datetime(2016, 5, 10, 11, 50))

    # after time span -- this should fail
    with pytest.raises(RuntimeError):
        wm.prepare_for_model_step(sc, 600, datetime(2016, 5, 10, 12, 50))

    # turn on extrapolation in the wind environment object
    wind.extrapolation_is_allowed = True

    # before timespan -- this should pass now
    wm.prepare_for_model_step(sc, 600, datetime(2016, 5, 10, 11, 50))

    # after timespan -- this should pass now
    wm.prepare_for_model_step(sc, 600, datetime(2016, 5, 10, 12, 50))

    # test the error message that we get when a RuntimeError is raised.
    with pytest.raises(RuntimeError):
        try:
            wind.extrapolation_is_allowed = False
            wm.prepare_for_model_step(sc, 600, datetime(2016, 5, 10, 11, 50))
        except RuntimeError as err:
            msg = err.args[0]
            assert "No available data" in msg
            assert "WindMover" in msg
            assert "2016-05-10 11:50:00" in msg
            assert "2016-05-10 12:00:00" in msg
            assert "2016-05-10 12:40:00" in msg
            raise
Esempio n. 2
0
def test_wind_from_values():
    """
    simple test for the utility
    """
    values = [(datetime(2016, 5, 10, 12,  0), 5, 45),
              (datetime(2016, 5, 10, 12, 20), 6, 50),
              (datetime(2016, 5, 10, 12, 40), 7, 55),
              ]

    wind = wind_from_values(values)

    # see if it's got the correct data
    for dt, r, theta in values:
        vals = wind.get_value(dt)
        assert np.allclose(vals[0], r)
        assert np.allclose(vals[1], theta)
Esempio n. 3
0
def test_wind_from_values_knots():
    """
    simple test for the utility == passing in knots
    """
    values = [(datetime(2016, 5, 10, 12,  0), 5, 45),
              (datetime(2016, 5, 10, 12, 20), 6, 50),
              (datetime(2016, 5, 10, 12, 40), 7, 55),
              ]

    wind = wind_from_values(values, units='knot')

    # see if it's got the correct data
    for dt, r, theta in values:
        vals = wind.get_value(dt)
        assert np.allclose(vals[0], unit_conversion.convert('velocity', 'knot', 'm/s', r))
        assert np.allclose(vals[1], theta)
Esempio n. 4
0
def test_wind_from_values():
    """
    simple test for the utility
    """
    values = [(datetime(2016, 5, 10, 12,  0), 5, 45),
              (datetime(2016, 5, 10, 12, 20), 6, 50),
              (datetime(2016, 5, 10, 12, 40), 7, 55),
              ]

    wind = wind_from_values(values)

    # see if it's got the correct data
    for dt, r, theta in values:
        vals = wind.get_value(dt)
        assert np.allclose(vals[0], r)
        assert np.allclose(vals[1],theta)
Esempio n. 5
0
def test_wind_from_values_knots():
    """
    simple test for the utility == passing in knots
    """
    values = [(datetime(2016, 5, 10, 12,  0), 5, 45),
              (datetime(2016, 5, 10, 12, 20), 6, 50),
              (datetime(2016, 5, 10, 12, 40), 7, 55),
              ]

    wind = wind_from_values(values, units='knot')

    # see if it's got the correct data
    for dt, r, theta in values:
        vals = wind.get_value(dt)
        assert np.allclose(vals[0], unit_conversion.convert('velocity',
                                                            'knot', 'm/s', r))
        assert np.allclose(vals[1], theta)
def test_wind_mover():
    """
    use a wind_mover, about as simple as it comes
    """

    # fake data arrays:
    num = 2
    pos_dt = np.dtype([('lon', np.float), ('lat', np.float), ('depth', np.float)])
    sc = SC({'positions': np.zeros((num,), dtype=pos_dt),
             'status_codes': np.zeros((num,), dtype=np.int16),
             'windages': np.zeros((num,)),
             })
#    delta = np.zeros_like(sc['positions'])

    wind = wind_from_values([(datetime(2016, 5, 10, 12, 0), 5, 45),
                             (datetime(2016, 5, 10, 12, 20), 6, 50),
                             (datetime(2016, 5, 10, 12, 40), 7, 55),
                             ])
    wm = WindMover(wind)
    # in time span, this should work:
    wm.prepare_for_model_step(sc, 600, datetime(2016, 5, 10, 12, 20))

    # before timespan -- this should fail
    with pytest.raises(RuntimeError):
        wm.prepare_for_model_step(sc, 600, datetime(2016, 5, 10, 11, 50))

    # after timespan -- this should fail
    with pytest.raises(RuntimeError):
        wm.prepare_for_model_step(sc, 600, datetime(2016, 5, 10, 12, 50))

    # # test the message:
    # try:
    #     wm.prepare_for_model_step(sc, 600, datetime(2016, 5, 10, 11, 50))
    # except RuntimeError as err:

    try:
        wm.prepare_for_model_step(sc, 600, datetime(2016, 5, 10, 11, 50))
    except RuntimeError as err:
        msg = err.args[0]
        assert "No available data" in msg
        assert "WindMover" in msg
        assert "2016-05-10 11:50:00" in msg
        assert "2016-05-10 12:00:00" in msg
        assert "2016-05-10 12:40:00" in msg