def from_sexagesimal(x, hours=False):
    """
    Given string of the form "dd:mm:ss.sss" or "hh:mm:ss.sss" (when
    hours=True), convert to decimal degrees.
    """
    w = x.split(':')
    w[0] = w[0].strip()
    s = 1.
    if w[0][0]=='-':
        s=-1.
        w[0] = w[0][1:]
    y = 0.
    c = 1.
    for yy in w:
        y += float(yy) * c
        c /= 60.
    if hours: y*= 15.
    return y*s