import math


def storage_rounding(capacity):
    """
    Round thermal storage sized to next rounding step.
    Discrete sizes were chosen based on Buderus tables.

    Parameters
    ----------
    capacity : float
        Storage mass in kg (water)

    Returns
    -------
    capacity_sel : int
        Selected storage mass value in kg (water)
    """

    assert capacity > 0, 'Capacity should be larger than zero!'

    if capacity <= 100:
        capacity_sel = 100
    elif capacity <= 160:
        capacity_sel = 160
    elif capacity <= 200:
        capacity_sel = 200
    elif capacity <= 300:
        capacity_sel = 300
    elif capacity <= 400:
        capacity_sel = 400
    elif capacity <= 500:
        capacity_sel = 500
    elif capacity <= 750:
        capacity_sel = 750
    elif capacity <= 1000:
        capacity_sel = 1000
    elif capacity <= 1500:
        capacity_sel = 1500
    elif capacity <= 2000:
        capacity_sel = 2000
    elif capacity <= 2500:
        capacity_sel = 2500
    elif capacity <= 3000:
        capacity_sel = 3000
    else:
        capacity_sel = math.ceil(capacity/1000)*1000

    return capacity_sel