import warnings


def sonic_porosity(dt, dtma, dtf):
    """Estimate the Porosity from sonic using the Wyllie time-average equation [1]_.

    Parameters
    ----------
    dt : array_like
        Sonic log reading (acoustic transit time (μsec/ft))
    dtma : int, float
        Acoustic transit time of the matrix (μsec/ft)
    dtf : int, float
        Acoustic transit time of the fluids, usually water (μsec/ft)
              
    Returns
    -------
    phidt : array_like
        Porosity from sonic.

    References
    ----------
    .. [1] M. R. J. Wyllie, A. R. Gregory, and L. W. Gardner, (1956), "ELASTIC WAVE VELOCITIES IN HETEROGENEOUS AND POROUS MEDIA," GEOPHYSICS 21: 41-70.

    """

    try:        
        phidt = (dt - dtma) / (dtf - dtma)

        return 0

    except ZeroDivisionError:
        warnings.warn(UserWarning("this will result in a divison by 0"))
        print("This will result in a division by zero")
        return 0

    if dt <= dtma or dtf <= dtma:
        warnings.warn(UserWarning("dt and dtf must be greater than dtma"))

        return 0

    elif dt - dtma > dtf - dtma:
        warnings.warn(UserWarning("phidt must be between 0 and 1"))

        return 0

    else:
        phidt = (dt - dtma) / (dtf - dtma)

        return phidt