本文整理汇总了Python中gnome.model.Model.next方法的典型用法代码示例。如果您正苦于以下问题:Python Model.next方法的具体用法?Python Model.next怎么用?Python Model.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnome.model.Model
的用法示例。
在下文中一共展示了Model.next方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_linearity_of_wind_movers
# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import next [as 别名]
def test_linearity_of_wind_movers(wind_persist):
'''
WindMover is defined as a linear operation - defining a model
with a single WindMover with 15 knot wind is equivalent to defining
a model with three WindMovers each with 5 knot wind. Or any number of
WindMover's such that the sum of their magnitude is 15knots and the
direction of wind is the same for both cases.
Below is an example which defines two models and runs them.
In model2, there are multiple winds defined so the windage parameter
is reset 3 times for one timestep.
Since windage range and persistence do not change, this only has the effect
of doing the same computation 3 times. However, the results are the same.
The mean and variance of the positions for both models are close.
As windage_persist is decreased, the values become closer.
Setting windage_persist=0 gives the large difference between them.
'''
units = 'meter per second'
start_time = datetime(2012, 1, 1, 0, 0)
series1 = np.array((start_time, (15, 45)),
dtype=datetime_value_2d).reshape((1, ))
series2 = np.array((start_time, (6, 45)),
dtype=datetime_value_2d).reshape((1, ))
series3 = np.array((start_time, (3, 45)),
dtype=datetime_value_2d).reshape((1, ))
num_LEs = 1000
element_type = floating(windage_persist=wind_persist)
model1 = Model(name='model1')
model1.duration = timedelta(hours=1)
model1.time_step = timedelta(hours=1)
model1.start_time = start_time
model1.spills += point_line_release_spill(num_elements=num_LEs,
start_position=(1., 2., 0.),
release_time=start_time,
element_type=element_type)
model1.movers += WindMover(Wind(timeseries=series1, units=units),
make_default_refs=False)
model2 = Model(name='model2')
model2.duration = timedelta(hours=10)
model2.time_step = timedelta(hours=1)
model2.start_time = start_time
model2.spills += point_line_release_spill(num_elements=num_LEs,
start_position=(1., 2., 0.),
release_time=start_time,
element_type=element_type)
# todo: CHECK RANDOM SEED
# model2.movers += WindMover(Wind(timeseries=series1, units=units))
model2.movers += WindMover(Wind(timeseries=series2, units=units))
model2.movers += WindMover(Wind(timeseries=series2, units=units))
model2.movers += WindMover(Wind(timeseries=series3, units=units))
model2.set_make_default_refs(False)
while True:
try:
model1.next()
except StopIteration as ex:
# print message
print ex.message
break
while True:
try:
model2.next()
except StopIteration as ex:
# print message
print ex.message
break
# mean and variance at the end should be fairly close
# look at the mean of the position vector. Assume m1 is truth
# and m2 is approximation - look at the absolute error between
# mean position of m2 in the 2 norm.
# rel_mean_error =(np.linalg.norm(np.mean(model2.spills.LE('positions'), 0)
# - np.mean(model1.spills.LE('positions'), 0)))
# assert rel_mean_error <= 0.5
# Similarly look at absolute error in variance of position of m2
# in the 2 norm.
rel_var_error = np.linalg.norm(np.var(model2.spills.LE('positions'), 0) -
np.var(model1.spills.LE('positions'), 0))
assert rel_var_error <= 0.0015