本文整理汇总了Python中gnome.movers.WindMover.prepare_for_model_run方法的典型用法代码示例。如果您正苦于以下问题:Python WindMover.prepare_for_model_run方法的具体用法?Python WindMover.prepare_for_model_run怎么用?Python WindMover.prepare_for_model_run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnome.movers.WindMover
的用法示例。
在下文中一共展示了WindMover.prepare_for_model_run方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_active
# 需要导入模块: from gnome.movers import WindMover [as 别名]
# 或者: from gnome.movers.WindMover import prepare_for_model_run [as 别名]
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
示例2: test_prepare_for_model_step
# 需要导入模块: from gnome.movers import WindMover [as 别名]
# 或者: from gnome.movers.WindMover import prepare_for_model_run [as 别名]
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])
示例3: test_variable_wind_after_model_time
# 需要导入模块: from gnome.movers import WindMover [as 别名]
# 或者: from gnome.movers.WindMover import prepare_for_model_run [as 别名]
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)
示例4: test_constant_wind_after_model_time
# 需要导入模块: from gnome.movers import WindMover [as 别名]
# 或者: from gnome.movers.WindMover import prepare_for_model_run [as 别名]
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])
示例5: test_exceptions
# 需要导入模块: from gnome.movers import WindMover [as 别名]
# 或者: from gnome.movers.WindMover import prepare_for_model_run [as 别名]
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)
示例6: test_timespan
# 需要导入模块: from gnome.movers import WindMover [as 别名]
# 或者: from gnome.movers.WindMover import prepare_for_model_run [as 别名]
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
示例7: test_variable_wind_after_model_time_with_extrapolation
# 需要导入模块: from gnome.movers import WindMover [as 别名]
# 或者: from gnome.movers.WindMover import prepare_for_model_run [as 别名]
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])
示例8: test_windages_updated
# 需要导入模块: from gnome.movers import WindMover [as 别名]
# 或者: from gnome.movers.WindMover import prepare_for_model_run [as 别名]
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])