def get_group_share(solution, techs, group_type='supply',
                    var='e_prod'):
    """
    From ``solution.summary``, get the share of the given list of ``techs``
    from the total for the given ``group_type``, for the given ``var``.

    """
    summary = solution.summary
    meta = solution.metadata.to_pandas()
    group = meta.query('type == "' + group_type + '"').index.tolist()
    if group_type == 'transmission':
        # Special case for transmission techs, we only want
        # the base tech names, since we're looking this
        # up in the summary table
        def transmission_basenames(group):
            return list(set([i.split(':')[0] for i in group]))
        techs = transmission_basenames(techs)
        group = transmission_basenames(group)
    supply_total = summary.loc[group, var].sum()
    supply_group = summary.loc[techs, var].sum()
    try:
        return supply_group / supply_total
    except ZeroDivisionError:
        # FIXME it seems that on some systems, supply_ are not numpy.floats
        # but regular Python floats, leading to a ZeroDivisionError
        # in cases such as demand groups
        return np.nan
dataset/ETHPy150Open calliope-project/calliope/calliope/analysis.py/get_group_share/original