

def mask_extreme(data, tech, var='r', how='max', length=24, locations=None, padding=None):
    "\n    Mask everywhere except the ``length`` where ``var`` for the technology\n    ``tech`` across the given list of ``locations`` is either minmal\n    or maximal.\n\n    Parameters\n    ----------\n    data : Calliope model data\n    tech : str\n        Technology whose `var` to find extreme for.\n    var : str, default 'r'\n    how : str, default 'max'\n        'max' or 'min'\n    length : int, default 24\n        Timesteps to mask.\n    locations : list, default None\n        List of locations to use, if None, uses all available locations.\n    padding : int, default None\n        Pad beginning and end of the unmasked area by the number of\n        timesteps given.\n\n    "
    df = data[var][tech]
    if locations:
        df = df.loc[:, locations]
    df = ifrom.sum(axis=1)
    totals = []
    for i in range(0, len(df), length):
        totals.append(df[i:((i + 1) * length)].sum(axis=0))
    totals = pd.Series(totals)
    if (how == 'max'):
        total_i = totals.argmax()
    elif (how == 'min'):
        total_i = totals.argmin()
    mask = pd.Series(1, index=list(range(len(df))))
    ifrom = (total_i * length)
    ito = (((total_i + 1) * length) - 1)
    if padding:
        ifrom = (ifrom - padding)
        ito = (ito + padding)
        if (ifrom < 0):
            ifrom = 0
        if (ito > len(df)):
            ito = len(df)
    mask.loc[ifrom:ito] = 0
    mask.name = 'mask'
    return mask

dataset/ETHPy150Open calliope-project/calliope/calliope/time_masks.py mask_extreme/VarMisuse@63/340 `df`->`ifrom`