当前位置: 首页>>代码示例>>Python>>正文


Python movers.WindMover类代码示例

本文整理汇总了Python中gnome.movers.WindMover的典型用法代码示例。如果您正苦于以下问题:Python WindMover类的具体用法?Python WindMover怎么用?Python WindMover使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WindMover类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_prepare_for_model_step

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])
开发者ID:,项目名称:,代码行数:26,代码来源:

示例2: test_constant_wind_after_model_time

    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])
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:32,代码来源:test_wind_mover.py

示例3: test_variable_wind_after_model_time

    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)
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:29,代码来源:test_wind_mover.py

示例4: test_empty_init

def test_empty_init():
    '''
    wind=None
    '''
    wm = WindMover()
    assert wm.make_default_refs
    _defaults(wm)
    assert wm.name == 'WindMover'
    print wm.validate()
开发者ID:,项目名称:,代码行数:9,代码来源:

示例5: test_exception_new_from_dict

def test_exception_new_from_dict():

    # WindMover does not modify Wind object!

    wm = WindMover(environment.Wind(filename=file_))

    wm_state = wm.to_dict('create')
    wm_state.update({'wind': environment.Wind(filename=file_)})

    with pytest.raises(ValueError):
        WindMover.new_from_dict(wm_state)
开发者ID:JamesMakela,项目名称:GNOME2,代码行数:11,代码来源:test_wind_mover.py

示例6: test_serialize_deserialize

def test_serialize_deserialize(wind_circ):
    """
    tests and illustrate the funcitonality of serialize/deserialize for
    WindMover.
    """
    wind = Wind(filename=file_)
    wm = WindMover(wind)
    serial = wm.serialize()
    assert 'wind' in serial

    wm2 = wm.deserialize(serial)

    assert wm == wm2
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:13,代码来源:test_wind_mover.py

示例7: test_active

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
开发者ID:JamesMakela,项目名称:GNOME2,代码行数:25,代码来源:test_wind_mover.py

示例8: test_properties

def test_properties(wind_circ):
    """
    test setting the properties of the object
    """
    wm = WindMover(wind_circ['wind'])

    wm.uncertain_duration = 1
    wm.uncertain_time_delay = 2
    wm.uncertain_speed_scale = 3
    wm.uncertain_angle_scale = 4

    assert wm.uncertain_duration == 1
    assert wm.uncertain_time_delay == 2
    assert wm.uncertain_speed_scale == 3
    assert wm.uncertain_angle_scale == 4
开发者ID:,项目名称:,代码行数:15,代码来源:

示例9: test_serialize_deserialize

def test_serialize_deserialize(wind_circ):
    """
    tests and illustrate the funcitonality of serialize/deserialize for
    WindMover.
    """
    wind = Wind(filename=file_)
    wm = WindMover(wind)
    serial = wm.serialize('webapi')
    assert 'wind' in serial

    dict_ = wm.deserialize(serial)
    dict_['wind'] = wind_circ['wind']
    wm.update_from_dict(dict_)

    assert wm.wind == wind_circ['wind']
开发者ID:,项目名称:,代码行数:15,代码来源:

示例10: test_exceptions

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)
开发者ID:,项目名称:,代码行数:17,代码来源:

示例11: test_properties

def test_properties(wind_circ):
    """
    test setting the properties of the object
    """
    wm = WindMover(wind_circ['wind'])

    wm.uncertain_duration = 1
    wm.uncertain_time_delay = 2
    wm.uncertain_speed_scale = 3
    wm.uncertain_angle_scale = 4

    assert wm.uncertain_duration == 1
    assert wm.uncertain_time_delay == 2
    assert wm.uncertain_speed_scale == 3
    assert wm.uncertain_angle_scale == 4
    assert wm.data_start == datetime(2012, 11, 6, 20, 10)
    assert wm.data_stop == datetime(2012, 11, 6, 20, 15)
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:17,代码来源:test_wind_mover.py

示例12: test_serialize_deserialize

def test_serialize_deserialize(wind_circ, do):
    """
    tests and illustrates the funcitonality of serialize/deserialize for
    WindMover.
    """
    wind = environment.Wind(filename=file_)
    wm = WindMover(wind)
    json_ = wm.serialize(do)
    if do == 'create':
        assert 'wind' not in json_

        # reference to 'wind' object is made by the Model().save() function
        # by default 'wind' object is not serialized in 'create' mode
        # so for this test to work, add the 'wind' key, value back in before
        # constructing new WindMover. In the real use case, the model does this
        dict_ = wm.deserialize(json_)
        dict_['wind'] = wind
        wm2 = WindMover.new_from_dict(dict_)
        assert wm == wm2

    else:
        assert 'wind' in json_

        wind_update = wind_circ['wind']
        json_['wind'] = wind_update.serialize(do)
        dict_ = wm.deserialize(json_)
        wm.from_dict(dict_)

        assert wm.wind == wind_update
开发者ID:kthyng,项目名称:GNOME2,代码行数:29,代码来源:test_wind_mover.py

示例13: test_new_from_dict

def test_new_from_dict():
    """
    Currently only checks that new object can be created from dict
    It does not check equality of objects
    """

    wind = environment.Wind(filename=file_)
    wm = WindMover(wind)  # WindMover does not modify Wind object!
    wm_state = wm.to_dict('create')

    # must create a Wind object and add this to wm_state dict

    wind2 = environment.Wind.new_from_dict(wind.to_dict('create'))
    wm_state.update({'wind': wind2})
    wm2 = WindMover.new_from_dict(wm_state)

    assert wm is not wm2
    assert wm.wind is not wm2.wind
    assert wm == wm2
开发者ID:kthyng,项目名称:GNOME2,代码行数:19,代码来源:test_wind_mover.py

示例14: test_wind_mover

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
开发者ID:,项目名称:,代码行数:44,代码来源:

示例15: test_new_from_dict

def test_new_from_dict():
    """
    Currently only checks that new object can be created from dict
    It does not check equality of objects
    """

    wind = environment.Wind(filename=file_)
    wm = WindMover(wind)  # WindMover does not modify Wind object!
    wm_state = wm.to_dict('create')

    # must create a Wind object and add this to wm_state dict

    wind2 = environment.Wind.new_from_dict(wind.to_dict('create'))
    wm_state.update({'wind': wind2})
    wm2 = WindMover.new_from_dict(wm_state)

    # check serializable state is correct

    assert all([wm.__getattribute__(k) == wm2.__getattribute__(k)
               for k in WindMover.state.get_names('create') if k
               != 'wind_id' and k != 'obj_type'])
    assert wm.wind.id == wm2.wind.id
开发者ID:JamesMakela,项目名称:GNOME2,代码行数:22,代码来源:test_wind_mover.py


注:本文中的gnome.movers.WindMover类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。