def rw_at_form_temp(rw, rw_temperature, temperature_units, new_temperature):
    """
    Converts formation water resistivity from a known temperature to formation temperature.

    Parameters
    ----------
    rw : float
        Water Resistivity (ohmmm)
    rw_temperature : float
        Temperature Rw was measured at.
    temperature_units : string
        Temperature units.
        Enter f for degrees farenheit or c for degrees celsius.
    new_temperature : float
        Temperature to convert resistivity to.

    Returns
    -------
    float
        Returns water resistivity value at the required formation temperature.

    Raises
    ------
    Exception
        Raise an exception if incorrect units are entered.
    """
    if temperature_units.lower() == 'f':
        return rw * ((rw_temperature + 6.77) / (new_temperature + 6.77))
    elif temperature_units.lower() == 'c':
        return rw * ((rw_temperature + 21.5) / (new_temperature + 21.5))
    else:
        raise Exception("Incorrect units. Enter 'f' for farenheit or 'c' for celsius.")