gridspec.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:xbpch 作者: darothen 项目源码 文件源码
def _get_model_info(model_name):
    """
    Get the grid specifications for a given model.

    Parameters
    ----------
    model_name : string
        Name of the model. Supports multiple formats
        (e.g., 'GEOS5', 'GEOS-5' or 'GEOS_5').

    Returns
    -------
    specifications : dict
        Grid specifications as a dictionary.

    Raises
    ------
    ValueError
        If the model is not supported (see `models`) or if the given
        `model_name` corresponds to several entries in the list of
        supported models.

    """
    # trying to get as much as possible a valid model name from the given
    # `model_name`, using regular expressions.
    split_name = re.split(r'[\-_\s]', model_name.strip().upper())
    sep_chars = ('', ' ', '-', '_')
    gen_seps = itertools.combinations_with_replacement(
        sep_chars, len(split_name) - 1
    )
    test_names = ("".join((n for n in itertools.chain(*list(zip(split_name,
                                                           s + ('',))))))
                  for s in gen_seps)
    match_names = list([name for name in test_names if name
                        in _get_supported_models()])

    if not len(match_names):
        raise ValueError("Model '{0}' is not supported".format(model_name))
    elif len(match_names) > 1:
        raise ValueError("Multiple matched models for given model name '{0}'"
                         .format(model_name))

    valid_model_name = match_names[0]
    parent_models = _find_references(valid_model_name)

    model_spec = dict()
    for m in parent_models:
        model_spec.update(MODELS[m])
    model_spec.pop('reference')
    model_spec['model_family'] = parent_models[0]
    model_spec['model_name'] = valid_model_name

    return model_spec
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号