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


Python Model.step方法代码示例

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


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

示例1: test_ice_image_mid_run

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [as 别名]
def test_ice_image_mid_run():
    """
        Test image outputter with a model
        NOTE: could it be tested with just a mover, and not a full model?
          -- that gets tricky with the cache and timesteps...
    """
    start_time = datetime(2015, 5, 14, 0)
    model = Model(time_step=3600 * 24, start_time=start_time, duration=timedelta(days=3))  # one day
    model.cache_enabled = False
    model.uncertain = False

    c_ice_mover = IceMover(curr_file, topology_file)
    model.movers += c_ice_mover

    # run the model a couple steps
    step = model.step()
    step = model.step()

    # now add the outputter
    model.outputters += IceImageOutput(c_ice_mover, viewport=((-175.0, 65.0), (-145.0, 75.05)))

    # and run some more:
    step = model.step()
    step = model.step()

    # and check the output
    ice_output = step["IceImageOutput"]

    for key in ("time_stamp", "thickness_image", "concentration_image", "bounding_box", "projection"):
        assert key in ice_output

        print "thickness img size:", len(ice_output["thickness_image"])
        print "concentration img size:", len(ice_output["concentration_image"])
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:35,代码来源:test_ice_image_outputter.py

示例2: test_simple_run_with_image_output

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [as 别名]
def test_simple_run_with_image_output(tmpdir):
    '''
    Pretty much all this tests is that the model will run and output images
    '''
    images_dir = tmpdir.mkdir('Test_images').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
    gnome_map = gnome.map.MapFromBNA(testdata['MapFromBNA']['testmap'],
                                     refloat_halflife=6)  # hours
    renderer = gnome.outputters.Renderer(testdata['MapFromBNA']['testmap'],
                                         images_dir, size=(400, 300))
    geo_json = TrajectoryGeoJsonOutput(output_dir=images_dir)

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

    model.outputters += renderer
    model.outputters += geo_json

    a_mover = SimpleMover(velocity=(1., -1., 0.))
    model.movers += a_mover
    assert len(model.movers) == 1

    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 = Spill(SpatialRelease(start_position=start_points,
                                 release_time=start_time))

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

    model.start_time = spill.release.release_time

    # image_info = model.next_image()
    num_steps_output = 0
    while True:
        try:
            model.step()
            num_steps_output += 1
        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,代码行数:60,代码来源:test_model.py

示例3: test_weathering_data_attr

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [as 别名]
def test_weathering_data_attr():
    '''
    mass_balance is initialized/written if we have weatherers
    '''
    ts = 900
    s1_rel = datetime.now().replace(microsecond=0)
    s2_rel = s1_rel + timedelta(seconds=ts)
    s = [point_line_release_spill(10, (0, 0, 0), s1_rel),
         point_line_release_spill(10, (0, 0, 0), s2_rel)]

    model = Model(time_step=ts, start_time=s1_rel)
    model.spills += s
    model.step()

    for sc in model.spills.items():
        assert len(sc.mass_balance) == 2
        for key in ('beached', 'off_maps'):
            assert key in sc.mass_balance

    model.environment += [Water(), constant_wind(0., 0)]
    model.weatherers += [Evaporation(model.environment[0],
                                     model.environment[1])]

    # use different element_type and initializers for both spills
    s[0].amount = 10.0
    s[0].units = 'kg'
    model.rewind()
    model.step()

    for sc in model.spills.items():
        # since no substance is defined, all the LEs are marked as
        # nonweathering
        assert sc.mass_balance['non_weathering'] == sc['mass'].sum()
        assert sc.mass_balance['non_weathering'] == s[0].amount

    s[1].amount = 5.0
    s[1].units = 'kg'
    model.rewind()
    exp_rel = 0.0

    for ix in range(2):
        model.step()
        exp_rel += s[ix].amount
        for sc in model.spills.items():
            assert sc.mass_balance['non_weathering'] == sc['mass'].sum()
            assert sc.mass_balance['non_weathering'] == exp_rel

    model.rewind()

    assert sc.mass_balance == {}

    # weathering data is now empty for all steps
    del model.weatherers[0]

    for ix in xrange(2):
        model.step()
        for sc in model.spills.items():
            assert len(sc.mass_balance) == 2
            assert (len(set(sc.mass_balance.keys()) -
                        {'beached', 'off_maps'}) == 0)
开发者ID:sandhujasmine,项目名称:PyGnome,代码行数:62,代码来源:test_model.py

示例4: test_start_time

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [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

示例5: test_model_time_and_current_time_in_sc

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [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

示例6: test_simple_run_with_image_output_uncertainty

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [as 别名]
def test_simple_run_with_image_output_uncertainty():
    '''
    Pretty much all this tests is that the model will run and output images
    '''
    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.outputters.Renderer(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:JamesMakela-NOAA,项目名称:PyGnome,代码行数:59,代码来源:test_model.py

示例7: test_callback_add_mover_midrun

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [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

示例8: test_serialize_deserialize

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [as 别名]
def test_serialize_deserialize(json_):
    '''
    todo: this behaves in unexpected ways when using the 'model' testfixture.
    For now, define a model in here for the testing - not sure where the
    problem lies
    '''
    s_time = datetime(2014, 1, 1, 1, 1, 1)
    model = Model(start_time=s_time)
    model.spills += point_line_release_spill(num_elements=5,
        start_position=(0, 0, 0),
        release_time=model.start_time)

    o_put = NetCDFOutput(os.path.join(base_dir, u'xtemp.nc'))
    model.outputters += o_put
    model.movers += RandomMover(diffusion_coef=100000)

    #==========================================================================
    # o_put = [model.outputters[outputter.id]
    #          for outputter in model.outputters
    #          if isinstance(outputter, NetCDFOutput)][0]
    #==========================================================================

    model.rewind()
    print "step: {0}, _start_idx: {1}".format(-1, o_put._start_idx)
    for ix in range(2):
        model.step()
        print "step: {0}, _start_idx: {1}".format(ix, o_put._start_idx)

    #for json_ in ('save', 'webapi'):
    dict_ = o_put.deserialize(o_put.serialize(json_))
    o_put2 = NetCDFOutput.new_from_dict(dict_)
    if json_ == 'save':
        assert o_put == o_put2
    else:
        # _start_idx and _middle_of_run should not match
        assert o_put._start_idx != o_put2._start_idx
        assert o_put._middle_of_run != o_put2._middle_of_run
        assert o_put != o_put2

    if os.path.exists(o_put.netcdf_filename):
        print '\n{0} exists'.format(o_put.netcdf_filename)
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:43,代码来源:test_netcdf_outputter.py

示例9: test_ice_image_mid_run

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [as 别名]
def test_ice_image_mid_run():
    '''
    Test image outputter with a model 
    NOTE: could it be tested with just a mover, and not a full model?
      -- that gets tricky with the cache and timesteps...
    '''
    start_time = datetime(2015, 5, 14, 0)
    model = Model(time_step=3600*24, # one day
                  start_time=start_time,
                  duration=timedelta(days=3),)
    model.cache_enabled = False
    model.uncertain = False
    c_ice_mover = IceMover(curr_file, topology_file)
    model.movers += c_ice_mover

    ## run the model a couple steps
    step = model.step()
    step = model.step()

    ## now add the outputter
    iio = IceImageOutput(c_ice_mover)
    model.outputters += iio

    ## and run some more:

    step = model.step()
    step = model.step()
    ## and check the output
    ice_output = step['IceImageOutput']
    # print ice_output['time_stamp']
    # print ice_output['concentration_image'][:50] # could be really big!
    # print ice_output['bounding_box']
    # print ice_output['projection']
    for key in ('time_stamp',
                'thickness_image',
                'concentration_image',
                'bounding_box',
                'projection'):
        assert key in ice_output
开发者ID:liuy0813,项目名称:PyGnome,代码行数:41,代码来源:test_ice_image_outputter.py

示例10: test_release_at_right_time

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [as 别名]
def test_release_at_right_time():
    '''
    Tests that the elements get released when they should

    There are issues in that we want the elements to show
    up in the output for a given time step if they were
    supposed to be released then.  Particularly for the
    first time step of the model.
    '''
    # default to now, rounded to the nearest hour
    seconds_in_minute = 60
    minutes_in_hour = 60
    seconds_in_hour = seconds_in_minute * minutes_in_hour

    start_time = datetime(2013, 1, 1, 0)
    time_step = 2 * seconds_in_hour

    model = Model(time_step=time_step, start_time=start_time,
                  duration=timedelta(hours=12))

    # add a spill that starts right when the run begins

    model.spills += point_line_release_spill(num_elements=12,
                                             start_position=(0, 0, 0),
                                             release_time=datetime(2013,
                                                                   1, 1, 0),
                                             end_release_time=datetime(2013,
                                                                       1, 1, 6)
                                             )

    # before the run - no elements present since data_arrays get defined after
    # 1st step (prepare_for_model_run):

    assert model.spills.items()[0].num_released == 0

    model.step()
    assert model.spills.items()[0].num_released == 4

    model.step()
    assert model.spills.items()[0].num_released == 8

    model.step()
    assert model.spills.items()[0].num_released == 12

    model.step()
    assert model.spills.items()[0].num_released == 12
开发者ID:sandhujasmine,项目名称:PyGnome,代码行数:48,代码来源:test_model.py

示例11: test_make_default_refs

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [as 别名]
def test_make_default_refs():
    '''
    ensure make_default_refs is a thread-safe operation
    once object is instantiated, object.make_default_refs is an attribute of
    instance
    '''
    model = Model()
    model1 = Model()
    wind = Wind(timeseries=[(t, (0, 1))], units='m/s')
    water = Water()

    waves = Waves(name='waves')
    waves1 = Waves(name='waves1', make_default_refs=False)
    model.environment += [wind,
                          water,
                          waves]
    model1.environment += waves1

    # waves should get auto hooked up/waves1 should not
    model.step()
    assert waves.wind is wind
    assert waves.water is water
    with pytest.raises(ReferencedObjectNotSet):
        model1.step()
开发者ID:liuy0813,项目名称:PyGnome,代码行数:26,代码来源:test_gnomeobject.py

示例12: test_simple_run_with_image_output

# 需要导入模块: from gnome.model import Model [as 别名]
# 或者: from gnome.model.Model import step [as 别名]
def test_simple_run_with_image_output():
    """
    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_images')
    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

    gnome_map = 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=gnome_map,
        uncertain=False,
        cache_enabled=False,
        )

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

    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)

    assert len(model.spills) == 1

    model.start_time = spill.release_time

    # image_info = model.next_image()

    num_steps_output = 0
    while True:
        print 'calling step'
        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,代码行数:70,代码来源:test_model.py


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