def _shadow_level(kernel, threshold, sensitivity):
    """
    Calculates the greyscale shadow level for a given kernel,
    the diode threshold and the diode sensitivity.

    :param kernel:      pooling kernel for down scaling
    :type kernel:       float array (2 dimensional)

    :param threshold:   thresholds for light intensity (determines the shadowlevel)
    :type threshold:    list or tuple (len == 3) descending order

    :param sensitivity: diode sensitivity
    :type sensitivity:  float

    :return:            shadowlevel (integer between 0 and 3)
    """
    light_intensity = 0.0
    for y in range(len(kernel)):
        for x in range(len(kernel[0])):
            light_intensity += kernel[y][x]
    # Normalizing the shadowlevel with kernel size
    light_intensity /= (len(kernel)*len(kernel[0]))
    if   light_intensity > (threshold[0] + sensitivity):
        return 0
    elif light_intensity > (threshold[1] + sensitivity):
        return 1
    elif light_intensity > (threshold[2] + sensitivity):
        return 2
    else:
        return 3