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


Python abc.Collection方法代码示例

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


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

示例1: delete

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def delete(self, idx):
        """Delete an aircraft"""
        # If this is a multiple delete, sort first for list delete
        # (which will use list in reverse order to avoid index confusion)
        if isinstance(idx, Collection):
            idx = np.sort(idx)

        # Call the actual delete function
        super(Traffic, self).delete(idx)

        # Update conditions list
        self.cond.delac(idx)

        # Update number of aircraft
        self.ntraf = len(self.lat)
        return True 
开发者ID:TUDelft-CNS-ATM,项目名称:bluesky,代码行数:18,代码来源:traffic.py

示例2: selaltcmd

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def selaltcmd(self, idx, alt, vspd=None):
        """ Select altitude command: ALT acid, alt, [vspd] """
        bs.traf.selalt[idx]   = alt
        bs.traf.swvnav[idx]   = False

        # Check for optional VS argument
        if vspd:
            bs.traf.selvs[idx] = vspd
        else:
            if not isinstance(idx, Collection):
                idx = np.array([idx])
            delalt        = alt - bs.traf.alt[idx]
            # Check for VS with opposite sign => use default vs
            # by setting autopilot vs to zero
            oppositevs = np.logical_and(bs.traf.selvs[idx] * delalt < 0., abs(bs.traf.selvs[idx]) > 0.01)

            bs.traf.selvs[idx[oppositevs]] = 0. 
开发者ID:TUDelft-CNS-ATM,项目名称:bluesky,代码行数:19,代码来源:autopilot.py

示例3: delete

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def delete(self, idx):
        # Remove element (aircraft) idx from all lists and arrays
        for child in self._children:
            child.delete(idx)

        for v in self._ArrVars:
            self._Vars[v] = np.delete(self._Vars[v], idx)

        if self._LstVars:
            if isinstance(idx, Collection):
                for i in reversed(idx):
                    for v in self._LstVars:
                        del self._Vars[v][i]
            else:
                for v in self._LstVars:
                    del self._Vars[v][idx] 
开发者ID:TUDelft-CNS-ATM,项目名称:bluesky,代码行数:18,代码来源:trafficarrays.py

示例4: _share_metadata_key

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def _share_metadata_key(k, values, average_times):
    """Combine metadata. Helper for combine_metadata, decide if key is shared."""
    any_arrays = any([hasattr(val, "__array__") for val in values])
    # in the real world, the `ancillary_variables` attribute may be
    # List[xarray.DataArray], this means our values are now
    # List[List[xarray.DataArray]].
    # note that this list_of_arrays check is also true for any
    # higher-dimensional ndarray, but we only use this check after we have
    # checked any_arrays so this false positive should have no impact
    list_of_arrays = any(
            [isinstance(val, Collection) and len(val) > 0 and
             all([hasattr(subval, "__array__")
                 for subval in val])
             for val in values])
    if any_arrays:
        return _share_metadata_key_array(values)
    elif list_of_arrays:
        return _share_metadata_key_list_arrays(values)
    elif 'time' in k and isinstance(values[0], datetime) and average_times:
        return True
    elif all(val == values[0] for val in values[1:]):
        return True
    return False 
开发者ID:pytroll,项目名称:satpy,代码行数:25,代码来源:dataset.py

示例5: unstructure_attrs_asdict

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def unstructure_attrs_asdict(self, obj):
        cls = obj.__class__
        attrs = cls.__attrs_attrs__
        dispatch = self._unstructure_func.dispatch
        # add version stamp
        if cls is Font:
            rv = {".formatVersion": self.version}
        else:
            rv = {}
        override = cls is Font or cls is Layer
        for a in attrs:
            # skip internal attrs
            if not a.init:
                continue
            name = a.name
            v = getattr(obj, name)
            if not v:
                # skip attrs that have trivial default values set
                if v == a.default:
                    continue
                # skip empty collections
                if isinstance(v, Collection):
                    continue
            # force our specialized types overrides
            type_ = v.__class__
            if override:
                t = a.type
                try:
                    if issubclass(t.__origin__, dict) and t.__args__[0] is str:
                        type_ = t
                except (AttributeError, TypeError):
                    pass
            # remove underscore from private attrs
            if name[0] == "_":
                name = name[1:]
            rv[name] = dispatch(type_)(v)
        return rv 
开发者ID:trufont,项目名称:tfont,代码行数:39,代码来源:tfontConverter.py

示例6: __subclasshook__

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def __subclasshook__(cls, C):
            if cls is Collection:
                if any("__len__" in B.__dict__ for B in C.__mro__) and \
                        any("__iter__" in B.__dict__ for B in C.__mro__) and \
                        any("__contains__" in B.__dict__ for B in C.__mro__):
                    return True
            return NotImplemented

# Python 3.4 require contextlib2 for temporarily redirecting stderr and stdout 
开发者ID:TuuuNya,项目名称:WebPocket,代码行数:11,代码来源:cmd2.py

示例7: flag_based_complete

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def flag_based_complete(self, text: str, line: str, begidx: int, endidx: int,
                            flag_dict: Dict[str, Union[Iterable, Callable]],
                            all_else: Union[None, Iterable, Callable]=None) -> List[str]:
        """
        Tab completes based on a particular flag preceding the token being completed
        :param text: the string prefix we are attempting to match (all returned matches must begin with it)
        :param line: the current input line with leading whitespace removed
        :param begidx: the beginning index of the prefix text
        :param endidx: the ending index of the prefix text
        :param flag_dict: dictionary whose structure is the following:
                          keys - flags (ex: -c, --create) that result in tab completion for the next
                                 argument in the command line
                          values - there are two types of values
                             1. iterable list of strings to match against (dictionaries, lists, etc.)
                             2. function that performs tab completion (ex: path_complete)
        :param all_else: an optional parameter for tab completing any token that isn't preceded by a flag in flag_dict
        :return: a list of possible tab completions
        """
        # Get all tokens through the one being completed
        tokens, _ = self.tokens_for_completion(line, begidx, endidx)
        if not tokens:
            return []

        completions_matches = []
        match_against = all_else

        # Must have at least 2 args for a flag to precede the token being completed
        if len(tokens) > 1:
            flag = tokens[-2]
            if flag in flag_dict:
                match_against = flag_dict[flag]

        # Perform tab completion using a Collection
        if isinstance(match_against, Collection):
            completions_matches = self.basic_complete(text, line, begidx, endidx, match_against)

        # Perform tab completion using a function
        elif callable(match_against):
            completions_matches = match_against(text, line, begidx, endidx)

        return completions_matches 
开发者ID:TuuuNya,项目名称:WebPocket,代码行数:43,代码来源:cmd2.py

示例8: test_algorithms

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def test_algorithms():
    assert isinstance(hashlib.algorithms_guaranteed, Collection)
    assert hashlib.algorithms_guaranteed

    assert isinstance(hashlib.algorithms_available, Collection)
    assert hashlib.algorithms_available

    assert frozenset(hashlib.algorithms_guaranteed).issubset(
        hashlib.algorithms_available
    ) 
开发者ID:Synss,项目名称:python-mbedtls,代码行数:12,代码来源:test_md.py

示例9: _validate_value

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def _validate_value(self, val: V, key: str) -> V:
        if (
            hasattr(val, "index")
            and isinstance(val.index, cabc.Collection)
            and not (val.index == self.dim_names).all()
        ):
            # Could probably also re-order index if it’s contained
            raise ValueError(
                f"value.index does not match parent’s axis {self.axes[0]} names"
            )
        return super()._validate_value(val, key) 
开发者ID:theislab,项目名称:anndata,代码行数:13,代码来源:aligned_mapping.py

示例10: selhdgcmd

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def selhdgcmd(self, idx, hdg):  # HDG command
        """ Select heading command: HDG acid, hdg """
        if not isinstance(idx, Collection):
            idx = np.array([idx])
        if not isinstance(hdg, Collection):
            hdg = np.array([hdg])
        # If there is wind, compute the corresponding track angle
        if bs.traf.wind.winddim > 0:
            ab50 = bs.traf.alt[idx] > 50.0 * ft
            bel50 = np.logical_not(ab50)
            iab = idx[ab50]
            ibel = idx[bel50]

            tasnorth = bs.traf.tas[iab] * np.cos(np.radians(hdg[ab50]))
            taseast = bs.traf.tas[iab] * np.sin(np.radians(hdg[ab50]))
            vnwnd, vewnd = bs.traf.wind.getdata(bs.traf.lat[iab], bs.traf.lon[iab], bs.traf.alt[iab])
            gsnorth = tasnorth + vnwnd
            gseast = taseast + vewnd
            self.trk[iab] = np.degrees(np.arctan2(gseast, gsnorth))%360.
            self.trk[ibel] = hdg
        else:
            self.trk[idx] = hdg

        bs.traf.swlnav[idx] = False
        # Everything went ok!
        return True 
开发者ID:TUDelft-CNS-ATM,项目名称:bluesky,代码行数:28,代码来源:autopilot.py

示例11: setLNAV

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def setLNAV(self, idx, flag=None):
        """ Set LNAV on or off for specific or for all aircraft """
        if not isinstance(idx, Collection):
            if idx is None:
                # All aircraft are targeted
                bs.traf.swlnav = np.array(bs.traf.ntraf * [flag])
            else:
                # Prepare for the loop
                idx = np.array([idx])

        # Set LNAV for all aircraft in idx array
        output = []
        for i in idx:
            if flag is None:
                output.append(bs.traf.id[i] + ": LNAV is " + ("ON" if bs.traf.swlnav[i] else "OFF"))

            elif flag:
                route = self.route[i]
                if route.nwp <= 0:
                    return False, ("LNAV " + bs.traf.id[i] + ": no waypoints or destination specified")
                elif not bs.traf.swlnav[i]:
                   bs.traf.swlnav[i] = True
                   route.direct(i, route.wpname[route.findact(i)])
            else:
                bs.traf.swlnav[i] = False
        if flag == None:
            return True, '\n'.join(output) 
开发者ID:TUDelft-CNS-ATM,项目名称:bluesky,代码行数:29,代码来源:autopilot.py

示例12: setVNAV

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def setVNAV(self, idx, flag=None):
        """ Set VNAV on or off for specific or for all aircraft """
        if not isinstance(idx, Collection):
            if idx is None:
                # All aircraft are targeted
                bs.traf.swvnav    = np.array(bs.traf.ntraf * [flag])
                bs.traf.swvnavspd = np.array(bs.traf.ntraf * [flag])
            else:
                # Prepare for the loop                
                idx = np.array([idx])

        # Set VNAV for all aircraft in idx array
        output = []
        for i in idx:
            if flag is None:
                msg = bs.traf.id[i] + ": VNAV is " + "ON" if bs.traf.swvnav[i] else "OFF"
                if not bs.traf.swvnavspd[i]:
                    msg += " but VNAVSPD is OFF"
                output.append(bs.traf.id[i] + ": VNAV is " + "ON" if bs.traf.swvnav[i] else "OFF")

            elif flag:
                if not bs.traf.swlnav[i]:
                    return False, (bs.traf.id[i] + ": VNAV ON requires LNAV to be ON")

                route = self.route[i]
                if route.nwp > 0:
                    bs.traf.swvnav[i]    = True
                    bs.traf.swvnavspd[i] = True
                    self.route[i].calcfp()
                    actwpidx = self.route[i].iactwp
                    self.ComputeVNAV(i,self.route[i].wptoalt[actwpidx],self.route[i].wpxtoalt[actwpidx],\
                                     self.route[i].wptorta[actwpidx],self.route[i].wpxtorta[actwpidx])
                    bs.traf.actwp.nextaltco[i] = self.route[i].wptoalt[actwpidx]

                else:
                    return False, ("VNAV " + bs.traf.id[i] + ": no waypoints or destination specified")
            else:
                bs.traf.swvnav[i]    = False
                bs.traf.swvnavspd[i] = False
        if flag == None:
            return True, '\n'.join(output) 
开发者ID:TUDelft-CNS-ATM,项目名称:bluesky,代码行数:43,代码来源:autopilot.py

示例13: lsvar

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def lsvar(varname=''):
    ''' Stack function to list information on simulation variables in the
        BlueSky console. '''
    if not varname:
        # When no argument is passed, show a list of parent objects for which
        # variables can be accessed
        return True, '\n' + \
            str.join(', ', [key for key in varlist])

    # Find the variable in the variable list
    v = findvar(varname)
    if v:
        thevar = v.get()  # reference to the actual variable
        # When the variable is an object, get child attributes
        attrs = getvarsfromobj(thevar)
        vartype = v.get_type()  # Type of the variable
        if isinstance(v.parent, TrafficArrays) and v.parent.istrafarray(v.varname):
            vartype += ' (TrafficArray)'
        txt = \
            'Variable:   {}\n'.format(v.varname) + \
            'Type:       {}\n'.format(vartype)
        if isinstance(thevar, Collection):
            txt += 'Size:       {}\n'.format(len(thevar))
        txt += 'Parent:     {}'.format(v.parentname)
        if attrs:
            txt += '\nAttributes: ' + str.join(', ', attrs) + '\n'
        return True, '\n' + txt
    return False, 'Variable {} not found'.format(varname) 
开发者ID:TUDelft-CNS-ATM,项目名称:bluesky,代码行数:30,代码来源:varexplorer.py

示例14: is_num

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def is_num(self):
        ''' py3 replacement of operator.isNumberType.'''
        v = getattr(self.parent, self.varname)
        return isinstance(v, Number) or \
            (isinstance(v, np.ndarray) and v.dtype.kind not in 'OSUV') or \
            (isinstance(v, Collection) and self.index and
             all([isinstance(v[i], Number) for i in self.index])) 
开发者ID:TUDelft-CNS-ATM,项目名称:bluesky,代码行数:9,代码来源:varexplorer.py

示例15: delete

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Collection [as 别名]
def delete(self, idx):
        self.delac.extend(np.array(traf.id)[idx], traf.lat[idx], traf.lon[idx], traf.distflown[idx])
        # n = len(idx) if isinstance(idx, Collection) else 1
        # print(n, 'aircraft deleted, ntraf =', traf.ntraf, 'idx =', idx, 'len(traf.lat) =', len(traf.lat)) 
开发者ID:TUDelft-CNS-ATM,项目名称:bluesky,代码行数:6,代码来源:metrics.py


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