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


Python OrderedDict.pop方法代码示例

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


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

示例1: merge_hists

# 需要导入模块: from odict import OrderedDict [as 别名]
# 或者: from odict.OrderedDict import pop [as 别名]
def merge_hists(hists_d, merge_groups, order=PhysicsProcess.desired_plot_order):
    """
    Merges the dictionary of input histograms according to the merge rules, which are specified
    as a key-value dictionary, where the key is the target and value a list of (regular) expressions
    to merge under the key.

    For example, {
        "WJets": ["W[1-4]Jets_.*"],
        "tchan": ["T_t_ToLeptons", "Tbar_t_ToLeptons"],
    } will perform the corresponding merges. The values of the merge dict are the keys of the input histogram dict.

    returns - a dictionary with the merged histograms. Optionally you can specify a list with the desired order of the keys.
    """
    for v in hists_d.values():
        if not isinstance(v, Hist) and not isinstance(v, ROOT.TH1I) and not isinstance(v, ROOT.TH1F) and not isinstance(v, Hist2D) and not isinstance(v, ROOT.TH2I) and not isinstance(v, ROOT.TH2F):
            raise ValueError("First argument(hists_d) must be a dict of Histograms, but found %s" % v)

    out_d = OrderedDict()
    logger.debug("merge_hists: input histograms %s" % str(hists_d))

    for merge_name, items in merge_groups.items():
        logger.debug("Merging %s to %s" % (items, merge_name))

        matching_keys = []
        for item in items:
            t = filter(lambda x: re.match(item + "$", x), hists_d.keys())
            matching_keys += t
            logger.debug("Matched %s to %s" % (str(t), item))
        if len(matching_keys)==0:
            continue
        logger.debug("Merging matched %s" % str(matching_keys))
        hist = hists_d[matching_keys[0]].Clone()
        for item in matching_keys[1:]:
            hist.Add(hists_d[item])

        out_d[merge_name] = hist
        out_d[merge_name].SetTitle(merge_name)
        out_d[merge_name].SetName(merge_name)

    out_d_ordered = OrderedDict()

    for elem in order:
        try:
            out_d_ordered[elem] = out_d.pop(elem)
            if hasattr(PhysicsProcess, merge_name):
                if type(getattr(PhysicsProcess, merge_name)) is dict:   #take nominal name if multiple options
                    out_d_ordered[elem].SetTitle(getattr(PhysicsProcess, merge_name)["nominal"].pretty_name)
                else:   #regular
                    out_d_ordered[elem].SetTitle(getattr(PhysicsProcess, merge_name).pretty_name)
        except KeyError: #We don't care if there was an element in the order which was not present in the merge output
            pass

    #Put anything that was not in the order list simply to the end
    for k, v in out_d.items():
        out_d_ordered[k] = v

    return out_d_ordered
开发者ID:HEP-KBFI,项目名称:stpol,代码行数:59,代码来源:utils.py


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