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


Python OrderedCollection.register_callback方法代码示例

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


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

示例1: test_add_replace_callback

# 需要导入模块: from gnome.utilities.orderedcollection import OrderedCollection [as 别名]
# 或者: from gnome.utilities.orderedcollection.OrderedCollection import register_callback [as 别名]
    def test_add_replace_callback(self):
        "register one callback with multiple events (add, replace)"

        # lets work with a mutable type

        oc = OrderedCollection(dtype=ObjToAdd)
        oc.register_callback(self._add_callback, events=("add", "replace"))

        # check everything if False initially

        self._reset_ObjToAdd_init_state()

        oc += self.to_add

        for obj in oc:
            assert obj.add_callback
            assert not obj.rm_callback
            assert not obj.replace_callback

        rep = ObjToAdd()
        oc[s_id(self.to_add[0])] = rep

        for obj in oc:
            assert obj.add_callback
            assert not obj.rm_callback
            assert not obj.replace_callback
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:28,代码来源:test_ordered_collection.py

示例2: test_remove_callback

# 需要导入模块: from gnome.utilities.orderedcollection import OrderedCollection [as 别名]
# 或者: from gnome.utilities.orderedcollection.OrderedCollection import register_callback [as 别名]
    def test_remove_callback(self):
        "test remove callback is invoked after removing an object"

        oc = OrderedCollection(dtype=ObjToAdd)  # lets work with a mutable type
        oc.register_callback(self._rm_callback, events="remove")
        oc.register_callback(self._add_callback, events="add")

        # check everything if False initially

        self._reset_ObjToAdd_init_state()

        oc += self.to_add

        del oc[s_id(self.to_add[0])]

        assert self.to_add[0].rm_callback
        assert self.to_add[0].add_callback
        assert not self.to_add[0].replace_callback

        self.to_add[0].reset()  # reset all to false
        oc += self.to_add[0]  # let's add this back in

        for obj in oc:
            assert obj.add_callback
            assert not obj.rm_callback
            assert not obj.replace_callback
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:28,代码来源:test_ordered_collection.py

示例3: test_add_callback

# 需要导入模块: from gnome.utilities.orderedcollection import OrderedCollection [as 别名]
# 或者: from gnome.utilities.orderedcollection.OrderedCollection import register_callback [as 别名]
    def test_add_callback(self):
        '''
            test add callback is invoked after adding an object or
            list of objects
        '''

        # lets work with a mutable type
        oc = OrderedCollection(dtype=ObjToAdd)
        oc.register_callback(self._add_callback, events='add')

        # check everything if False initially

        self._reset_ObjToAdd_init_state()

        oc += self.to_add
        oc += ObjToAdd()

        for obj in oc:
            assert obj.add_callback
            assert not obj.rm_callback
            assert not obj.replace_callback
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:23,代码来源:test_ordered_collection.py

示例4: test_replace_callback

# 需要导入模块: from gnome.utilities.orderedcollection import OrderedCollection [as 别名]
# 或者: from gnome.utilities.orderedcollection.OrderedCollection import register_callback [as 别名]
    def test_replace_callback(self):
        "test replace callback is invoked after replacing an object"

        # lets work with a mutable type

        oc = OrderedCollection(dtype=ObjToAdd)
        oc.register_callback(self._replace_callback, events="replace")

        # check everything if False initially

        self._reset_ObjToAdd_init_state()

        oc += self.to_add
        rep = ObjToAdd()
        oc[s_id(self.to_add[0])] = rep

        for obj in oc:
            assert not obj.add_callback
            assert not obj.rm_callback
            if id(obj) == id(rep):
                assert obj.replace_callback
            else:
                assert not obj.replace_callback
开发者ID:JamesMakela-NOAA,项目名称:PyGnome,代码行数:25,代码来源:test_ordered_collection.py

示例5: SpillContainer

# 需要导入模块: from gnome.utilities.orderedcollection import OrderedCollection [as 别名]
# 或者: from gnome.utilities.orderedcollection.OrderedCollection import register_callback [as 别名]
class SpillContainer(AddLogger, SpillContainerData):
    """
    Container class for all spills -- it takes care of capturing the released
    LEs from all the spills, putting them all in a single set of arrays.

    Many of the "fields" associated with a collection of elements are optional,
    or used only by some movers, so only the ones required will be requested
    by each mover.

    The data for the elements is stored in the _data_arrays dict. They can be
    accessed by indexing. For example:

    positions = spill_container['positions'] : returns a (num_LEs, 3) array of
    world_point_types
    """
    def __init__(self, uncertain=False):
        super(SpillContainer, self).__init__(uncertain=uncertain)
        self.spills = OrderedCollection(dtype=gnome.spill.Spill)
        self.spills.register_callback(self._spills_changed,
                                      ('add', 'replace', 'remove'))
        self.rewind()

    def __setitem__(self, data_name, array):
        """
        Invoke base class __setitem__ method so the _data_array is set
        correctly.  In addition, create the appropriate ArrayType if it wasn't
        created by the user.
        """
        super(SpillContainer, self).__setitem__(data_name, array)
        if data_name not in self._array_types:
            shape = self._data_arrays[data_name].shape[1:]
            dtype = self._data_arrays[data_name].dtype.type

            self._array_types[data_name] = ArrayType(shape, dtype,
                                                     name=data_name)

    def _reset_arrays(self):
        '''
        reset _array_types dict so it contains default keys/values
        '''
        gnome.array_types.reset_to_defaults(['spill_num', 'id'])

        self._array_types = {'positions': positions,
                             'next_positions': next_positions,
                             'last_water_positions': last_water_positions,
                             'status_codes': status_codes,
                             'spill_num': spill_num,
                             'id': id,
                             'mass': mass,
                             'age': age}
        self._data_arrays = {}

    def _reset__substances_spills(self):
        '''
        reset internal attributes to None and empty list []:

        1. _substances_spills: data structure to contain spills per substance
        2. _oil_comp_array_len: max number of psuedocomponents - relevant if
           more than one substance is used.
        3. _fate_data_list: list of FateDataView() objects. One object per
           substance if substance is not None

        '''
        # Initialize following either the first time it is used or in
        # prepare_for_model_run() -- it could change with each new spill
        self._substances_spills = None
        self._oil_comp_array_len = None

    def _reset__fate_data_list(self):
        # define the fate view of the data if 'fate_status' is in data arrays
        # 'fate_status' is included if weathering is on
        self._fate_data_list = []

    def reset_fate_dataview(self):
        '''
        reset data arrays for each fate_dataviewer. Each substance that is not
        None has a fate_dataviewer object.
        '''
        for viewer in self._fate_data_list:
            viewer.reset()

    def _set_substancespills(self):
        '''
        _substances could change when spills are added/deleted
        using _spills_changed callback to reset self._substance_spills to None
        If 'substance' is None, we still include it in this data structure -
        all spills that are 'on' are included. A spill that is off isn't really
        being modeled so ignore it.

        .. note::
            Should not be called in middle of run. prepare_for_model_run()
            will invoke this if self._substance_spills is None. This is another
            view of the data - it doesn't contain any state that needs to be
            persisted.
        '''
        subs = []
        spills = []
        if self._oil_comp_array_len is None:
            self._oil_comp_array_len = 1

#.........这里部分代码省略.........
开发者ID:axiom-data-science,项目名称:PyGnome,代码行数:103,代码来源:spill_container.py


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