def mask_relative_difference(data, target1, target2, days=5,
                             padding_days=1, per_zone=False):
    data_length = len(data._dt)

    def _get_most_different(data, target1, target2,
                            days, padding_days, target_zone=None):
        # Get length of a day in timesteps
        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:  # Assume this is a demand series and <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` are the datetimes for the found days (indexed by timestep index)
        result = datetimes.dt.date.drop_duplicates().head(days)

        periods = []
        for index, r in result.iteritems():
            # `selected` is the index of the first timestamp in the chosen day
            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 where everything is 1 (reduce resolution) by default
    mask = pd.Series(1, index=list(range(data_length)))
    # For the desired time periods, change the mask to native resolution (0)
    for p in periods:
        mask.loc[p[0]:p[1] - 1] = 0
    mask.name = 'mask'
    return mask
Masks everywhere except the ``days`` number of days where the
dataset/ETHPy150Open calliope-project/calliope/calliope/time_masks.py/mask_relative_difference