From time to time I encounter ValueErrors when with the Quaternion library when extracting the equatorial angles. For example, this happens:
File "/.../lib/python2.7/site-packages/Quaternion.py", line 233, in _quat2equatorial
dec = degrees(atan2(xn , sqrt(1 - xn**2)));
ValueError: math domain error
This appears to be because 1-xn2 is occasionally negative due to floating point issues. Since the expression 1-xn2 should never be negative, a simple fix is to wrap it in max(0,1-xn**2) inside sqrt.
Bug Report and suggested fix from Shuning Bian:
From time to time I encounter ValueErrors when with the Quaternion library when extracting the equatorial angles. For example, this happens:
This appears to be because 1-xn2 is occasionally negative due to floating point issues. Since the expression 1-xn2 should never be negative, a simple fix is to wrap it in max(0,1-xn**2) inside sqrt.