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


Python Model.start_time方法代码示例

本文整理汇总了Python中gnome.model.Model.start_time方法的典型用法代码示例。如果您正苦于以下问题:Python Model.start_time方法的具体用法?Python Model.start_time怎么用?Python Model.start_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gnome.model.Model的用法示例。


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

示例1: test_start_time

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_start_time():
    model = Model()

    st = datetime.now()
    model.start_time = st
    assert model.start_time == st
    assert model.current_time_step == -1

    model.step()

    st = datetime(2012, 8, 12, 13)
    model.start_time = st

    assert model.current_time_step == -1
    assert model.start_time == st
开发者ID:sandhujasmine,项目名称:PyGnome,代码行数:17,代码来源:test_model.py

示例2: test_simple_run_with_map

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_simple_run_with_map():
    '''
    pretty much all this tests is that the model will run
    '''

    start_time = datetime(2012, 9, 15, 12, 0)

    model = Model()

    model.map = gnome.map.MapFromBNA(testmap, refloat_halflife=6)  # hours
    a_mover = SimpleMover(velocity=(1., 2., 0.))

    model.movers += a_mover
    assert len(model.movers) == 1

    spill = point_line_release_spill(num_elements=10,
                                     start_position=(0., 0., 0.),
                                     release_time=start_time)

    model.spills += spill
    assert len(model.spills) == 1
    model.start_time = spill.release.release_time

    # test iterator
    for step in model:
        print 'just ran time step: %s' % step
        assert step['step_num'] == model.current_time_step

    # reset and run again
    model.reset()

    # test iterator is repeatable
    for step in model:
        print 'just ran time step: %s' % step
        assert step['step_num'] == model.current_time_step
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:37,代码来源:test_model.py

示例3: test_simple_run_with_image_output_uncertainty

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_simple_run_with_image_output_uncertainty(tmpdir):
    '''
    Pretty much all this tests is that the model will run and output images
    '''
    images_dir = tmpdir.mkdir('Test_images2').strpath

    if os.path.isdir(images_dir):
        shutil.rmtree(images_dir)
    os.mkdir(images_dir)

    start_time = datetime(2012, 9, 15, 12, 0)

    # the land-water map
    gmap = gnome.map.MapFromBNA(testdata['MapFromBNA']['testmap'],
                                refloat_halflife=6)  # hours
    renderer = gnome.outputters.Renderer(testdata['MapFromBNA']['testmap'],
                                         images_dir, size=(400, 300))

    model = Model(start_time=start_time,
                  time_step=timedelta(minutes=15), duration=timedelta(hours=1),
                  map=gmap,
                  uncertain=True, cache_enabled=False,
                  )

    model.outputters += renderer
    a_mover = SimpleMover(velocity=(1., -1., 0.))
    model.movers += a_mover

    N = 10  # a line of ten points
    start_points = np.zeros((N, 3), dtype=np.float64)
    start_points[:, 0] = np.linspace(-127.1, -126.5, N)
    start_points[:, 1] = np.linspace(47.93, 48.1, N)
    # print start_points

    release = SpatialRelease(start_position=start_points,
                             release_time=start_time)

    model.spills += Spill(release)

    # model.add_spill(spill)

    model.start_time = release.release_time

    # image_info = model.next_image()

    model.uncertain = True
    num_steps_output = 0
    while True:
        try:
            image_info = model.step()
            num_steps_output += 1
            print image_info
        except StopIteration:
            print 'Done with the model run'
            break

    # there is the zeroth step, too.
    calculated_steps = (model.duration.total_seconds() / model.time_step) + 1
    assert num_steps_output == calculated_steps
开发者ID:sandhujasmine,项目名称:PyGnome,代码行数:61,代码来源:test_model.py

示例4: test_mover_api

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_mover_api():
    '''
    Test the API methods for adding and removing movers to the model.
    '''
    start_time = datetime(2012, 1, 1, 0, 0)

    model = Model()
    model.duration = timedelta(hours=12)
    model.time_step = timedelta(hours=1)
    model.start_time = start_time

    mover_1 = SimpleMover(velocity=(1., -1., 0.))
    mover_2 = SimpleMover(velocity=(1., -1., 0.))
    mover_3 = SimpleMover(velocity=(1., -1., 0.))
    mover_4 = SimpleMover(velocity=(1., -1., 0.))

    # test our add object methods

    model.movers += mover_1
    model.movers += mover_2

    # test our get object methods

    assert model.movers[mover_1.id] == mover_1
    assert model.movers[mover_2.id] == mover_2
    with raises(KeyError):
        temp = model.movers['Invalid']
        print temp

    # test our iter and len object methods
    assert len(model.movers) == 2
    assert len([m for m in model.movers]) == 2
    for (m1, m2) in zip(model.movers, [mover_1, mover_2]):
        assert m1 == m2

    # test our add objectlist methods
    model.movers += [mover_3, mover_4]
    assert [m for m in model.movers] == [mover_1, mover_2, mover_3, mover_4]

    # test our remove object methods
    del model.movers[mover_3.id]
    assert [m for m in model.movers] == [mover_1, mover_2, mover_4]

    with raises(KeyError):
        # our key should also be gone after the delete
        temp = model.movers[mover_3.id]
        print temp

    # test our replace method
    model.movers[mover_2.id] = mover_3
    assert [m for m in model.movers] == [mover_1, mover_3, mover_4]
    assert model.movers[mover_3.id] == mover_3

    with raises(KeyError):
        # our key should also be gone after the delete
        temp = model.movers[mover_2.id]
        print temp
开发者ID:sandhujasmine,项目名称:PyGnome,代码行数:59,代码来源:test_model.py

示例5: test_callback_add_mover

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_callback_add_mover():
    'Test callback after add mover'
    units = 'meter per second'

    model = Model()
    model.start_time = datetime(2012, 1, 1, 0, 0)
    model.duration = timedelta(hours=10)
    model.time_step = timedelta(hours=1)

    # start_loc = (1.0, 2.0, 0.0)  # random non-zero starting points

    # add Movers
    model.movers += SimpleMover(velocity=(1., -1., 0.))
    series = np.array((model.start_time, (10, 45)),
                      dtype=datetime_value_2d).reshape((1, ))
    model.movers += WindMover(Wind(timeseries=series, units=units))

    # this should create a Wind object
    new_wind = Wind(timeseries=series, units=units)
    model.environment += new_wind
    assert new_wind in model.environment
    assert len(model.environment) == 2

    tide_file = get_datafile(os.path.join(tides_dir, 'CLISShio.txt'))
    tide_ = Tide(filename=tide_file)

    d_file = get_datafile(os.path.join(lis_dir, 'tidesWAC.CUR'))
    model.movers += CatsMover(d_file, tide=tide_)

    model.movers += CatsMover(d_file)

    for mover in model.movers:
        assert mover.active_start == inf_datetime.InfDateTime('-inf')
        assert mover.active_stop == inf_datetime.InfDateTime('inf')

        if hasattr(mover, 'wind'):
            assert mover.wind in model.environment

        if hasattr(mover, 'tide'):
            if mover.tide is not None:
                assert mover.tide in model.environment

    # Add a mover with user defined active_start / active_stop values
    # - these should not be updated

    active_on = model.start_time + timedelta(hours=1)
    active_off = model.start_time + timedelta(hours=4)
    custom_mover = SimpleMover(velocity=(1., -1., 0.),
                               active_start=active_on,
                               active_stop=active_off)
    model.movers += custom_mover

    assert model.movers[custom_mover.id].active_start == active_on
    assert model.movers[custom_mover.id].active_stop == active_off
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:56,代码来源:test_model.py

示例6: test_callback_add_mover

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_callback_add_mover():
    """ Test callback after add mover """

    units = 'meter per second'

    model = Model()
    model.time_step = timedelta(hours=1)
    model.duration = timedelta(hours=10)
    model.start_time = datetime(2012, 1, 1, 0, 0)

    # start_loc = (1.0, 2.0, 0.0)  # random non-zero starting points

    # add Movers

    model.movers += SimpleMover(velocity=(1., -1., 0.))
    series = np.array((model.start_time, (10, 45)),
                      dtype=datetime_value_2d).reshape((1, ))
    model.movers += WindMover(Wind(timeseries=series, units=units))

    tide_file = get_datafile(os.path.join(os.path.dirname(__file__),
                             r"sample_data", 'tides', 'CLISShio.txt'))
    tide_ = Tide(filename=tide_file)

    d_file = get_datafile(os.path.join(datadir,
                          r"long_island_sound/tidesWAC.CUR"))
    model.movers += CatsMover(d_file, tide=tide_)

    model.movers += CatsMover(d_file)

    for mover in model.movers:
        assert mover.active_start == inf_datetime.InfDateTime('-inf')
        assert mover.active_stop == inf_datetime.InfDateTime('inf')

        if isinstance(mover, WindMover):
            assert mover.wind.id in model.environment

        if isinstance(mover, CatsMover):
            if mover.tide is not None:
                assert mover.tide.id in model.environment

    # Add a mover with user defined active_start / active_stop values
    # - these should not be updated

    active_on = model.start_time + timedelta(hours=1)
    active_off = model.start_time + timedelta(hours=4)
    custom_mover = SimpleMover(velocity=(1., -1., 0.),
                               active_start=active_on,
                               active_stop=active_off)
    model.movers += custom_mover

    assert model.movers[custom_mover.id].active_start == active_on
    assert model.movers[custom_mover.id].active_stop == active_off
开发者ID:JamesMakela,项目名称:GNOME2,代码行数:54,代码来源:test_model.py

示例7: test_model_time_and_current_time_in_sc

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_model_time_and_current_time_in_sc():
    model = Model()
    model.start_time = datetime.now()

    assert model.current_time_step == -1
    assert model.model_time == model.start_time

    for step in range(4):
        model.step()

        assert model.current_time_step == step
        assert (model.model_time ==
                model.start_time + timedelta(seconds=step * model.time_step))

        for sc in model.spills.items():
            assert model.model_time == sc.current_time_stamp
开发者ID:sandhujasmine,项目名称:PyGnome,代码行数:18,代码来源:test_model.py

示例8: test_simple_run_rewind

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_simple_run_rewind():
    '''
    Pretty much all this tests is that the model will run
    and the seed is set during first run, then set correctly
    after it is rewound and run again
    '''

    start_time = datetime(2012, 9, 15, 12, 0)

    model = Model()

    model.map = gnome.map.GnomeMap()
    a_mover = SimpleMover(velocity=(1., 2., 0.))

    model.movers += a_mover
    assert len(model.movers) == 1

    spill = point_line_release_spill(num_elements=10,
                                     start_position=(0., 0., 0.),
                                     release_time=start_time)

    model.spills += spill
    assert len(model.spills) == 1

    # model.add_spill(spill)

    model.start_time = spill.release.release_time

    # test iterator
    for step in model:
        print 'just ran time step: %s' % model.current_time_step
        assert step['step_num'] == model.current_time_step

    pos = np.copy(model.spills.LE('positions'))

    # rewind and run again:
    print 'rewinding'
    model.rewind()

    # test iterator is repeatable
    for step in model:
        print 'just ran time step: %s' % model.current_time_step
        assert step['step_num'] == model.current_time_step

    assert np.all(model.spills.LE('positions') == pos)
开发者ID:sandhujasmine,项目名称:PyGnome,代码行数:47,代码来源:test_model.py

示例9: test_callback_add_mover_midrun

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_callback_add_mover_midrun():
    'Test callback after add mover called midway through the run'
    model = Model()
    model.start_time = datetime(2012, 1, 1, 0, 0)
    model.duration = timedelta(hours=10)
    model.time_step = timedelta(hours=1)

    # start_loc = (1.0, 2.0, 0.0)  # random non-zero starting points

    # model = setup_simple_model()

    for i in range(2):
        model.step()

    assert model.current_time_step > -1

    # now add another mover and make sure model rewinds
    model.movers += SimpleMover(velocity=(2., -2., 0.))
    assert model.current_time_step == -1
开发者ID:sandhujasmine,项目名称:PyGnome,代码行数:21,代码来源:test_model.py

示例10: test_simple_run_with_map

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_simple_run_with_map():
    """
    pretty much all this tests is that the model will run
    """

    start_time = datetime(2012, 9, 15, 12, 0)

    model = Model()

    model.map = gnome.map.MapFromBNA(testmap, refloat_halflife=6)  # hours
    a_mover = SimpleMover(velocity=(1., 2., 0.))

    model.movers += a_mover
    assert len(model.movers) == 1

    spill = PointLineSource(num_elements=10,
            start_position=(0., 0., 0.), release_time=start_time)

    model.spills += spill

    # model.add_spill(spill)

    assert len(model.spills) == 1
    model.start_time = spill.release_time

    # test iterator:

    for step in model:
        print 'just ran time step: %s' % step

    # reset and run again:

    model.reset()

    # test iterator:

    for step in model:
        print 'just ran time step: %s' % step

    assert True
开发者ID:JamesMakela,项目名称:GNOME2,代码行数:42,代码来源:test_model.py

示例11: test_linearity_of_wind_movers

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [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
开发者ID:sandhujasmine,项目名称:PyGnome,代码行数:91,代码来源:test_model.py

示例12: test_all_movers

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_all_movers(start_time, release_delay, duration):
    '''
    Tests that all the movers at least can be run

    Add new ones as they come along!
    '''

    model = Model()
    model.time_step = timedelta(hours=1)
    model.duration = timedelta(seconds=model.time_step * duration)
    model.start_time = start_time
    start_loc = (1., 2., 0.)  # random non-zero starting points

    # a spill - release after 5 timesteps

    release_time = (start_time +
                    timedelta(seconds=model.time_step * release_delay))
    model.spills += point_line_release_spill(num_elements=10,
                                             start_position=start_loc,
                                             release_time=release_time)

    # the land-water map
    model.map = gnome.map.GnomeMap()  # the simplest of maps

    # simple mover
    model.movers += SimpleMover(velocity=(1., -1., 0.))
    assert len(model.movers) == 1

    # random mover
    model.movers += RandomMover(diffusion_coef=100000)
    assert len(model.movers) == 2

    # wind mover
    series = np.array((start_time, (10, 45)),
                      dtype=datetime_value_2d).reshape((1, ))
    model.movers += WindMover(Wind(timeseries=series,
                              units='meter per second'))
    assert len(model.movers) == 3

    # CATS mover
    model.movers += CatsMover(testdata['CatsMover']['curr'])
    assert len(model.movers) == 4

    # run the model all the way...
    num_steps_output = 0
    for step in model:
        num_steps_output += 1
        print 'running step:', step

    # test release happens correctly for all cases
    if release_delay < duration:
        # at least one get_move has been called after release
        assert np.all(model.spills.LE('positions')[:, :2] != start_loc[:2])
    elif release_delay == duration:
        # particles are released after last step so no motion,
        # only initial _state
        assert np.all(model.spills.LE('positions') == start_loc)
    else:
        # release_delay > duration so nothing released though model ran
        assert len(model.spills.LE('positions')) == 0

    # there is the zeroth step, too.
    calculated_steps = (model.duration.total_seconds() / model.time_step) + 1
    assert num_steps_output == calculated_steps
开发者ID:sandhujasmine,项目名称:PyGnome,代码行数:66,代码来源:test_model.py

示例13: test_simple_run_with_image_output_uncertainty

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import start_time [as 别名]
def test_simple_run_with_image_output_uncertainty():
    """
    pretty much all this tests is that the model will run and output images
    """

    # create a place for test images (cleaning out any old ones)

    images_dir = os.path.join(basedir, 'Test_images2')
    if os.path.isdir(images_dir):
        shutil.rmtree(images_dir)
    os.mkdir(images_dir)

    start_time = datetime(2012, 9, 15, 12, 0)

    # the land-water map

    gmap = gnome.map.MapFromBNA(testmap, refloat_halflife=6)  # hours
    renderer = gnome.renderer.Renderer(testmap, images_dir, size=(400,
            300))

    model = Model(
        time_step=timedelta(minutes=15),
        start_time=start_time,
        duration=timedelta(hours=1),
        map=gmap,
        uncertain=True,
        cache_enabled=False,
        )

    model.outputters += renderer
    a_mover = SimpleMover(velocity=(1., -1., 0.))
    model.movers += a_mover

    N = 10  # a line of ten points
    start_points = np.zeros((N, 3), dtype=np.float64)
    start_points[:, 0] = np.linspace(-127.1, -126.5, N)
    start_points[:, 1] = np.linspace(47.93, 48.1, N)

    # print start_points

    spill = SpatialRelease(start_positions=start_points,
                           release_time=start_time)

    model.spills += spill

    # model.add_spill(spill)

    model.start_time = spill.release_time

    # image_info = model.next_image()

    model.uncertain = True

    num_steps_output = 0
    while True:
        try:
            image_info = model.step()
            num_steps_output += 1
            print image_info
        except StopIteration:
            print 'Done with the model run'
            break

    # there is the zeroth step, too.

    assert num_steps_output == model.duration.total_seconds() \
        / model.time_step + 1
开发者ID:JamesMakela,项目名称:GNOME2,代码行数:69,代码来源:test_model.py


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