def estimate_flag(bflag, corr_moments, cr_moments, cr_ldr, bounds_unfiltered_moments):
    """retrieve the integer flag from the binary flag

    the available integer flags are:

    .. code-block:: python

        {0: 'not influenced', 1: 'hydromet only',
         2: 'plankton', 3: 'low snr',
         4: '', 5: 'melting layer'}

    Args:
        bflag (dict): binary flag dict
        corr_moments (list): list with the corrected moments
        cr_moments (list): list with the cloud radar moemnts
        cr_ldr (float): cloud radar ldr in dB
        bounds_unfiltered_moments (list): all peak boundaries
    Returns:
        add_to_binary_flag, flag, flag_doc

    """
    # do not overwrite bflag here! (this has to be done at top level)
    addbflag = {'low_snr': 0, 
                'plankton': 0,
                'melting_layer': 0}
    flag_doc = {0: 'not influenced',
                1: 'hydromet only',
                2: 'plankton',
                3: 'low snr',
                4: '',
                5: 'melting layer'}

    bins_above_noise = sum(
        [b[1]-b[0] for b in bounds_unfiltered_moments])
    bounds_unfiltered_moments.sort()
    bin_max_span = bounds_unfiltered_moments[-1][-1] - bounds_unfiltered_moments[0][0]

    if bflag["particle_influence"] == 1:
        flag = 1
        if corr_moments[0].snr < 10:
            addbflag['low_snr'] = 1
            flag = 3
        if cr_ldr > -13:
            if cr_moments[0].Z < -3:
                addbflag['plankton'] = 1
                flag = 2
            else:
                addbflag['melting_layer'] = 1
                flag = 5
        else:
            if (len(corr_moments) > 4 
                or bins_above_noise > 140 
                or bin_max_span > 180
                or bflag['hs_higher_noise'] == 1):
                addbflag['melting_layer'] = 1
                flag = 5
    else:
        flag = 0
    return addbflag, flag, flag_doc