-
Notifications
You must be signed in to change notification settings - Fork 477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
comparing positive and negative angles #1344
Comments
I personally do not think it is a good idea. While in some contexts it makes total sense, in some others both angles represent totally different things: think , e.g. if you are describing an orientation change (one would be clock-wise and the other counter-clockwise). I would suggest that, if in your context both are equal, you compare using mod() explicitly: import pint
import numpy
ureg = pint.UnitRegistry()
numpy.mod(-140 * ureg.degrees, 360 * ureg.degrees) == numpy.mod(220 * ureg.degrees, 360 * ureg.degrees) |
Same here, if you want this I'd suggest wrapping this in a function. I know it sounds appealing at first, but I'd rather put those kind of examples in the docs. from math import pi
import pint
ureg = pint.UnitRegistry()
-140 * ureg.degrees % (360 * ureg.degrees) == 220 * ureg.degrees
-140 * ureg.degrees % (1 * ureg.turn) == 220 * ureg.degrees
-140 * ureg.degrees % (2 * pi) == 220 * ureg.degrees |
I think there are multiple concepts here: "relative angles" or orientation changes, which can describe multiple turns and can be positive or negative (clockwise and counter-clockwise, depending on the definition), and "absolute angles" or "positions on a circle" which are always in the range of I think we should try to support both, probably by adding special "absolute angle" units or using contexts. I guess I would prefer the special units because it might make sense to use both variants in the same equation. |
I agree wth @cpascual and @jules-ch, I think such a feature (while tempting in particular applications) would complicate the code and generate unexpected results for some user. Regarding @keewis suggestions, not sure how to do it. What I usually do in my code is having a function to normalize angles which I run after any code that computes an angle. I am not sure if this belongs in pint, and if it does, is it a function or a quantity method. |
+1 to adding @jules-ch 's examples to the docs (specially the 3rd one which is both very compact and self-explanatory) |
return
False
. Is it possible for it to returnTrue
instead?xref xarray-contrib/pint-xarray#119
The text was updated successfully, but these errors were encountered: