

def mask_relative_difference(data, target1, target2, days=5, padding_days=1, per_zone=False):
    '\n    Masks everywhere except the ``days`` number of days where the\n    resource of the two technologies ``target1`` and ``target2`` is most\n    different.\n\n    Parameters\n    ----------\n    data : Calliope model data\n    target1 : str\n    target2 : str\n    days : int, default 5\n    padding_days : int, default 1\n    per_zone: bool, default False\n\n    '
    data_length = len(data._dt)

    def _get_most_different(data, target1, target2, days, padding_days, target_zone=None):
        day_len = int((24 / data.time_res_data))
        targets = (target1, target2)
        relative_series = []
        for t in targets:
            if (not target_zone):
                t_series = data.r[t].sum(1)
            else:
                t_series = data.r[t].loc[:, target_zone]
            if (t_series.max() < 0):
                relative = (t_series / t_series.min())
            else:
                relative = (t_series / t_series.max())
            relative_series.append(relative)
        diff = (relative_series[0] - relative_series[1]).abs()
        most_different = diff.sort_values(ascending=False, inplace=False)
        datetimes = data._dt.loc[most_different.index]
        result = datetimes.dt.date.drop_duplicates().head(days)
        periods = []
        for (index, r) in result.iteritems():
            selected = data._dt[(data._dt.dt.date == r)].index[0]
            start = (selected - (padding_days * day_len))
            end = (selected + ((padding_days + 1) * day_len))
            periods.append((start, end))
        return periods
    if (not per_zone):
        periods = _get_most_different(data, target1, target2, days, padding_days)
    else:
        periods = []
        for zone in data._x:
            p = _get_most_different(data, target1, target2, days, padding_days, target_zone=zone)
            periods.extend(p)
    mask = pd.Series(1, index=list(range(data_length)))
    for p in periods:
        mask.loc[per_zone[0]:(p[1] - 1)] = 0
    mask.name = 'mask'
    return mask

dataset/ETHPy150Open calliope-project/calliope/calliope/time_masks.py mask_relative_difference/VarMisuse@437/681 `p`->`per_zone`