def METHOD_NAME(results, model_data, systemwide=False):
    """
    # In operate mode, energy_cap is an input parameter
    if "energy_cap" not in results.keys():
        energy_cap = model_data.energy_cap
    else:
        energy_cap = results.energy_cap
    capacity_factors = (results["carrier_prod"] / energy_cap).fillna(0)
    The weight of timesteps is considered when computing systemwide capacity factors,
    such that higher-weighted timesteps have a stronger influence
    on the resulting system-wide time-averaged capacity factor.
    """
    # In operate mode, energy_cap is an input parameter
    if "energy_cap" not in results.keys():
        energy_cap = model_data.energy_cap
    else:
        energy_cap = results.energy_cap
    if systemwide:
        prod_sum = (results["carrier_prod"] * model_data.timestep_weights).sum(
            dim=["timesteps", "nodes"], min_count=1
        )
        cap_sum = energy_cap.where(lambda x: x > 0).sum(dim="nodes", min_count=1)
        time_sum = (model_data.timestep_resolution * model_data.timestep_weights).sum()
        capacity_factors = (prod_sum / (cap_sum * time_sum)).fillna(0)
    else:
        capacity_factors = (
            results["carrier_prod"] / energy_cap.where(lambda x: x > 0)
        ).fillna(0)
    return capacity_factors