-
Notifications
You must be signed in to change notification settings - Fork 101
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
New phase class #695
base: master
Are you sure you want to change the base?
New phase class #695
Conversation
p.s. Not working on python 2.7, obviously... |
Moving final discussion from #586 here, in particular the answer to #685 (comment):
I think it would not be particularly difficult for the class itself have the equivalency between cycles and dimensionless built-in. Indeed, the example I pushed in #695 already did that for initialization, and that could be extended to the unit-conversion methods .to and .to_value. I don't think I'm the right person to making a PR that extends its use to other parts of tempo, but I'm definitely willing to help trouble-shoot problems and make adjustments as needed. I do think that the same phase class (or a lower-precision version) should be used for orbital phase as well. |
The new Phase class has better precision and rounds to even. The former brings out very small floating point differences. At floating point precision, sadly, 0.7 - 1 != -0.3.
I rebased this now that #701 has been merged. Not surprisingly, the multiplication and division work fine with my phase class, though I had to adjust quite a number of the tests since the current PINT phase class does not round to even, and also loses precision in some cases (which amusingly, for the tests gives more reasonable results, such as 0.7 - 1 == 0.3, while if one works with floats directly:
Since my class keeps full float precision, those tests failed... It also means that, e.g.,
p.s. Also added the full test suite; if there is serious interest in having this class, I'd probably like to redo the PR to include the git history of its creation. I'm happy to relicense under BSD. |
In #685, I mentioned that I had previously attempted to replace PINT's underpowered
Phase
class with something I had written with Jing for our scintillometry package. It is aQuantity
subclass which separately tracks integer and fractional cycles (bit likeTimeDelta
). It behaves like aQuantity
but tries to keep precision, using, e.g., just the fractional part when evaluatingnp.sin
.I revived my old attempt, rebasing and fixing the few places where things broke. Right now, it is slightly hacked in - I think that if it were to replace phase everywhere, things would likely simplify.