import math


def calc_conv_dBZlim(coef):
    """ Calculate dBZ limit for convective/frontal case Z-R calculation.
    Limit with default values is 23.48 dBZ.
    
    Keyword arguments:
    coef -- dictionary containing Z(R) A and B coefficients zr_a, zr_b, zr_a_c and zr_a_c (c for convective rain)

    Return:
    conv_dbzlim -- Limit dBZ value for convective rain rate calculation
    """

    zr_a = coef['zr_a']
    zr_b = coef['zr_b']
    zr_a_c = coef['zr_a_c']
    zr_b_c = coef['zr_b_c']
    
    if zr_a == zr_a_c:
        conv_dbzlim = 10.0 * math.log10(zr_a)
    else:
        R = (zr_a / zr_a_c) ** (1.0 / (zr_b_c - zr_b))
        conv_dbzlim = 10.0 * math.log10(zr_a * (R ** zr_b))

    return conv_dbzlim