def time_average(avg, total_time, value, time_incr):
    """A macro to update a time-weighted average for a quantity.

    Args:
        avg (float or array): current average
        total_time (float): the time interval the current average applies to
        value (float or array): new value to be averaged in
        time_incr (float): the time interval the new value applies to

    Returns:
        float or array: time averaged value
    """
    return (avg * total_time + value * time_incr) / \
        (total_time + time_incr)