def clipped_map(value, from_low, from_high, to_low, to_high):
    """Clip a value to fit a domain and then map it to a range.

    :param value: value to be clipped and mapped
    :param from_low, from_high: domain of the value.  If the value is
        outside this domain, it will first be clipped.
    :param to_low, to_high: range of the mapped value.  After clipping,
        the value will be mapped to this range.
    :returns: (clipped_value, mapped_value) tuple.

    """
    if value < from_low:
        clipped = from_low
    elif value > from_high:
        clipped = from_high
    else:
        clipped = value

    relative_value = (1. * clipped - from_low) / (from_high - from_low)
    mapped = relative_value * (to_high - to_low) + to_low

    return clipped, mapped