def angleDiff(angle1, angle2, take_smaller=True):
a = np.arctan2(np.sin(angle1 - angle2), np.cos(angle1 - angle2))<EOL>if isinstance(a, np.ndarray) and take_smaller:<EOL><INDENT>a = np.abs(a)<EOL>ab = np.abs(np.pi - a)<EOL>with np.errstate(invalid='<STR_LIT:ignore>'):<EOL><INDENT>i = a > ab<EOL><DEDENT>a[i] = ab[i]<EOL><DEDENT>return a<EOL>
smallest difference between 2 angles
code from http://stackoverflow.com/questions/1878907/the-smallest-difference-between-2-angles