

def mask_extreme_week(data, tech, var='r', how='sum', what='min'):
    "\n    Mask everywhere except the week containing the day where ``var`` of\n    ``tech`` is minimal (what='min') or maximal (what='max') across the\n    sum (how='sum') of or the mode (most) of locations (how='mode').\n\n    Parameters\n    ----------\n    data : Calliope model data\n    tech : str\n        Technology whose `var` to find extreme week for.\n    var : str, default 'r'\n    how : str, default 'sum'\n        'sum' or 'mode'\n    what : str, default 'min'\n        'min' or 'max'\n\n    "
    df = data[var][tech]
    day_len = int((24 / data.time_res_data))
    dff_index = list(range(0, len(df), day_len))
    dff = df.rolling(window=day_len).sum().reindex(dff_index)
    idx_extr = (lambda x: getattr(x, 'idx{}'.format(what)))
    if (how == 'mode'):
        selected = idx_extr(dff)().mode()[0]
    elif (how == 'sum'):
        selected = idx_extr(dff.sum(axis=1))()
    d = d._dt.at[selected]
    week_start = (selected - (day_len * d.dayofweek))
    week_end = (selected + (day_len * (7 - d.dayofweek)))
    mask = pd.Series(1, index=list(range(len(df))))
    mask.loc[week_start:(week_end - 1)] = 0
    mask.name = 'mask'
    return mask

dataset/ETHPy150Open calliope-project/calliope/calliope/time_masks.py mask_extreme_week/VarMisuse@159/417 `data`->`d`