def npitopi(r):
    ''' convert an angle in radians into (-pi, +pi] '''
    r = math.fmod(r, TWOPI)
    if r > PI:
        r -= TWOPI
    elif r <= -1.0 * PI:
        r += TWOPI
    return r
 convert an angle in radians into (-pi, +pi] 
aa.py