Exemplo n.º 1
0
    def test_constant_wind_after_model_time(self):
        '''
            test to make sure the wind mover is behaving properly with
            out-of-bounds winds.
            A constant wind should extrapolate if it is out of bounds,
            so prepare_for_model_step() should not fail.

            We are testing that the wind extrapolates properly, so the
            windages should be updated in the same way as the in-bounds test
        '''
        wind_time = datetime(2012, 8, 21, 13)  # one day after model time

        wind = Wind(timeseries=np.array((wind_time, (2., 25.)),
                                        dtype=datetime_value_2d).reshape(1),
                    units='meter per second')

        wm = WindMover(wind)
        wm.prepare_for_model_run()

        for ix in range(2):
            curr_time = sec_to_date(date_to_sec(self.model_time) +
                                    self.time_step * ix)
            print 'curr_time = ', curr_time

            old_windages = np.copy(self.sc['windages'])
            wm.prepare_for_model_step(self.sc, self.time_step, curr_time)

            mask = self.sc['windage_persist'] == -1
            assert np.all(self.sc['windages'][mask] == old_windages[mask])

            mask = self.sc['windage_persist'] > 0
            assert np.all(self.sc['windages'][mask] != old_windages[mask])
Exemplo n.º 2
0
def test_active():
    """ test that mover must be both active and on to get movement """

    time_step = 15 * 60  # seconds

    start_pos = (3., 6., 0.)
    rel_time = datetime(2012, 8, 20, 13)  # yyyy/month/day/hr/min/sec

    sc = sample_sc_release(5, start_pos, rel_time)

    # value is given as (r,theta)

    time_val = np.zeros((1, ), dtype=datetime_value_2d)
    time_val['time'] = rel_time
    time_val['value'] = (2., 25.)

    wm = WindMover(Wind(timeseries=time_val, units='meter per second'),
                   on=False)

    wm.prepare_for_model_run()
    wm.prepare_for_model_step(sc, time_step, rel_time)

    delta = wm.get_move(sc, time_step, rel_time)
    wm.model_step_is_done()

    assert wm.active is False
    assert np.all(delta == 0)  # model_time + time_step = active_start
Exemplo n.º 3
0
    def test_variable_wind_after_model_time(self):
        '''
            test to make sure the wind mover is behaving properly with
            out-of-bounds winds.
            A variable wind should not extrapolate if it is out of bounds,
            so prepare_for_model_step() should fail with an exception
            in this case.
        '''
        wind_time = datetime(2012, 8, 21, 13)  # one day after model time

        time_series = (np.zeros((3, ), dtype=datetime_value_2d)
                       .view(dtype=np.recarray))
        time_series.time = [sec_to_date(date_to_sec(wind_time) +
                                        self.time_step * i)
                            for i in range(3)]
        time_series.value = np.array(((2., 25.), (2., 25.), (2., 25.)))

        wind = Wind(timeseries=time_series.reshape(3),
                    units='meter per second')

        wm = WindMover(wind)
        wm.prepare_for_model_run()

        for ix in range(2):
            curr_time = sec_to_date(date_to_sec(self.model_time) +
                                    self.time_step * ix)

            with raises(RuntimeError):
                wm.prepare_for_model_step(self.sc, self.time_step, curr_time)
Exemplo n.º 4
0
def test_active():
    """ test that mover must be both active and on to get movement """

    time_step = 15 * 60  # seconds

    start_pos = (3., 6., 0.)
    rel_time = datetime(2012, 8, 20, 13)  # yyyy/month/day/hr/min/sec

    sc = sample_sc_release(5, start_pos, rel_time)

    # value is given as (r,theta)

    time_val = np.zeros((1, ), dtype=datetime_value_2d)
    time_val['time'] = np.datetime64(rel_time.isoformat())
    time_val['value'] = (2., 25.)

    wm = WindMover(environment.Wind(timeseries=time_val,
                   units='meter per second'), on=False)

    wm.prepare_for_model_run()
    wm.prepare_for_model_step(sc, time_step, rel_time)
    delta = wm.get_move(sc, time_step, rel_time)
    wm.model_step_is_done()
    assert wm.active == False
    assert np.all(delta == 0)  # model_time + time_step = active_start
Exemplo n.º 5
0
def test_prepare_for_model_step():
    """
    explicitly test to make sure windages are being updated for persistence
    != 0 and windages are not being changed for persistance == -1
    """
    time_step = 15 * 60  # seconds
    model_time = datetime(2012, 8, 20, 13)  # yyyy/month/day/hr/min/sec
    sc = sample_sc_release(5, (3., 6., 0.), model_time)
    sc['windage_persist'][:2] = -1
    wind = Wind(timeseries=np.array((model_time, (2., 25.)),
                                    dtype=datetime_value_2d).reshape(1),
                units='meter per second')

    wm = WindMover(wind)
    wm.prepare_for_model_run()

    for ix in range(2):
        curr_time = sec_to_date(date_to_sec(model_time) + time_step * ix)
        old_windages = np.copy(sc['windages'])
        wm.prepare_for_model_step(sc, time_step, curr_time)

        mask = [sc['windage_persist'] == -1]
        assert np.all(sc['windages'][mask] == old_windages[mask])

        mask = [sc['windage_persist'] > 0]
        assert np.all(sc['windages'][mask] != old_windages[mask])
Exemplo n.º 6
0
    def test_variable_wind_after_model_time(self):
        '''
            test to make sure the wind mover is behaving properly with
            out-of-bounds winds.
            A variable wind should not extrapolate if it is out of bounds,
            so prepare_for_model_step() should fail with an exception
            in this case.
        '''
        wind_time = datetime(2012, 8, 21, 13)  # one day after model time

        time_series = (np.zeros((3, ), dtype=datetime_value_2d)
                       .view(dtype=np.recarray))
        time_series.time = [sec_to_date(date_to_sec(wind_time) +
                                        self.time_step * i)
                            for i in range(3)]
        time_series.value = np.array(((2., 25.), (2., 25.), (2., 25.)))

        wind = Wind(timeseries=time_series.reshape(3),
                    units='meter per second')

        wm = WindMover(wind)
        wm.prepare_for_model_run()

        for ix in range(2):
            curr_time = sec_to_date(date_to_sec(self.model_time) +
                                    self.time_step * ix)

            with raises(RuntimeError):
                wm.prepare_for_model_step(self.sc, self.time_step, curr_time)
Exemplo n.º 7
0
    def test_constant_wind_after_model_time(self):
        '''
            test to make sure the wind mover is behaving properly with
            out-of-bounds winds.
            A constant wind should extrapolate if it is out of bounds,
            so prepare_for_model_step() should not fail.

            We are testing that the wind extrapolates properly, so the
            windages should be updated in the same way as the in-bounds test
        '''
        wind_time = datetime(2012, 8, 21, 13)  # one day after model time

        wind = Wind(timeseries=np.array((wind_time, (2., 25.)),
                                        dtype=datetime_value_2d).reshape(1),
                    units='meter per second')

        wm = WindMover(wind)
        wm.prepare_for_model_run()

        for ix in range(2):
            curr_time = sec_to_date(date_to_sec(self.model_time) +
                                    self.time_step * ix)
            print 'curr_time = ', curr_time

            old_windages = np.copy(self.sc['windages'])
            wm.prepare_for_model_step(self.sc, self.time_step, curr_time)

            mask = self.sc['windage_persist'] == -1
            assert np.all(self.sc['windages'][mask] == old_windages[mask])

            mask = self.sc['windage_persist'] > 0
            assert np.all(self.sc['windages'][mask] != old_windages[mask])
Exemplo n.º 8
0
def test_prepare_for_model_step():
    """
    explicitly test to make sure windages are being updated for persistence
    != 0 and windages are not being changed for persistance == -1
    """
    time_step = 15 * 60  # seconds
    model_time = datetime(2012, 8, 20, 13)  # yyyy/month/day/hr/min/sec
    sc = sample_sc_release(5, (3., 6., 0.), model_time)
    sc['windage_persist'][:2] = -1
    wind = Wind(timeseries=np.array((model_time, (2., 25.)),
                                    dtype=datetime_value_2d).reshape(1),
                units='meter per second')

    wm = WindMover(wind)
    wm.prepare_for_model_run()

    for ix in range(2):
        curr_time = sec_to_date(date_to_sec(model_time) + time_step * ix)
        old_windages = np.copy(sc['windages'])
        wm.prepare_for_model_step(sc, time_step, curr_time)

        mask = [sc['windage_persist'] == -1]
        assert np.all(sc['windages'][mask] == old_windages[mask])

        mask = [sc['windage_persist'] > 0]
        assert np.all(sc['windages'][mask] != old_windages[mask])
Exemplo n.º 9
0
def test_exceptions():
    """
    Test ValueError exception thrown if improper input arguments
    """
    with raises(ReferencedObjectNotSet) as excinfo:
        wm = WindMover()
        wm.prepare_for_model_run()
    print excinfo.value.message

    with raises(TypeError):
        """
        violates duck typing so may want to remove. Though current WindMover's
        backend cython object looks for C++ OSSM object which is embedded in
        Wind object which is why this check was enforced. Can be
        re-evaluated if there is a need.
        """
        WindMover(wind=10)
Exemplo n.º 10
0
def test_exceptions():
    """
    Test ValueError exception thrown if improper input arguments
    """
    with raises(ReferencedObjectNotSet) as excinfo:
        wm = WindMover()
        wm.prepare_for_model_run()
    print excinfo.value.message

    with raises(TypeError):
        """
        violates duck typing so may want to remove. Though current WindMover's
        backend cython object looks for C++ OSSM object which is embedded in
        Wind object which is why this check was enforced. Can be
        re-evaluated if there is a need.
        """
        WindMover(wind=10)
Exemplo n.º 11
0
def test_timespan():
    """
    Ensure the active flag is being set correctly and checked,
    such that if active=False, the delta produced by get_move = 0
    """
    time_step = 15 * 60  # seconds

    start_pos = (3., 6., 0.)
    rel_time = datetime(2012, 8, 20, 13)  # yyyy/month/day/hr/min/sec

    sc = sample_sc_release(5, start_pos, rel_time)

    # value is given as (r,theta)
    model_time = rel_time
    time_val = np.zeros((1, ), dtype=datetime_value_2d)
    time_val['time'] = rel_time
    time_val['value'] = (2., 25.)

    wm = WindMover(Wind(timeseries=time_val,
                        units='meter per second'),
                   active_range=(model_time + timedelta(seconds=time_step),
                                 InfDateTime('inf')))

    wm.prepare_for_model_run()
    wm.prepare_for_model_step(sc, time_step, model_time)

    delta = wm.get_move(sc, time_step, model_time)
    wm.model_step_is_done()

    assert wm.active is False
    assert np.all(delta == 0)  # model_time + time_step = active_start

    wm.active_range = (model_time - timedelta(seconds=time_step / 2),
                       InfDateTime('inf'))
    wm.prepare_for_model_step(sc, time_step, model_time)

    delta = wm.get_move(sc, time_step, model_time)
    wm.model_step_is_done()

    assert wm.active is True
    print '''\ntest_timespan delta \n{0}'''.format(delta)
    assert np.all(delta[:, :2] != 0)  # model_time + time_step > active_start
Exemplo n.º 12
0
    def test_variable_wind_after_model_time_with_extrapolation(self):
        '''
            test to make sure the wind mover is behaving properly with
            out-of-bounds winds.
            A variable wind can extrapolate if it is configured to do so,
            so prepare_for_model_step() should succeed in this case.

            We are testing that the wind extrapolates properly, so the
            windages should be updated in the same way as the in-bounds test
        '''
        wind_time = datetime(2012, 8, 21, 13)  # one day after model time

        time_series = (np.zeros((3, ), dtype=datetime_value_2d)
                       .view(dtype=np.recarray))
        time_series.time = [sec_to_date(date_to_sec(wind_time) +
                                        self.time_step * i)
                            for i in range(3)]
        time_series.value = np.array(((2., 25.), (2., 25.), (2., 25.)))

        wind = Wind(timeseries=time_series.reshape(3),
                    extrapolation_is_allowed=True,
                    units='meter per second')

        wm = WindMover(wind)
        wm.prepare_for_model_run()

        for ix in range(2):
            curr_time = sec_to_date(date_to_sec(self.model_time) +
                                    self.time_step * ix)

            old_windages = np.copy(self.sc['windages'])
            wm.prepare_for_model_step(self.sc, self.time_step, curr_time)

            mask = self.sc['windage_persist'] == -1
            assert np.all(self.sc['windages'][mask] == old_windages[mask])

            mask = self.sc['windage_persist'] > 0
            assert np.all(self.sc['windages'][mask] != old_windages[mask])
Exemplo n.º 13
0
    def test_variable_wind_after_model_time_with_extrapolation(self):
        '''
            test to make sure the wind mover is behaving properly with
            out-of-bounds winds.
            A variable wind can extrapolate if it is configured to do so,
            so prepare_for_model_step() should succeed in this case.

            We are testing that the wind extrapolates properly, so the
            windages should be updated in the same way as the in-bounds test
        '''
        wind_time = datetime(2012, 8, 21, 13)  # one day after model time

        time_series = (np.zeros((3, ), dtype=datetime_value_2d)
                       .view(dtype=np.recarray))
        time_series.time = [sec_to_date(date_to_sec(wind_time) +
                                        self.time_step * i)
                            for i in range(3)]
        time_series.value = np.array(((2., 25.), (2., 25.), (2., 25.)))

        wind = Wind(timeseries=time_series.reshape(3),
                    extrapolation_is_allowed=True,
                    units='meter per second')

        wm = WindMover(wind)
        wm.prepare_for_model_run()

        for ix in range(2):
            curr_time = sec_to_date(date_to_sec(self.model_time) +
                                    self.time_step * ix)

            old_windages = np.copy(self.sc['windages'])
            wm.prepare_for_model_step(self.sc, self.time_step, curr_time)

            mask = self.sc['windage_persist'] == -1
            assert np.all(self.sc['windages'][mask] == old_windages[mask])

            mask = self.sc['windage_persist'] > 0
            assert np.all(self.sc['windages'][mask] != old_windages[mask])
Exemplo n.º 14
0
    def test_windages_updated(self):
        '''
            explicitly test to make sure:
            - windages are being updated for persistence != 0 and
            - windages are not being changed for persistance == -1
        '''
        wind = Wind(timeseries=np.array((self.model_time, (2., 25.)),
                                        dtype=datetime_value_2d).reshape(1),
                    units='meter per second')

        wm = WindMover(wind)
        wm.prepare_for_model_run()

        for ix in range(2):
            curr_time = sec_to_date(date_to_sec(self.model_time) +
                                    self.time_step * ix)
            old_windages = np.copy(self.sc['windages'])
            wm.prepare_for_model_step(self.sc, self.time_step, curr_time)

            mask = self.sc['windage_persist'] == -1
            assert np.all(self.sc['windages'][mask] == old_windages[mask])

            mask = self.sc['windage_persist'] > 0
            assert np.all(self.sc['windages'][mask] != old_windages[mask])
Exemplo n.º 15
0
    def test_windages_updated(self):
        '''
            explicitly test to make sure:
            - windages are being updated for persistence != 0 and
            - windages are not being changed for persistance == -1
        '''
        wind = Wind(timeseries=np.array((self.model_time, (2., 25.)),
                                        dtype=datetime_value_2d).reshape(1),
                    units='meter per second')

        wm = WindMover(wind)
        wm.prepare_for_model_run()

        for ix in range(2):
            curr_time = sec_to_date(date_to_sec(self.model_time) +
                                    self.time_step * ix)
            old_windages = np.copy(self.sc['windages'])
            wm.prepare_for_model_step(self.sc, self.time_step, curr_time)

            mask = self.sc['windage_persist'] == -1
            assert np.all(self.sc['windages'][mask] == old_windages[mask])

            mask = self.sc['windage_persist'] > 0
            assert np.all(self.sc['windages'][mask] != old_windages[mask])