def map(v, ds, de, ts, te):
    """\
    Map the value v, in range [ds, de] to
    the corresponding value in range [ts, te]
    """
    d1 = de - ds
    d2 = te - ts
    v2 = v - ds
    r = v2 / d1

    return ts + d2 * r