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


Python SpillContainer.get_substances方法代码示例

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


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

示例1: test_spills_with_and_notwith_substance

# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import get_substances [as 别名]
    def test_spills_with_and_notwith_substance(self):
        '''
        datastructure only adds substance/spills if substance is not None
        deleting spill resets datastructure.

        - the spills in _substances_spills 'is' the same as the spills
          in sc.spills - same object
        '''
        sc = SpillContainer()
        sc.spills += [Spill(Release(datetime.now(), 10),
                            element_type=floating(substance=None),
                            name='spill0'),
                      Spill(Release(datetime.now(), 10),
                            element_type=floating(substance=test_oil),
                            name='spill1')]

        assert len(sc.get_substances()) == 2
        sc.prepare_for_model_run()
        all_spills = list(chain.from_iterable(sc._substances_spills.spills))
        assert len(all_spills) == len(sc.spills)
        for spill in all_spills:
            assert sc.spills[spill.id] is spill

        del sc.spills[-1]
        assert len(sc.get_substances()) == 1
        assert len(sc.iterspillsbysubstance()) == 1
开发者ID:liuy0813,项目名称:PyGnome,代码行数:28,代码来源:test_spill_container.py

示例2: test_no_substance

# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import get_substances [as 别名]
    def test_no_substance(self):
        '''
        no substance means run trajectory without an OilProps object/without
        weathering is one reason to do this
        '''
        sc = SpillContainer()
        sc.spills += [Spill(Release(datetime.now(), 10),
                            element_type=floating(substance=None),
                            name='spill0'),
                      Spill(Release(datetime.now(), 10),
                            element_type=floating(substance=None),
                            name='spill1')]
        assert len(sc.itersubstancedata('mass')) == 0
        assert len(sc.get_substances()) == 1
        assert len(sc.get_substances(complete=False)) == 0

        # iterspillsbysubstance() iterates through all the spills associated
        # with each substance including the spills where substance is None
        assert len(sc.iterspillsbysubstance()) == 2
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:21,代码来源:test_spill_container.py

示例3: test_split_element

# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import get_substances [as 别名]
def test_split_element():
    '''
    test split_element() method
    '''
    sc = SpillContainer()
    o_sc = SpillContainer()
    reltime = datetime(2015, 1, 1, 12, 0, 0)
    num_les = 10
    sc.spills += point_line_release_spill(num_les, (1, 1, 1),
                                          reltime,
                                          amount=100,
                                          units='kg',
                                          substance=test_oil)
    o_sc.spills += copy.deepcopy(sc.spills[0])

    sc.prepare_for_model_run({'fate_status'})
    sc.release_elements(900, reltime)

    o_sc.prepare_for_model_run({'fate_status'})
    o_sc.release_elements(900, reltime)

    # now do a split at element - fate data is not being initialized; however
    # we want to make sure fate_data arrays are sync'd with sc data arrays so
    # test for fate=non_weather
    num = 2
    l_frac = (.65, .35)
    subs = sc.get_substances(complete=False)[0]
    data = sc.substancefatedata(subs,
                                {'fate_status'},
                                fate='non_weather')
    assert 'id' in data

    ix = data['id'][0]
    sc.split_element(ix, num, l_frac)
    for name in sc._data_arrays:
        split = sc[name]
        d_split = data[name]

        idx = np.where(sc['id'] == ix)[0][0]
        orig = o_sc[name]
        assert len(split) == num_les + num - 1
        assert len(d_split) == num_les + num - 1
        at = sc.array_types[name]
        if isinstance(at, array_types.ArrayTypeDivideOnSplit):
            assert np.allclose(split[idx:idx + num].sum(0), orig[idx])
            assert np.allclose(split[idx], l_frac[0] * orig[idx])
        else:
            assert np.all(split[idx:idx + num] == orig[idx])

        # fatedata copy of sc data is also updated
        assert np.allclose(d_split, split)
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:53,代码来源:test_spill_container.py

示例4: test_spills_same_substance_init

# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import get_substances [as 别名]
 def test_spills_same_substance_init(self):
     sc = SpillContainer()
     et = floating(substance=test_oil)
     sp_add = [point_line_release_spill(3, (1, 1, 1), datetime.now(),
                                        element_type=et),
               Spill(Release(datetime.now(), 10),
                     amount=100, units='kg',
                     element_type=floating(substance=test_oil)),
               Spill(Release(datetime.now(), 10),
                     element_type=floating(substance=et.substance))
               ]
     sc.spills += sp_add
     assert len(sc.get_substances()) == 1
     sc.prepare_for_model_run()
     assert all([sp_add == spills for spills in sc.iterspillsbysubstance()])
开发者ID:liuy0813,项目名称:PyGnome,代码行数:17,代码来源:test_spill_container.py

示例5: test_spills_different_substance_init

# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import get_substances [as 别名]
    def test_spills_different_substance_init(self):
        sc = SpillContainer()
        splls0 = [point_line_release_spill(3, (1, 1, 1),
                                           datetime.now(),
                                           element_type=floating(substance=test_oil)),
                  Spill(Release(datetime.now(), 10),
                        element_type=floating(substance=test_oil)),
                  ]
        sc.spills += splls0
        splls1 = [Spill(Release(datetime.now(), 10),
                        element_type=floating(substance='oil_crude'))
                  ]
        sc.spills += splls1

        assert (len(sc.get_substances()) == 2 and
                len(sc.iterspillsbysubstance()) == 2)
开发者ID:liuy0813,项目名称:PyGnome,代码行数:18,代码来源:test_spill_container.py

示例6: test_spills_different_substance_release

# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import get_substances [as 别名]
    def test_spills_different_substance_release(self):
        '''
        Test data structure gets correctly set/updated after release_elements
        is invoked
        '''
        sc = SpillContainer()
        rel_time = datetime(2014, 1, 1, 12, 0, 0)
        end_time = rel_time + timedelta(hours=1)
        time_step = 900
        splls0 = [point_line_release_spill(100, (1, 1, 1),
                                           rel_time,
                                           end_release_time=end_time,
                                           element_type=floating(substance=test_oil),
                                           amount=100,
                                           units='kg'),
                  point_line_release_spill(50, (2, 2, 2),
                                           rel_time + timedelta(seconds=900),
                                           element_type=floating(substance=test_oil),
                                           amount=150,
                                           units='kg'),
                  ]
        sc.spills += splls0
        splls1 = point_line_release_spill(10, (0, 0, 0),
                                          rel_time,
                                          element_type=floating(substance=None))
        sc.spills += splls1

        at = {'density', 'mass_components'}
        sc.prepare_for_model_run(at)
        assert len(sc.get_substances()) == 2

        print '\nElements released:'
        for ix in range(-1, 8):
            time = rel_time + timedelta(seconds=time_step) * ix
            num_rel = sc.release_elements(time_step, time)
            print num_rel
            for substance, data in sc.itersubstancedata(at):
                assert substance.name == test_oil
                idx = sc._substances_spills.substances.index(substance)
                mask = sc['substance'] == idx
                for array in at:
                    assert array in data
                    assert np.all(data[array] == sc[array][mask])
开发者ID:liuy0813,项目名称:PyGnome,代码行数:45,代码来源:test_spill_container.py

示例7: test_no_spills

# 需要导入模块: from gnome.spill_container import SpillContainer [as 别名]
# 或者: from gnome.spill_container.SpillContainer import get_substances [as 别名]
 def test_no_spills(self):
     'test iterators work without any spills'
     sc = SpillContainer()
     assert len(sc.iterspillsbysubstance()) == 0
     assert len(sc.get_substances()) == 1
     assert len(sc.get_substances(complete=False)) == 0
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:8,代码来源:test_spill_container.py


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